[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[py-rrdtool-cvs] [Commit] py-rrdtool/rrdtool RRDtool.py __init__.py
From: |
Hye-Shik Chang <address@hidden> |
Subject: |
[py-rrdtool-cvs] [Commit] py-rrdtool/rrdtool RRDtool.py __init__.py |
Date: |
Mon, 27 May 2002 15:44:38 -0400 |
perky 02/05/27 15:44:38
Modified: rrdtool __init__.py
Added: rrdtool RRDtool.py
Log:
Add immature implementation of OO-rrdtool
Revision Changes Path
1.4 +8 -6 py-rrdtool/rrdtool/__init__.py
Index: __init__.py
===================================================================
RCS file: /cvsroot/py-rrdtool/py-rrdtool/rrdtool/__init__.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- __init__.py 24 May 2002 16:57:42 -0000 1.3
+++ __init__.py 27 May 2002 19:44:38 -0000 1.4
@@ -1,13 +1,13 @@
#
-# __init__.py
+# __init__.py
#
-# py-rrdtool package initializer
+# py-rrdtool package initializer
#
-# Author : Hye-Shik Chang <address@hidden>
-# Date : $Date: 2002/05/24 16:57:42 $
-# Created : 24 May 2002
+# Author : Hye-Shik Chang <address@hidden>
+# Date : $Date: 2002/05/27 19:44:38 $
+# Created : 24 May 2002
#
-# $Revision: 1.3 $
+# $Revision: 1.4 $
#
# ==========================================================================
# This file is part of py-rrdtool.
@@ -28,3 +28,5 @@
#
from _rrdtool import *
+from RRDtool import RRD, RRDBase, DS, RRA
+from RRDtool import CDEF, DEF, PRINT, GPRINT, LINE, HRULE, VRULE, AREA, STACK
1.1 py-rrdtool/rrdtool/RRDtool.py
Index: RRDtool.py
===================================================================
#
# RRDtool.py
#
# Object-Oriented RRD Wrapper
#
# Author : Hye-Shik Chang <address@hidden>
# Date : $Date: 2002/05/27 19:44:38 $
# Created : 25 May 2002
#
# $Revision: 1.1 $
#
# ==========================================================================
# This file is part of py-rrdtool.
#
# py-rrdtool is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# py-rrdtool is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Foobar; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
from _rrdtool import *
try:
True
except:
True = 1
False = 0
class DS:
GAUGE = 'GAUGE'; COUNTER = 'COUNTER'
DERIVE = 'DERIVE'; ABSOLUTE = 'ABSOLUTE'
def __init__(self, dst, heartbeat, min=None, max=None):
self.dst = dst
self.heartbeat = heartbeat
self.min = min
self.max = max
def digest(self, name):
return 'DS:%s:%s:%d:%s:%s' % (
name, self.dst, self.heartbeat,
(self.min is None) and 'U' or self.min,
(self.max is None) and 'U' or self.max)
class RRA:
AVERAGE = 'AVERAGE'; MIN = 'MIN'
MAX = 'MAX'; LAST = 'LAST'
def __init__(self, cf, xff, steps=600, rows=288):
self.cf = cf
self.xff = xff
self.steps = steps
self.rows = rows
def digest(self):
return 'RRA:%s:%g:%d:%d' % (self.cf, self.xff, self.steps, self.rows)
class RRDBase:
"""
Essential Base Class for Round Robin Databases
"""
starttime = -10
step = 300
ds = {}
rra = []
file = ''
isloaded = 0
def __init__(self, file):
self.file = file
def create(self):
apply(create,
[self.file, '-b', str(self.starttime), '-s', str(self.step)] +
[v.digest(k) for k, v in self.ds.items()] +
[v.digest() for v in self.rra]
)
def load(self):
i = info(self.file)
self.step = i['step']
self.starttime = i['last_update'] - 10
self.ds = {}
for k, v in i['ds'].items():
self.ds[k] = DS(v['type'], v['minimal_heartbeat'], v['min'],
v['max'])
self.rra = [
RRA(v['cf'], v['xff'], v['pdp_per_row'], v['rows'])
for v in i['rra']
]
self.isloaded = True
def change(self, file):
self.file = file
self.isloaded = 0
def update(self, *values):
update(self.file, *['%d:%g' % v for v in values])
def update_now(self, value):
update(self.file, '%d:%g' % (time(), value))
def info(self)
return info(self.file)
def last(self):
return last(self.file)
def resize(self, rra, newsize=None, grow=None, shrink=None):
if not isloaded:
self.load()
if isinstance(rra, RRA):
rrao = rra
rran = self.rra.index(rra) # throws IndexError
else: # int
rrao = self.rra[rran].rows
rran = rra
if newsize is not None:
if rrao.rows < newsize:
resize(self.file, str(rran), 'GROW',
str(newsize - rrao.rows) )
elif rrao.rows < newsize:
resize(self.file, str(rran), 'SHRINK',
str(rrao.rows - newsize) )
rrao.rows = newsize
elif grow is not None:
resize(self.file, str(rran), 'GROW', str(grow))
rrao.rows += grow
elif shrink is not None:
resize(self.file, str(rran), 'SHRINK', str(shrink))
rrao.rows -= shrink
def fetch(self, cf, start=None, end=None, resolution=None):
pass
def tune(self):
#rrdtool tune filename [--heartbeat|-h ds-name:heartbeat]
#[--minimum|-i ds-name:min] [--maximum|-a ds-name:max]
#[--data-source-type|-d ds-name:DST] [--data-source-
#rename|-r old-name:new-name]
pass
class RRD (RRDBase):
"""
Fancy Base Class for Round Robin Databases
"""
def change(self, file, create=1):
self.file = file
try:
self.load()
except error, why:
if create:
self.create()
else:
raise error, why
__init__ = change
class DEF:
def __init__(self, rrd, dsname, cf):
self.rrd = rrd
self.dsname = dsname
self.cf = cf
def digest(self, vname):
return vname+'='+':'.join([
isinstance(self.rrd, RRDBase) and self.rrd.file or self.rrd,
self.dsname, self.cf])
class CDEF:
def __init__(self, expression, raw=True):
if raw:
self.expression = expression
else:
self.expression = self.translate(expression)
def digest(self, vname):
return vname+'='+self.expression
# these option generators were written in function
# instead of class for performance
class PRINT:
pass
class GPRINT:
pass
class HRULE:
pass
class VRULE:
pass
class LINE:
pass
class AREA:
pass
class STACK:
pass
class RRDgraph:
"""
RRDgraph Base Class
"""
# Constant Members
SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR = \
'SECOND', 'MINUTE', 'HOUR', 'DAY', 'WEEK', 'MONTH', 'YEAR'
# Overridable Members
start = None # integer
end = None # integer
xgrid = None # [(GTM, GST), (MTM, MST), (LTM, LST), LPR, LFM]
units_exponent = None # integer
vertical_label = None # string
width = None # integer
height = None # integer
interlaced = None # bool
imgformat = None # 'GIF', 'PNG', 'GD'
background = None # string
lazy = None # bool
upper_limit = None # float
lower_limit = None # float
logarithmic = None # bool
no_legend = None # bool
title = None # string
dses = None # dictionary of DEF class instance or CDEF string
comments = None # list of string
drawings = None # list of instances of HRULE, VRULE, LINE, AREA,
STACK classes
# listing order have an effect on output.
# Not supported Yet
#
# ygrid, alt_ygrid, alt_autoscale, overlay, unit, rigid, base
# color, step, prints, gprints
def __init__(self):
pass
def openrrd(filepath):
return RRD(filepath, 0)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [py-rrdtool-cvs] [Commit] py-rrdtool/rrdtool RRDtool.py __init__.py,
Hye-Shik Chang <address@hidden> <=