~vcs-imports/bts-lin/trunk

« back to all changes in this revision

Viewing changes to rrd/bootstrap_rrd.py

  • Committer: Sandro Tosi
  • Date: 2015-04-02 18:14:04 UTC
  • Revision ID: git-v1:b4fc9c0b0324907ca796fb10f90b01a46537f63a
Keep historical data in an RRD db, update it at each run and generate graphs

Three scripts compose the RRD integration:

* bootstrap_rrd.py - generates the initial RRD from a set of summary files
* graph_rrd.py - generates graphs from the RRD db
* update_rrd.py - updates the RRD with one summary, to be used after each run

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# vim:set encoding=utf-8:
 
3
###############################################################################
 
4
# Initialize the RRD db from the summary files of previous bts-link executions
 
5
#
 
6
# Docs used:
 
7
# http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html
 
8
# http://oss.oetiker.ch/rrdtool/doc/rrdupdate.en.html
 
9
###############################################################################
 
10
# Copyright:
 
11
#   © 2015 Sandro Tosi <morph@debian.org>
 
12
#
 
13
# Redistribution and use in source and binary forms, with or without
 
14
# modification, are permitted provided that the following conditions
 
15
# are met:
 
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
 
23
#    permission.
 
24
#
 
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
###############################################################################
 
36
 
 
37
from __future__ import with_statement
 
38
import sys
 
39
import yaml
 
40
import datetime
 
41
from collections import defaultdict
 
42
import rrdtool
 
43
import os.path
 
44
 
 
45
if len(sys.argv) == 1:
 
46
    print "Usage: " + sys.argv[0] + " <list of summary files>"
 
47
    sys.exit(1)
 
48
 
 
49
basedir = os.path.dirname(os.path.abspath(__file__))
 
50
rrdfile = os.path.join(basedir, 'bts-link.rrd')
 
51
 
 
52
r = defaultdict(lambda: defaultdict(dict))
 
53
tags = set(['elapsed_time', ])
 
54
 
 
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']:
 
62
            tags.add(tag)
 
63
            r[summary_epoch][tag] = summary['Tags summary'][tag]
 
64
 
 
65
# http://oss.oetiker.ch/rrdtool/doc/rrdcreate.en.html
 
66
rrdtool.create(rrdfile,
 
67
    '--start', '1233446400',  # 2009-02-01 00:00:00
 
68
    '--step', '86400',
 
69
    # datasource definition
 
70
    ['DS:%s:GAUGE:604800:0:U' % ds for ds in sorted(tags)],
 
71
    'RRA:LAST:0.1:1:5475'
 
72
)
 
73
 
 
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())))
 
78
        )
 
 
b'\\ No newline at end of file'