aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlias Apalodimas <ilias.apalodimas@linaro.org>2017-08-28 19:10:58 +0300
committerIlias Apalodimas <ilias.apalodimas@linaro.org>2017-08-28 19:10:58 +0300
commit0618437127d77a1eb35c1fd8a5386d742b612094 (patch)
tree0e8f7bf44e9ed0a339ac8b1341225e3b36802da0
parent729241e96b67e4a1f02ecc7bb12b525823edcdae (diff)
Added python tool to generate rrd graphs
-rw-r--r--tools/rrd_graphs/pkg-gen-stats82
-rwxr-xr-xtools/rrd_graphs/rrd-plot.py101
2 files changed, 183 insertions, 0 deletions
diff --git a/tools/rrd_graphs/pkg-gen-stats b/tools/rrd_graphs/pkg-gen-stats
new file mode 100644
index 0000000..f899dad
--- /dev/null
+++ b/tools/rrd_graphs/pkg-gen-stats
@@ -0,0 +1,82 @@
+1503923303:1001053:1760137
+1503923304:1001387:1765741
+1503923305:1001332:1794420
+1503923306:1001337:1876531
+1503923307:1001388:1822553
+1503923308:1001350:1818189
+1503923309:1001334:1855517
+1503923310:1001489:1764370
+1503923311:1000988:1826791
+1503923312:1001389:1819563
+1503923313:1001355:1857333
+1503923314:1001355:1830731
+1503923315:1001364:1800934
+1503923316:1001395:1880289
+1503923317:1001359:1880830
+1503923318:1001365:1780367
+1503923319:1001349:1783984
+1503923320:1001108:1749302
+1503923321:1001364:1876738
+1503923322:1001475:1785101
+1503923323:1001393:1806231
+1503923324:1001403:1787548
+1503923325:1001411:1777931
+1503923326:1000939:1824027
+1503923327:1001496:1771043
+1503923328:1001521:1831311
+1503923329:1000927:1783728
+1503923330:1001518:1768677
+1503923331:1001471:1835556
+1503923332:1001452:1816968
+1503923333:1001470:1867117
+1503923334:1001460:1832360
+1503923335:1001467:1818040
+1503923336:1001521:1818373
+1503923337:1001628:1712311
+1503923338:1003177:1728569
+1503923339:1001499:1746851
+1503923340:1001513:1785627
+1503923341:1001460:1725664
+1503923342:1001483:1759375
+1503923343:1001509:1801291
+1503923344:1001459:1832866
+1503923345:1001448:1852807
+1503923346:1001459:1835925
+1503923347:1001077:1747375
+1503923348:1001442:1797145
+1503923349:1001493:1776114
+1503923350:1001436:1778327
+1503923351:1001412:1803931
+1503923352:1001404:1851082
+1503923353:1001440:1863038
+1503923354:1001455:1872712
+1503923355:1001407:1770311
+1503923356:1001478:1848012
+1503923357:1001440:1826538
+1503923358:1001641:1767393
+1503923359:1001499:1839713
+1503923360:1001423:1825974
+1503923361:1001414:1828780
+1503923362:1001461:1758188
+1503923363:1001487:1763347
+1503923364:1001435:1830177
+1503923365:1001542:1889949
+1503923366:1001410:1888410
+1503923367:1001413:1880223
+1503923368:1001406:1840532
+1503923369:1001460:1837350
+1503923370:1001442:1751467
+1503923371:1001423:1818733
+1503923372:1001046:1828602
+1503923373:1001534:1741878
+1503923374:1001538:1660823
+1503923375:1000999:1754092
+1503923376:1001513:1753061
+1503923377:1001527:1739283
+1503923378:1000985:1771114
+1503923379:1001459:1750048
+1503923380:1001542:1741350
+1503923381:1001422:1783772
+1503923382:1001470:1843356
+1503923383:1001405:1834727
+1503923384:1000590:1830982
diff --git a/tools/rrd_graphs/rrd-plot.py b/tools/rrd_graphs/rrd-plot.py
new file mode 100755
index 0000000..0a1d719
--- /dev/null
+++ b/tools/rrd_graphs/rrd-plot.py
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+
+import rrdtool
+
+# create RRD database
+def create_db(start, end, rrd_db='ts.rrd'):
+ # DS says that this is a data set. Check rrd manpage for details.
+ # RRA directive defines how many values the the RRD database will archive and
+ # for how long.
+ #
+ # MAX normally means to only accept the maximum value if multiple values
+ # are available over multiple "steps". We are using MAX simply to say that
+ # we have variable which will contain one number and it should not be
+ # changed.
+ #
+ # 0.5 is an internal resolution value and should _not_ be changed.
+ #
+ #
+ # 1 specifies how many steps should be averaged before storing the value.
+ # 1500 is how many "steps" we will store in the db.
+ # 1 seconds (--step 1) we will store 1500 samples times 1 seconds
+ # Total 1500 seconds.
+
+ data_sources = ['DS:tdiff:GAUGE:2:0:10000000000',
+ 'DS:pps:GAUGE:2:0:100000000000',
+ 'RRA:MAX:0.5:1:1500']
+
+ startime = long(start) - 1
+ rrdtool.create(rrd_db, '--step', '1', '--start', str(startime), data_sources)
+ return 0
+
+# Update rrd databses with logged data.
+# data format epoch:avg time between samples:value
+def update_db(pkg_log='pkg-gen-stats', rrd_db='ts.rrd'):
+ ret = 0
+ try:
+ with open(pkg_log, 'r') as f:
+ for line in f:
+ epoch_time, tdiff, pps = line.split(":")
+ ret = rrdtool.update(rrd_db, '%s:%s:%lu' % (epoch_time, tdiff,
+ long(pps)))
+ except Exception as e:
+ print(e)
+
+
+ return ret
+
+def plot_db(start, end, output, rrd_db='ts.rrd'):
+ ret = 0
+ plot_sources = ['DEF:pps=sample_rrd:pps:MAX',
+ 'AREA:pps#00FF00:Packets per second',
+ 'GPRINT:pps:MAX:Max\: %lf%spps',
+ 'GPRINT:pps:MIN:Min\: %lf%spps',
+ 'GPRINT:pps:AVERAGE:Avg\: %lf%spps']
+
+ plot_sources = [x.replace('sample_rrd', rrd_db) for x in plot_sources]
+
+ ret = rrdtool.graph(output,
+ "--start", start,
+ "--end", end,
+ '--slope-mode',
+ '--title', "Netmap packets per second",
+ "--vertical-label=PPS",
+ '-w' '1024', '-h', '384',
+ '--lower-limit', '0',
+ '--x-grid', 'SECOND:15:MINUTE:1:SECOND:10:0:%T',
+ #GTM:GST:MTM:MST:LTM:LST:LPR:LFM
+ plot_sources)
+
+ return ret
+
+# Open file and get first-last time from epoch
+# @start: first entry
+# @end: last entry
+def get_tstamps(pkg_log='pkg-gen-stats'):
+ ret = (-1, -1)
+
+ # FIXME add checks for failures
+ try:
+ with open(pkg_log, 'r') as f:
+ start_time_arr = f.readline().split(":")
+ end_time_arr = f.readlines()[-1].split(":")
+ except Exception as e:
+ print(e)
+ return ret
+
+ start = start_time_arr[0]
+ end = end_time_arr[0]
+
+ return (start, end)
+
+def main():
+ output = 'graph.png'
+ start, end = get_tstamps()
+ create_db(start, end)
+ update_db()
+ plot_db(start,end, output)
+ print("Saved {}") . format(output)
+
+if __name__ == '__main__':
+ main()