2
# vim:set encoding=utf-8:
3
###############################################################################
4
# Initialize the RRD db from the summary files of previous bts-link executions
7
# http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html
8
# http://oss.oetiker.ch/rrdtool/doc/rrdupdate.en.html
9
###############################################################################
11
# © 2015 Sandro Tosi <morph@debian.org>
13
# Redistribution and use in source and binary forms, with or without
14
# modification, are permitted provided that the following conditions
16
# 1. Redistributions of source code must retain the above copyright
17
# notice, this list of conditions and the following disclaimer.
18
# 2. Redistributions in binary form must reproduce the above copyright
19
# notice, this list of conditions and the following disclaimer in the
20
# documentation and/or other materials provided with the distribution.
21
# 3. The names of its contributors may not be used to endorse or promote
22
# products derived from this software without specific prior written
25
# THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
26
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28
# EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
###############################################################################
37
from __future__ import with_statement
41
from collections import defaultdict
45
if len(sys.argv) == 1:
46
print "Usage: " + sys.argv[0] + " <list of summary files>"
49
basedir = os.path.dirname(os.path.abspath(__file__))
50
rrdfile = os.path.join(basedir, 'bts-link.rrd')
52
r = defaultdict(lambda: defaultdict(dict))
53
tags = set(['elapsed_time', ])
55
for summaryfile in sorted(sys.argv[1:]):
56
with open(summaryfile) as f:
57
summary = yaml.load(f)
58
# rrd wants epoch as timestamps
59
summary_epoch = summary['Execution complete'].strftime('%s')
60
r[summary_epoch]['elapsed_time'] = int(summary['Elapsed time'])
61
for tag in summary['Tags summary']:
63
r[summary_epoch][tag] = summary['Tags summary'][tag]
65
# http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html
66
rrdtool.create(rrdfile,
67
'--start', '1233446400', # 2009-02-01 00:00:00
69
# datasource definition
70
['DS:%s:GAUGE:604800:0:U' % ds for ds in sorted(tags)],
74
for ts in sorted(r.keys()):
75
rrdtool.update(rrdfile,
76
'-t', ':'.join(sorted(r[ts].keys())),
77
'%s:%s' % (ts, ':'.join(str(r[ts][k]) for k in sorted(r[ts].keys())))
b'\\ No newline at end of file'