Browse Source

Report all statistics about ping

Baptiste Jonglez 10 years ago
parent
commit
070d0d1c94
3 changed files with 39 additions and 15 deletions
  1. 26 9
      peerfinder.py
  2. 6 2
      templates/results.html
  3. 7 4
      templates/run.sh

+ 26 - 9
peerfinder.py

@@ -105,19 +105,33 @@ class Result(db.Model):
     participant_id = db.Column(db.Integer, db.ForeignKey('participant.id'))
     participant_id = db.Column(db.Integer, db.ForeignKey('participant.id'))
     participant = db.relationship('Participant',
     participant = db.relationship('Participant',
                                   backref=db.backref('results', lazy='dynamic'))
                                   backref=db.backref('results', lazy='dynamic'))
-    # In milliseconds
-    rtt = db.Column(db.Float)
     # Date at which the result was reported back to us
     # Date at which the result was reported back to us
     date = db.Column(db.DateTime)
     date = db.Column(db.DateTime)
-
-    def __init__(self, target_id, participant_uuid, rtt):
+    # In milliseconds
+    avgrtt = db.Column(db.Float)
+    # All these are optional
+    minrtt = db.Column(db.Float)
+    maxrtt = db.Column(db.Float)
+    jitter = db.Column(db.Float)
+    # Number of ping requests
+    probes_sent = db.Column(db.Integer)
+    # Number of successful probes
+    probes_received = db.Column(db.Integer)
+
+    def __init__(self, target_id, participant_uuid, avgrtt, minrtt, maxrtt,
+                 jitter, probes_sent, probes_received):
         target = Target.query.get_or_404(int(target_id))
         target = Target.query.get_or_404(int(target_id))
         participant = Participant.query.filter_by(uuid=participant_uuid,
         participant = Participant.query.filter_by(uuid=participant_uuid,
                                                   active=True).first_or_404()
                                                   active=True).first_or_404()
         self.target = target
         self.target = target
         self.participant = participant
         self.participant = participant
-        self.rtt = float(rtt)
         self.date = datetime.now()
         self.date = datetime.now()
+        self.avgrtt = float(avgrtt)
+        self.minrtt = float(minrtt) if minrtt is not None else None
+        self.maxrtt = float(maxrtt) if maxrtt is not None else None
+        self.jitter = float(jitter) if jitter is not None else None
+        self.probes_sent = int(probes_sent) if probes_sent is not None else None
+        self.probes_received = int(probes_received) if probes_received is not None else None
 
 
 
 
 def init_db():
 def init_db():
@@ -199,10 +213,13 @@ def get_next_target_family(uuid, family):
 
 
 @app.route('/result/report/<uuid>', methods=['POST'])
 @app.route('/result/report/<uuid>', methods=['POST'])
 def report_result(uuid):
 def report_result(uuid):
-    if {'rtt', 'target'}.issubset(request.form):
+    if {'avgrtt', 'target'}.issubset(request.form):
         target_id = request.form['target']
         target_id = request.form['target']
-        rtt = request.form['rtt']
-        result = Result(target_id, uuid, rtt)
+        avgrtt = request.form['avgrtt']
+        optional_args = [request.form.get(f) for f in
+                         ('minrtt', 'maxrtt', 'jitter', 'probes_sent',
+                          'probes_received')]
+        result = Result(target_id, uuid, avgrtt, *optional_args)
         db.session.add(result)
         db.session.add(result)
         # Record that the participant has returned a result
         # Record that the participant has returned a result
         participant = result.participant
         participant = result.participant
@@ -215,7 +232,7 @@ def report_result(uuid):
 @app.route('/result/show/<target_uniqueid>')
 @app.route('/result/show/<target_uniqueid>')
 def show_results(target_uniqueid):
 def show_results(target_uniqueid):
     target = Target.query.filter_by(unique_id=target_uniqueid).first_or_404()
     target = Target.query.filter_by(unique_id=target_uniqueid).first_or_404()
-    results = target.results.order_by('rtt').all()
+    results = target.results.order_by('avgrtt').all()
     return render_template('results.html', target=target, results=results)
     return render_template('results.html', target=target, results=results)
 
 
 
 

+ 6 - 2
templates/results.html

@@ -1,17 +1,21 @@
-Latencies to {{ target }} (job submitted at {{ target.submitted }})
+Latencies to <strong>{{ target }}</strong> (job submitted at {{ target.submitted }})
 
 
 <table>
 <table>
   <tr>
   <tr>
     <th>Source</th>
     <th>Source</th>
     <th>Contact</th>
     <th>Contact</th>
     <th>Latency</th>
     <th>Latency</th>
+    <th>Jitter</th>
+    <th>Packet loss</th>
     <th>Date</th>
     <th>Date</th>
   </tr>
   </tr>
   {% for r in results %}
   {% for r in results %}
   <tr>
   <tr>
     <td>{{ r.participant.name }}</td>
     <td>{{ r.participant.name }}</td>
     <td>{{ r.participant.contact }}</td>
     <td>{{ r.participant.contact }}</td>
-    <td>{{ r.rtt }} ms</td>
+    <td><strong>{{ r.avgrtt }} ms</strong></td>
+    <td>{{ r.jitter }} ms</td>
+    <td>{{ 100 * (r.probes_sent - r.probes_received) / r.probes_sent }}%</td>
     <td>{{ r.date }}</td>
     <td>{{ r.date }}</td>
   </tr>
   </tr>
   {% endfor %}
   {% endfor %}

+ 7 - 4
templates/run.sh

@@ -19,8 +19,11 @@ do
     [ -z "$id" -o -z "$ip" ] && continue
     [ -z "$id" -o -z "$ip" ] && continue
     # Make sure "id" is an integer
     # Make sure "id" is an integer
     printf "%d" "$id" > /dev/null 2>&1 || continue
     printf "%d" "$id" > /dev/null 2>&1 || continue
-    rtt="$($PING -c "$NB_PINGS" "$ip" | grep rtt | cut -d '/' -f 5)"
-    [ -z "$rtt" ] && continue
-    echo "RTT to target $id ($ip) is $rtt"
-    curl -d "target=${id}&rtt=${rtt}" "$PEERFINDER"/result/report/"$UUID"
+    # Parsing ping output, for Linux
+    output="$($PING -c "$NB_PINGS" "$ip" | grep -A1 "packets transmitted")"
+    echo $output | sed -e 's#^\([0-9]*\) packets transmitted, \([0-9]*\) received, .* rtt min/avg/max/mdev = \(.*\)/\(.*\)/\(.*\)/\(.*\) ms$#\1\t\2\t\3\t\4\t\5\t\6#' > /tmp/"$FAMILY"_tmp
+    read sent received minrtt avgrtt maxrtt jitter < /tmp/"$FAMILY"_tmp
+    [ -z "$avgrtt" ] && continue
+    echo "RTT to target $id ($ip) is $avgrtt"
+    curl -d "target=${id}&probes_sent=${sent}&probes_received=${received}&minrtt=${minrtt}&avgrtt=${avgrtt}&maxrtt=${maxrtt}&jitter=${jitter}" "$PEERFINDER"/result/report/"$UUID"
 done
 done