My favorites
|
Sign in
rrdpy
Python RRD Utilities
Project Home
Downloads
Source
Checkout
|
Browse
|
Changes
|
‹r11
r26
Source path:
svn
/
trunk
/
rrd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
#
# rrd.py
# Simple RRDTool wrapper
# Copyright (c) 2008 Corey Goldberg (corey@goldb.org)
#
# Download the Windows version of RRDTool from:
# http://www.gknw.net/mirror/rrdtool/
#
# You may need these fonts if RRDTool throws an error when you graph:
# http://dejavu.sourceforge.net/wiki/index.php/Main_Page
import os
import time
class RRD(object):
def __init__(self, rrd_name, vertical_label='test'):
self.rrd_name = rrd_name
self.vertical_label = vertical_label
def create_rrd(self, interval):
interval = str(interval)
interval_mins = float(interval) / 60
heartbeat = str(int(interval) * 2)
ds_string = ' DS:test:GAUGE:%s:U:U' % heartbeat
cmd_create = ''.join((
'rrdtool create ', self.rrd_name, ' --step ', interval, ds_string,
' RRA:AVERAGE:0.5:1:', str(int(4000 / interval_mins)),
' RRA:AVERAGE:0.5:', str(int(30 / interval_mins)), ':800',
' RRA:AVERAGE:0.5:', str(int(120 / interval_mins)), ':800',
' RRA:AVERAGE:0.5:', str(int(1440 / interval_mins)), ':800',
))
cmd = os.popen4(cmd_create)
cmd_output = cmd[1].read()
for fd in cmd: fd.close()
if len(cmd_output) > 0:
raise RRDException, 'Unable to create RRD: ' + cmd_output
def update(self, *values):
values_args = ''.join([str(value) + ':' for value in values])[:-1]
cmd_update = 'rrdtool update %s N:%s' % (self.rrd_name, values_args)
cmd = os.popen4(cmd_update)
cmd_output = cmd[1].read()
for fd in cmd: fd.close()
if len(cmd_output) > 0:
raise RRDException, 'Unable to update RRD: ' + cmd_output
def graph(self, mins):
start_time = 'now-%s' % (mins * 60)
output_filename = self.rrd_name + '.png'
end_time = 'now'
ds_name = 'test'
width = '400'
height = '150'
cur_date = time.strftime('%m/%d/%Y %H\:%M\:%S', time.localtime())
cmd_graph = 'rrdtool graph ' + output_filename + \
' DEF:' + ds_name + '=' + self.rrd_name + ':' + ds_name + ':AVERAGE' + \
' AREA:' + ds_name + '#FF0000' + \
' VDEF:' + ds_name + 'last=' + ds_name + ',LAST' + \
' VDEF:' + ds_name + 'avg=' + ds_name + ',AVERAGE' + \
' COMMENT:"' + cur_date + '"' + \
' GPRINT:' + ds_name + 'avg:" average=%6.2lf%S"' + \
' --title="' + self.rrd_name +'"' + \
' --vertical-label="' + self.vertical_label + '"' \
' --start=' + start_time + \
' --end=' + end_time + \
' --width=' + width + \
' --height=' + height + \
' --lower-limit="0"'
cmd = os.popen4(cmd_graph)
for fd in cmd: fd.close()
class RRDException(Exception): pass
Show details
Hide details
Change log
r13
by cgoldberg on Jul 07, 2008
Diff
[No log message]
Go to:
/trunk/rrd.py
Project members,
sign in
to write a code review
Older revisions
r11
by cgoldberg on Jul 02, 2008
Diff
[No log message]
r9
by cgoldberg on Apr 24, 2008
Diff
[No log message]
r8
by cgoldberg on Apr 24, 2008
Diff
[No log message]
All revisions of this file
File info
Size: 3040 bytes, 79 lines
View raw file
Hosted by