"Fossies" - the Fresh Open Source Software Archive

Member "HTTPing-2.9/plot-json.py" (29 Oct 2022, 1581 Bytes) of package /linux/www/HTTPing-2.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "plot-json.py" see the Fossies "Dox" file reference documentation.

    1 #! /usr/bin/python
    2 
    3 import sys
    4 import json
    5 import os
    6 import math
    7 
    8 fin = sys.argv[1]
    9 
   10 print "Loading from %s" % (fin)
   11 
   12 fh = open(fin)
   13 json_data = json.load(fh)
   14 
   15 print "Number of rows: %d" % (len(json_data))
   16 
   17 fdata = fin + ".dat"
   18 print "Writing data to %s" % (fdata)
   19 
   20 data_fh = open(fdata, "w")
   21 
   22 host='?'
   23 
   24 total=0
   25 total_sd=0
   26 n=0
   27 avg=0
   28 sd=0
   29 minp = 999999999
   30 maxp = -minp
   31 
   32 for row in json_data:
   33     if row['status'] == '1':
   34         val = float(row['total_s'])
   35         data_fh.write("%f %f\n" % (float(row['start_ts']), val))
   36         host=row['host']
   37         total += val
   38         total_sd += val * val
   39         n += 1
   40         if val > maxp:
   41             maxp = val
   42         if val < minp:
   43             minp = val
   44 
   45 print "Rows ignored: %d" % (len(json_data) - n)
   46 
   47 data_fh.close()
   48 
   49 if n > 0:
   50     avg = total / n
   51     sd = math.sqrt((total_sd / n) - math.pow(avg, 2.0))
   52 
   53 print "Average ping time: %fs (%d pings)" % (avg, n)
   54 print "Standard deviation: %fs" % (sd)
   55 print "Minimum ping value: %fs" % (minp)
   56 print "Maximum ping value: %fs" % (maxp)
   57 
   58 fscript = fin + ".sh"
   59 print "Writing script to %s" % (fscript)
   60 
   61 fpng = fin + ".png"
   62 
   63 script_fh = open(fscript, "w")
   64 
   65 script_fh.write("#! /bin/sh\n\n")
   66 script_fh.write("gnuplot <<EOF > " + fpng + "\n")
   67 script_fh.write("set term png size 800,600 tiny\n")
   68 script_fh.write("set autoscale\n")
   69 script_fh.write("set timefmt \"%s\"\n")
   70 script_fh.write("set xdata time\n")
   71 script_fh.write("set format x \"%H:%M:%S\"\n")
   72 script_fh.write("plot \"" + fdata + "\" using 1:2 with lines title \"" + host + "\"\n")
   73 script_fh.write("EOF\n")
   74 
   75 os.chmod(fscript, 0755)
   76 script_fh.close()
   77 
   78 print "Now invoke %s to generate %s" % (fscript, fpng)