예제 #1
0
 def makeImage(self):
   color="660000"
   finame= cntcom.BASEDIR+"imgs/"+self.displayname+'.png'
   finame2= cntcom.IMAGES+self.displayname+'.png'
   rrdinput=cntcom.BASEDIR+"imgs/graph.txt"
   fromto,pixwidth= cntcom.getStartEnd(cfg)
   ri= open(rrdinput,"w")
   #ri.write("graph graf.png --start %d -e %d --step 60 -w 600 "%
   #  (time0, time0+60*60))
   #ri.write("graph graf.png -s teatime --step 60 -w 600 ")
   #ri.write("graph graf.png -s 17:55 --step 60 -w 600 ")  # -10 hours max.
   # time: -s now-10h   -s 1:0 -e 4:0
   #ri.write("graph graf.png -s now-10h --step 60 -w 600 ")
   ri.write("graph "+finame+" "+fromto+" --step 60 -w "+pixwidth+" ")
   cn= self.displayname
   ri.write("DEF:%s=%s:%s:AVERAGE "% (cn, RRDDB, self.coname))
   ri.write("LINE2:%s#%s:%s "%(cn,color,cn))
   ri.close()
   # following allowed only without SElinux:
   #os.system("rrdtool - <"+rrdinput)
   pf= os.popen("rrdtool - <"+rrdinput); cmdout=pf.read(); pf.close()
   coa=string.split(cmdout)
   if (len(coa) >2) and (coa[1]=='OK'):
     return "<BR><IMG SRC=%s>\n"%(finame2)
   else:
     return "%s<BR><BR>\n"%(cmdout)
예제 #2
0
 def makeImage(self, ltuname):
     """period: month week day '10 hours' hour
 ltuname: one of names in LTUS
 """
     color = "660000"
     RRDDBname = RRDDB + ltuname + "counters.rrd"
     finame = cntcom.BASEDIR + "imgs/" + ltuname + self.displayname + ".png"
     finame2 = cntcom.IMAGES + ltuname + self.displayname + ".png"
     rrdinput = cntcom.BASEDIR + "imgs/graph.txt"
     # ri.write("graph graf.png --start %d -e %d --step 60 -w 600 "%
     #  (time0, time0+60*60))
     # ri.write("graph graf.png -s teatime --step 60 -w 600 ")
     # ri.write("graph graf.png -s 17:55 --step 60 -w 600 ")  # -10 hours max.
     # time: -s now-10h   -s 1:0 -e 4:0
     # ri.write("graph graf.png -s now-10h --step 60 -w 600 ")
     fromto, pixwidth = cntcom.getStartEnd(cfg)
     ri = open(rrdinput, "w")
     ri.write("graph " + finame + " " + fromto + " --step 60 -w " + pixwidth + " ")
     cn = self.displayname
     if cn == "dead-busy_ts":
         ri.write("DEF:%s=%s:%s:AVERAGE " % ("busy", RRDDBname, "busy"))
         ri.write("DEF:%s=%s:%s:AVERAGE " % ("busy_ts", RRDDBname, "busy_ts"))
         # simplified version:
         # dead-busy_ts= busy*0.4/(busy_ts+1)
         # ri.write("CDEF:%s=busy,0.4,*,busy_ts,1,+,/ "%(cn))
         # right way:
         # dead-busy_ts= busy*0.4/1           if busy_ts==0
         # dead-busy_ts= busy*0.4/busy_ts     if busy_ts!=0
         ri.write("CDEF:%s=busy,0.4,*,busy_ts,0,EQ,1,busy_ts,IF,/ " % (cn))
     elif cn == "dead-l2a":
         ri.write("DEF:%s=%s:%s:AVERAGE " % ("busy", RRDDBname, "busy"))
         ri.write("DEF:%s=%s:%s:AVERAGE " % ("l2a_strobe", RRDDBname, "l2a_strobe"))
         # dead-busy_l2a= busy*0.4/1           if l2a==0
         # dead-busy_l2a= busy*0.4/l2a         if l2a!=0
         ri.write("CDEF:%s=busy,0.4,*,l2a_strobe,0,EQ,1,l2a_strobe,IF,/ " % (cn))
     elif cn == "busyOverTime":
         ri.write("DEF:%s=%s:%s:AVERAGE " % ("busy", RRDDBname, "busy"))
         ri.write("DEF:%s=%s:%s:AVERAGE " % ("time", RRDDBname, "time"))
         ri.write("CDEF:%s=busy,time,/ " % (cn))
     else:
         ri.write("DEF:%s=%s:%s:AVERAGE " % (cn, RRDDBname, cn))
     ri.write("LINE2:%s#%s:%s " % (cn, color, ltuname + "_" + cn))
     ri.close()
     # following allowed only without SElinux:
     # os.system("rrdtool - <"+rrdinput)
     pf = os.popen("rrdtool - <" + rrdinput)
     cmdout = pf.read()
     pf.close()
     coa = string.split(cmdout)
     if (len(coa) > 2) and (coa[1] == "OK"):
         return "<BR><IMG SRC=%s>\n" % (finame2)
     else:
         return "%s<BR><BR>\n" % (cmdout)
예제 #3
0
파일: ltus.py 프로젝트: AakaFosfor/trigger
 def newgraph(self):   # open, assign name, delete old files
   self.ri= open(self.rrdinput,"w")
   fromto,pixwidth= cntcom.getStartEnd(cfg)
   namesname= "img%d"%self.nimg ; self.nimg= self.nimg+1
   finame= cntcom.BASEDIR+"imgs/"+namesname+'.png'
   finame2= cntcom.IMAGES+namesname+'.png'
   #ri.write("graph graf.png --start %d -e %d --step 60 -w 600 "%
   #  (time0, time0+60*60))
   #ri.write("graph graf.png -s teatime --step 60 -w 600 ")
   #ri.write("graph graf.png -s 17:55 --step 60 -w 600 ")  # -10 hours max.
   # time: -s now-10h   -s 1:0 -e 4:0
   #ri.write("graph graf.png -s now-10h --step 60 -w 600 ")
   linlog=" "
   if cfg.yaxis=="log": linlog= " -o "
   #linlog= cfg.yaxis+cfg.grouping
   self.ri.write("graph "+finame+" "+fromto+" --step 60 -w "+pixwidth+linlog)
   # delete old files:
   return finame2