Commit 438a1834 authored by Claudemir Todo Bom's avatar Claudemir Todo Bom
Browse files

* diferent files for config and status

parent b5a36132
Pipeline #134 failed with stages
in 21 seconds
......@@ -13,9 +13,12 @@ def getTimeStamp( timestamp , secs ):
class LogDigest:
def __init__ ( self , conffile ):
def __init__ ( self , confFile , statusFile ):
self.statusFile = statusFile
self.confFile = confFile
self.compiledMatchers={}
with open( conffile , 'r' ) as file:
self.status={}
with open( self.confFile , 'r' ) as file:
self.conf = simplejson.loads(file.read().replace('\n', ' ').replace('\t', ' '))
for matcherKey in self.conf["matchers"]:
self.compiledMatchers[matcherKey] = re.compile(self.conf["matchers"][matcherKey])
......@@ -35,13 +38,13 @@ class LogDigest:
if timestamp > self.nowLimit:
break
self.conf["position"] = logFile.tell()
self.status["position"] = logFile.tell()
if 'value' in mgroup:
value = mgroup["value"]
else:
value = 1
if 'marker' in mgroup:
self.counters.increment(str(timestamp) , marker , value)
else:
......@@ -49,7 +52,7 @@ class LogDigest:
break;
else:
self.conf["position"] = logFile.tell()
self.status["position"] = logFile.tell()
if timestamp > self.nowLimit:
break
......@@ -58,19 +61,19 @@ class LogDigest:
file = open ( filename , 'r' )
file.seek(position)
return file
def execute ( self ):
try:
if 'lastupdate' in self.conf and os.path.getmtime(self.conf["filename"]+".1") > self.conf["lastupdate"]:
logFile = self.openfile(self.conf["filename"]+".1", self.conf["position"])
if 'lastupdate' in self.status and os.path.getmtime(self.confFile+".1") > self.status["lastupdate"]:
logFile = self.openfile(self.confFile+".1", self.status["position"])
self.readfile(logFile)
self.conf["position"] = 0
self.status["position"] = 0
finally:
logFile = self.openfile(self.conf["filename"], self.conf["position"])
logFile = self.openfile(self.confFile, self.status["position"])
self.readfile(logFile)
self.conf["lastupdate"] = self.nowLimit
self.status["lastupdate"] = self.nowLimit
def savestatus( self , filename ):
with open (filename , 'w') as file:
file.write(simplejson.dumps(self.conf, sort_keys=True, indent='\t'))
def savestatus( self ):
with open (self.statusFile , 'w') as file:
file.write(simplejson.dumps(self.status, sort_keys=True, indent='\t'))
from pyrrd import rrd
import sys
from pyrrd import rrd
from pyrrd.graph import Graph , DEF , CDEF , AREA , GPRINT , LINE
from LogDigest import *
import os.path
......@@ -21,7 +23,13 @@ def prepareRRD( filename , conf , start = None , create = False ):
return myRRD
confile = "/root/logdigest.status"
if len(sys.argv) < 3:
sys.stderr.write("invalid arguments")
sys.exit(1)
confile = sys.argv[1]
statusfile = sys.argv[2]
ld = LogDigest(confile)
......@@ -59,14 +67,14 @@ for k in ld.counters:
value = '0'
buffervalues = buffervalues + divider + value
divider = ":"
myRRD.bufferValue( k , buffervalues )
haveUpdate = True
if haveUpdate:
myRRD.update( template = templateString )
ld.savestatus(confile)
ld.savestatus()
if "graph" in ld.conf:
defs = []
......@@ -82,12 +90,12 @@ if "graph" in ld.conf:
areas.append ( AREA( defObj = thisDEF , **(gdef["area"]) ))
if "line" in gdef:
lines.append ( LINE( defObj = thisDEF , **(gdef["line"]) ))
if "graphparam" in ld.conf:
graphparam = ld.conf["graphparam"]
else:
graphparam = { }
g = Graph ( ld.conf["graphfile"]+".png" , **graphparam )
g.data.extend ( defs + areas + lines )
g.write()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment