diff options
-rwxr-xr-x | tools/rrdui-cgi.py | 100 | ||||
-rw-r--r-- | tools/rrdui-create.py | 28 | ||||
-rw-r--r-- | tools/rrdui.py | 96 |
3 files changed, 98 insertions, 126 deletions
diff --git a/tools/rrdui-cgi.py b/tools/rrdui-cgi.py index 8b376f5..0c1ad0a 100755 --- a/tools/rrdui-cgi.py +++ b/tools/rrdui-cgi.py @@ -2,10 +2,107 @@ import os, sys, time import sets, cgi, shlex +import ConfigParser import rrdtool from rrdui import * +# TODO: Temporary +if not os.environ.has_key("CONFDIR") or not os.environ.has_key("WORKDIR"): + raise "not setup properly. CONFDIR and WORKDIR env variables must be set" + +CONFDIR = os.environ["CONFDIR"] +WORKDIR = os.environ["WORKDIR"] + +class GraphDef: + filename = None + filedata = None + title = "" + height = 0 + width = 0 + options = "" + commands = "" + category = "" + name = "" + + __config = None + + def __init__(self, name): + self.filename = "%s/%s" % (CONFDIR, name) + self.filedata = "%s/%s.rrd" % (WORKDIR, name) + self.category = "All" + self.name = name + + cfg = self.__config = ConfigParser.RawConfigParser() + cfg.read(self.filename) + + # Loading general stuff + if cfg.has_option("general", "title"): + self.title = cfg.get("general", "title") + if cfg.has_option("general", "category"): + self.title = cfg.get("general", "category") + + # Loading graph stuff + if cfg.has_option("graph", "width"): + self.width = int(cfg.get("graph", "width")) + if cfg.has_option("graph", "height"): + self.height = int(cfg.get("graph", "height")) + if cfg.has_option("graph", "options"): + self.options = cfg.get("graph", "options") + if not cfg.has_option("graph", "commands"): + raise "Missing commands attribute in: %s" % self.filename + self.commands = cfg.get("graph", "commands") + + + def getCreateInfo(self): + cfg = self.__config + rra = None + fields = {} + + # The RRA info + if cfg.has_option("create", "rra"): + rra = cfg.get("create", "rra").split() + + # The various fields + for field in cfg.options("create"): + if not field.startswith("field."): + continue + fieldname = field[6:] + fields[fieldname] = cfg.get("create", field) + + return (fields, rra) + + + def getPollingInfo(self): + cfg = self.__config + interval = 300 + fields = {} + + # The interval + if cfg.has_option("poll", "interval"): + interval = int(cfg.get("poll", "interval")) + + # The various fields + for field in cfg.options("poll"): + if not field.startswith("field."): + continue + fieldname = field[6:] + fields[fieldname] = cfg.get("poll", field) + + return (fields, interval) + + +def loadGraphs(): + + # List files and add appropriate paths + graphs = [] + for file in os.listdir(CONFDIR): + if os.path.isdir(file): + continue + graphs.append(GraphDef(file)) + return graphs + + def listGraphs(): graphs = loadGraphs() @@ -42,8 +139,7 @@ def displayGraph(): raise "Required arguments not specified" name = form["name"].value - category = form["category"].value - item = GraphDef(category, name) + item = GraphDef(name) # Default to one day display end = int(time.time()) diff --git a/tools/rrdui-create.py b/tools/rrdui-create.py deleted file mode 100644 index 3b46021..0000000 --- a/tools/rrdui-create.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python - -import os, sys -import rrdtool - -from rrdui import * - -def createItems(graphs): - - for item in graphs: - if os.path.exists(item.filedata): - continue - - args = [item.filedata, "-b-1y", "-s10"] - - # The creation info - (fields, rras) = item.getCreateInfo() - - # Flesh it out properly, and add it - args.extend(["RRA:%s" % r for r in rras]) - args.extend(["DS:%s:%s" % (f, fields[f]) for f in fields.keys()]) - - # And create it - rrdtool.create(*args) - -# Basics -graphs = loadGraphs() -createItems(graphs) diff --git a/tools/rrdui.py b/tools/rrdui.py deleted file mode 100644 index a4debf4..0000000 --- a/tools/rrdui.py +++ /dev/null @@ -1,96 +0,0 @@ -import os, sys, time -import ConfigParser - -# TODO: Temporary -CONFDIR = "/data/projects/rrdui/conf" -WORKDIR = "/data/projects/rrdui/work" - -class GraphDef: - filename = None - filedata = None - title = "" - height = 0 - width = 0 - options = "" - commands = "" - category = "" - name = "" - - __config = None - - def __init__(self, name): - self.filename = "%s/%s" % (CONFDIR, name) - self.filedata = "%s/%s.rrd" % (WORKDIR, name) - self.category = "All" - self.name = name - - cfg = self.__config = ConfigParser.RawConfigParser() - cfg.read(self.filename) - - # Loading general stuff - if cfg.has_option("general", "title"): - self.title = cfg.get("general", "title") - if cfg.has_option("general", "category"): - self.title = cfg.get("general", "category") - - # Loading graph stuff - if cfg.has_option("graph", "width"): - self.width = int(cfg.get("graph", "width")) - if cfg.has_option("graph", "height"): - self.height = int(cfg.get("graph", "height")) - if cfg.has_option("graph", "options"): - self.options = cfg.get("graph", "options") - if not cfg.has_option("graph", "commands"): - raise "Missing commands attribute in: %s" % self.filename - self.commands = cfg.get("graph", "commands") - - - def getCreateInfo(self): - cfg = self.__config - rra = None - fields = {} - - # The RRA info - if cfg.has_option("create", "rra"): - rra = cfg.get("create", "rra").split() - - # The various fields - for field in cfg.options("create"): - if not field.startswith("field."): - continue - fieldname = field[6:] - fields[fieldname] = cfg.get("create", field) - - return (fields, rra) - - - def getPollingInfo(self): - cfg = self.__config - interval = 300 - fields = {} - - # The interval - if cfg.has_option("poll", "interval"): - interval = int(cfg.get("poll", "interval")) - - # The various fields - for field in cfg.options("poll"): - if not field.startswith("field."): - continue - fieldname = field[6:] - fields[fieldname] = cfg.get("poll", field) - - return (fields, interval) - - -def loadGraphs(): - - # List files and add appropriate paths - graphs = [] - for file in os.listdir(CONFDIR): - if os.path.isdir(file): - continue - graphs.append(GraphDef(file)) - return graphs - - |