def _convertFile(filename):
    import rrdtool
    try:
        if rrdtool.info(filename)['ds[ds0].type'] == 'COUNTER':
            rrdtool.tune(filename, '-d', 'ds0:DERIVE', '-i', 'ds0:0')
    except KeyError:
        pass
def graph( name ):
	agentPath = rrdPath + name + "/"

	fname="netPred.rrd"
	title="Deteccion de comportamiento anomalo"
	endDate = rrdtool.last(str(agentPath + fname)) #ultimo valor del XML
	begDate = endDate - 36000

	rrdtool.tune(str(agentPath + fname),'--alpha','0.1')
	ret = rrdtool.graph(str(agentPath)+"netHW.png",
                        '--start', str(begDate), '--end', str(endDate), '--title=' + title,
                        "--vertical-label=Bytes/s",
                        '--slope-mode',
                        "DEF:obs="       + str(agentPath + fname) + ":inoctets:AVERAGE",
                        #"DEF:outoctets=" + str(agentPath + fname) + ":outoctets:AVERAGE",
                        "DEF:pred="      + str(agentPath + fname) + ":inoctets:HWPREDICT",
                        "DEF:dev="       + str(agentPath + fname) + ":inoctets:DEVPREDICT",
                        "DEF:fail="      + str(agentPath + fname) + ":inoctets:FAILURES",

                     #"RRA:DEVSEASONAL:1d:0.1:2",
                     #"RRA:DEVPREDICT:5d:5",
                     #"RRA:FAILURES:1d:7:9:5""
                        "CDEF:scaledobs=obs,8,*",
                        "CDEF:upper=pred,dev,2,*,+",
                        "CDEF:lower=pred,dev,2,*,-",
                        "CDEF:scaledupper=upper,8,*",
                        "CDEF:scaledlower=lower,8,*",
                        "CDEF:scaledpred=pred,8,*",
                        "TICK:fail#FDD017:1.0:Fallas",
                        "LINE3:scaledobs#00FF00:In traffic",
                        "LINE1:scaledpred#FF00FF:Prediccion\\n",
                        #"LINE1:outoctets#0000FF:Out traffic",
                        "LINE1:scaledupper#ff0000:Upper Bound Average bits in\\n",
                        "LINE1:scaledlower#0000FF:Lower Bound Average bits in")
Exemple #3
0
def graficarNoLineal(archivo,alfa):
        title="Deteccion de comportamiento anomalo, valor de Alpha "+str(alfa)
        rrdname="rrd/"+archivo+".rrd"
        endDate = rrdtool.last(rrdname) #ultimo valor del XML
        begDate = endDate - 86000

        rrdtool.tune(rrdname, '--alpha', str(alfa))
        ret = rrdtool.graph("png/netPalphaBajoFallas.png",
                                '--start', str(begDate), '--end', str(endDate), '--title=' + title,
                                "--vertical-label=Bytes/s",
                                '--slope-mode',
                                "DEF:obs=" + rrdname + ":inoctets:AVERAGE",
                                "DEF:outoctets=" + rrdname + ":outoctets:AVERAGE",
                                "DEF:pred=" + rrdname + ":inoctets:HWPREDICT",
                                "DEF:dev=" + rrdname + ":inoctets:DEVPREDICT",
                                "DEF:fail=" + rrdname + ":inoctets:FAILURES",

                        #"RRA:DEVSEASONAL:1d:0.1:2",
                        #"RRA:DEVPREDICT:5d:5",
                        #"RRA:FAILURES:1d:7:9:5""
                                "CDEF:scaledobs=obs,8,*",
                                "CDEF:upper=pred,dev,2,*,+",
                                "CDEF:lower=pred,dev,2,*,-",
                                "CDEF:scaledupper=upper,8,*",
                                "CDEF:scaledlower=lower,8,*",
                                "CDEF:scaledpred=pred,8,*",
                        "TICK:fail#FDD017:1.0:Fallas",
                        "LINE3:scaledobs#00FF00:In traffic",
                        "LINE1:scaledpred#FF00FF:Prediccion\\n",
                        #"LINE1:outoctets#0000FF:Out traffic",
                        "LINE1:scaledupper#ff0000:Upper Bound Average bits in\\n",
                        "LINE1:scaledlower#0000FF:Lower Bound Average bits in")
    def cutover(self, unused):
        import os
        import rrdtool
        from Products.ZenModel.PerformanceConf import PERF_ROOT
        CPU = 'cpu_cpu.rrd'

        for d, _, files in os.walk(PERF_ROOT):
            if CPU in files:
                rrdtool.tune(os.path.join(d, CPU),'-d', 'ds0:DERIVE', '-i', 'ds0:0')
Exemple #5
0
    def add_datasource_to_rrd(self, fname, dsname):
        """Add a new data source to an exisitng file.

        Add missing Data Sources (DS) to existing Round Robin Archive (RRA):
        See init_rrd for details.
        """
        ds_def = "DS:%s:ABSOLUTE:%s:0:U" % (dsname, rrdstep * 2)
        rrdtool.tune(fname, ds_def)
        self._dprint("[rrd] added DS %s to %s" % (dsname, fname))
    def process(self, fullpath):
        "convert a single file"
        log.debug("processing %s" % fullpath)
        newpath = os.path.join(os.path.dirname(fullpath),
                               '.' + os.path.basename(fullpath))
        # get type, old step
        info = rrdtool.info(fullpath)
        dataType = info['ds[ds0].type']

        try:
            os.unlink(newpath)
        except OSError:
            pass

        rraList = []
        for rraIndex in count():
            rra = {}
            rra['pdp_per_row'] = info.get('rra[%s].pdp_per_row' % rraIndex)
            rra['rows'] = info.get('rra[%s].rows' % rraIndex)
            if rra['pdp_per_row'] is None or rra['rows'] is None:
                break
            rraList.append(rra)

        # Collect some information about the current file:
        # how far back can the data go?
        earliest = info['last_update']

        # how wide is the biggest data point?
        biggest = 0
            
        for rra in rraList:
            size = rra['pdp_per_row'] * info['step']
            earliest = min(earliest, info['last_update'] - rra['rows'] * size)
            biggest = max(biggest, size)
            
        # create a file with the correct step to accept the data
        rrdtool.create(
            newpath,
            'DS:ds0:%s:%d:U:U' % (dataType, biggest * 2),
            '--start', str(earliest),
            '--step', str(self.options.step),
            *self.defaultRRDCommand.split())
            
        # extract the time and values from each archive
        updates = {}
        
        for rra in rraList:            
            self.processRRA(fullpath, rra, info, updates)
            
        # get the times in order
        updates = updates.items()
        updates.sort()
        rrdtool.update(newpath, *[('%d@%s' % (t, v)) for t, v in updates])
        # use a reasonable heartbeat
        rrdtool.tune(newpath, '-h','ds0:%d' % (self.options.step*3))
        if self.options.commit:
            os.rename(newpath, fullpath)
def _convertFile(filename):
    import rrdtool
    try:
        if rrdtool.info(filename)['ds[ds0].type'] == 'COUNTER':
            rrdtool.tune(filename,
                         '-d', 'ds0:DERIVE',
                         '-i', 'ds0:0')
    except KeyError:
        pass
    def cutover(self, unused):
        import os
        import rrdtool
        from Products.ZenModel.PerformanceConf import PERF_ROOT
        CPU = 'cpu_cpu.rrd'

        for d, _, files in os.walk(PERF_ROOT):
            if CPU in files:
                rrdtool.tune(os.path.join(d, CPU), '-d', 'ds0:DERIVE', '-i',
                             'ds0:0')
 def UpdateBase(self, tipo, nombre):
     if tipo == 0:
         aux = "DS:" + nombre + ":GAUGE:60:U:U"
         print(aux)
         ret = rrdtool.tune("Prac1.rrd", aux)
     if tipo == 1:
         ret = rrdtool.tune("Prac1.rrd", "DEL:" + nombre)
     rrdtool.dump(self.nombre + ".rrd", self.nombre + ".xml")
     if ret:
         print(rrdtool.error())
    def process(self, fullpath):
        "convert a single file"
        log.debug("processing %s" % fullpath)
        newpath = os.path.join(os.path.dirname(fullpath),
                               '.' + os.path.basename(fullpath))
        # get type, old step
        info = rrdtool.info(fullpath)
        dataType = info['ds[ds0].type']

        try:
            os.unlink(newpath)
        except OSError:
            pass

        rraList = []
        for rraIndex in count():
            rra = {}
            rra['pdp_per_row'] = info.get('rra[%s].pdp_per_row' % rraIndex)
            rra['rows'] = info.get('rra[%s].rows' % rraIndex)
            if rra['pdp_per_row'] is None or rra['rows'] is None:
                break
            rraList.append(rra)

        # Collect some information about the current file:
        # how far back can the data go?
        earliest = info['last_update']

        # how wide is the biggest data point?
        biggest = 0

        for rra in rraList:
            size = rra['pdp_per_row'] * info['step']
            earliest = min(earliest, info['last_update'] - rra['rows'] * size)
            biggest = max(biggest, size)

        # create a file with the correct step to accept the data
        rrdtool.create(newpath, 'DS:ds0:%s:%d:U:U' % (dataType, biggest * 2),
                       '--start', str(earliest), '--step',
                       str(self.options.step), *self.defaultRRDCommand.split())

        # extract the time and values from each archive
        updates = {}

        for rra in rraList:
            self.processRRA(fullpath, rra, info, updates)

        # get the times in order
        updates = updates.items()
        updates.sort()
        rrdtool.update(newpath, *[('%d@%s' % (t, v)) for t, v in updates])
        # use a reasonable heartbeat
        rrdtool.tune(newpath, '-h', 'ds0:%d' % (self.options.step * 3))
        if self.options.commit:
            os.rename(newpath, fullpath)
Exemple #11
0
def rrd_tune_ds_max(path, ds_max):
    ''' tune max for all DS in rrd '''
    try:
        logging.warn("tuning maximum value to %s for all DS in rrd %s", ds_max, path)
        tune_ds = list()
        for tune in rrd_get_ds_list(path):
            tune_ds.append("--maximum")
            tune_ds.append(str("%s:%s" % (tune, ds_max)))
        rrdtool.tune(path, tune_ds)
    except (rrdtool.OperationalError, rrdtool.ProgrammingError) as e:
        logging.error("failed to tune max for %s: %s", path, str(e))
Exemple #12
0
def actualizarHW(cadena,comunidad,host,puerto,rrd):
	print 'Entro actualizarHW ',cadena,comunidad,host,puerto,rrd
	
	total_input_traffic = 0
	total_output_traffic = 0
	rrdpath="./RRD_HW/"
	pngpath="./IMG_HW/"
	fname=rrd+".rrd"
	pngfname=rrd+".png"
	#Verifica que exista una rrd asociada al host, en caso de no existir crea una rrd nueva
	archivo_rrd = Path(rrdpath+fname)
	if archivo_rrd.is_file() == False:
		crearRRD.crearHW(rrdpath+fname)
		print "rrd HW Creada... en",rrdpath,fname
	else:
		print "Abriendo rrd HW..."

	endDate = rrdtool.last(rrdpath+fname) #ultimo valor del XML
	begDate = endDate - 3600
	#Inicia proceso de adquisicion de datos HW
	while 1:		
		total_input_traffic = int(consultaSNMP('public','10.100.71.100',1024,'1.3.6.1.2.1.2.2.1.18.1'))
		total_output_traffic = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.2.2.1.16.3'))
		
		'''total_tcp_established = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.9.0'))
		
		input_tcp_segs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.10.0'))
		output_tcp_segs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.6.11.0'))

		input_icmp_msgs = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.5.1.0'))	 	
		output_icmp_msgs = int( consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.5.14.0'))
		
		input_snmp_getReq = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.11.15.0'))
		output_snmp_getResp = int(consultaSNMP(comunidad,host,puerto,'1.3.6.1.2.1.11.28.0'))'''
		
		#valor = str(rrdtool.last(rrdpath+fname)+30) + str(total_input_traffic) + ':' + str(total_output_traffic) + ':' + str(total_tcp_established) + ':' + str(input_tcp_segs) + ':' + str(output_tcp_segs) + ':' + str(input_icmp_msgs) + ':' + str(output_icmp_msgs) + ':' + str(input_snmp_getReq) + ':' + str(output_snmp_getResp)
		
		#valor = str(rrdtool.last(rrdpath+fname)+30)+":" + str(total_input_traffic) + ':' + str(total_output_traffic) + ':' + str(total_tcp_established) + ':' + str(input_tcp_segs) + ':' + str(output_tcp_segs) + ':' + str(input_icmp_msgs) + ':' + str(output_icmp_msgs) + ':' + str(input_snmp_getReq) + ':' + str(output_snmp_getResp)
		valor = str(rrdtool.last(rrdpath+fname)+30)+":" + str(total_input_traffic)
		print 'Valor: ',valor
		rrdtool.update(rrdpath+fname,valor)
		rrdtool.dump(rrdpath+fname,rrd+'.xml')
		#print "actualizar: ",rrdpath,fname, rrd
		rrdtool.tune(rrdpath+fname,'--alpha','0.1')
		#time.sleep(1)			
	if ret:
		print rrdtool.error()
		time.sleep(300)
Exemple #13
0
def graficarHW(alpha, pestana):
    fname1 = "bdrrdtool/netPred.rrd"
    title = "Deteccion de comportamiento anomalo, valor de Alpha " + str(alpha)
    endDate = rrdtool.last(fname1)
    begDate = endDate - 1800
    while 1:
        rrdtool.tune(fname1, '--alpha', '0.1')
        ret = rrdtool.graph(
            "graficas/predHW.png",
            '--start',
            str(endDate),
            '--title=' + title,
            "--vertical-label=Bytes/s",
            '--slope-mode',
            "DEF:obs=" + fname1 + ":inoctets:AVERAGE",
            "DEF:outoctets=" + fname1 + ":outoctets:AVERAGE",
            "DEF:pred=" + fname1 + ":inoctets:HWPREDICT",
            "DEF:dev=" + fname1 + ":inoctets:DEVPREDICT",
            "DEF:fail=" + fname1 + ":inoctets:FAILURES",

            # "RRA:DEVSEASONAL:1d:0.1:2",
            # "RRA:DEVPREDICT:5d:5",
            # "RRA:FAILURES:1d:7:9:5""
            "CDEF:scaledobs=obs,8,*",
            "CDEF:upper=pred,dev,2,*,+",
            "CDEF:lower=pred,dev,2,*,-",
            "CDEF:scaledupper=upper,8,*",
            "CDEF:scaledlower=lower,8,*",
            "CDEF:scaledpred=pred,8,*",
            "TICK:fail#FDD017:1.0:Fallas",
            "LINE3:scaledobs#00FF00:In traffic",
            "LINE1:scaledpred#FF00FF:Prediccion\\n",
            # "LINE1:outoctets#0000FF:Out traffic",
            "LINE1:scaledupper#ff0000:Upper Bound Average bits in\\n",
            "LINE1:scaledlower#0000FF:Lower Bound Average bits in")

        img1 = PhotoImage(file="graficas/predHW.png")
        a1 = Label(pestana, image=img1)
        a1.image = img1
        a1.grid(row=4, column=0)
        time.sleep(1)
    def createDatabase(self):
        if os.path.isfile(self.fileName):
            return

        dataSources = [
            BuildDataSourceString(rrdConstants.DS_NETWORK,
                                  rrdConstants.TYPE_GAUGE)
        ]

        errorCode = rrdtool.create(self.fileName, '--start', rrdConstants.NOW,
                                   '--step', rrdConstants.STEP, *dataSources,
                                   *rrdConstants.RRA_DEFAULT_SETTINGS,
                                   rrdConstants.RRA_HW_SETTINGS)

        if errorCode:
            logging.error('Error creating RRDTool file : %s', rrdtool.error())
            raise

        rrdtool.tune(self.fileName, '--failure-threshold',
                     rrdConstants.HW_FAILURE_THRESHOLD, '--window-length',
                     rrdConstants.HW_WINDOW_LENGTH)
Exemple #15
0
def rrd_tune(section, target_directory=None):
    if target_directory is None:
        target_directory = config.rrd_directory

    DSlist_rrdfile = set(rrd_info(section))
    DSlist_lib = set(map(get_DSname, KEYINDEX[section]))

    missingDS = DSlist_lib - DSlist_rrdfile

    rrd_parameter = [get_filename(section, target_directory, "rrd")]

    DStype = "COUNTER"
    if section == "Cache DB RRsets":
        DStype = "ABSOLUTE"


    for DSname in missingDS:
        rrd_parameter.append(
            "DS:{DSname}:{DStype}:90:U:U".format(DSname=DSname, DStype=DStype))

    for line in rrd_parameter:
        print line

    rrdtool.tune(*rrd_parameter)
Exemple #16
0
def graficarNoLineal1(archivo):
        title="Deteccion de comportamiento anomalo"
        fname="rrd/"+archivo+".rrd"
        endDate = rrdtool.last(fname) #ultimo valor del XML
        begDate = endDate - 40000
        DatosAyer=begDate - 86400
        FinAyer=endDate - 86400
        scale = 8
        rrdtool.tune(fname, '--alpha', '0.9')
        rrdtool.tune(fname, '--beta', '0.0035')
        rrdtool.tune(fname, '--gamma', '0.1')
        ret = rrdtool.graph("png/predAC.png",
                                '--start', str(begDate), '--end', str(endDate), '--title=' + title,
                                "--vertical-label=Bytes/s",
                                '--slope-mode',
                                "DEF:obs=" + fname + ":inoctets:AVERAGE",
                                "DEF:obsAyer=" + fname + ":inoctets:AVERAGE:start="+str(DatosAyer)+":end="+str(FinAyer),
                                "DEF:pred=" + fname + ":inoctets:HWPREDICT",
                                "DEF:dev=" + fname + ":inoctets:DEVPREDICT",
                                "DEF:fail=" + fname + ":inoctets:FAILURES",
                                'SHIFT:obsAyer:86400',
                        #"RRA:DEVSEASONAL:1d:0.1:2",
                        #"RRA:DEVPREDICT:5d:5",
                        #"RRA:FAILURES:1d:7:9:5""
                                "CDEF:scaledobs=obs,"+str(scale)+",*",
                                "CDEF:scaledobsAyer=obsAyer,"+str(scale)+",*",
                                "CDEF:upper=pred,dev,2,*,+",
                                "CDEF:lower=pred,dev,2,*,-",
                                "CDEF:scaledupper=upper,"+str(scale)+",*",
                                "CDEF:scaledlower=lower,"+str(scale)+",*",
                                "CDEF:scaledpred=pred,"+str(scale)+",*",
                        "TICK:fail#FDD017:1.0: Fallas",
                        "AREA:scaledobsAyer#9C9C9C:Ayer",
                        "LINE3:scaledobs#00FF00:In traffic",
                        "LINE1:scaledpred#FF00FF:Prediccion",
                        #"LINE1:outoctets#0000FF:Out traffic",
                        "LINE1:scaledupper#ff0000:Upper Bound Average bits in",
        "LINE1:scaledlower#0000FF:Lower Bound Average bits in")
Exemple #17
0
def update_heartbeat(basename,heartbeat):
#    print "Updating heartbeat with %d" % heartbeat
    rrdtool.tune(basename + ".rrd",
                 '--heartbeat', 'mbps:%d' % heartbeat)
    def TuneHoltData(self, dp):
        # Alpha
        rrdtool.tune(self.context().path(dp),'--alpha',str(self.alpha))

        # Beta
        rrdtool.tune(self.context().path(dp),'--beta',str(self.beta))

        # Gamma
        rrdtool.tune(self.context().path(dp),'--gamma',str(self.gamma))
        rrdtool.tune(self.context().path(dp),'--gamma-deviation',str(self.gamma))

        # Delta
        rrdtool.tune(self.context().path(dp),'--deltapos',str(self.delta))
        rrdtool.tune(self.context().path(dp),'--deltaneg',str(self.delta))


        # Check that these actually changed otherwise we will reset
        # violation counts to 0
        data = rrdtool.info(self.context().path(dp))
        rrasearch = re.compile('^rra\[(\d+)\]\.(\S+)')
        sorted_keys=data.keys()
        sorted_keys.sort()
        for key in sorted_keys:
            value=data[key]
            rra_match=rrasearch.search(key)
            if rra_match:
                rranum,rraprop=rra_match.groups()

                # Failure Threshold
                if rraprop == 'failure_threshold' and value != self.threshold:
                    rrdtool.tune(self.context().path(dp),'--failure-threshold',str(self.threshold))

                # Window Length
                if rraprop == 'window_length' and value != self.window:
                    rrdtool.tune(self.context().path(dp),'--window-length',str(self.window))
Exemple #19
0
import time
import rrdtool

fname = "netPred.rrd"
pngfname = "predict.png"
title = "Deteccion de comportamiento anomalo, valor de Alpha 0.1"
endDate = rrdtool.last(fname)  #ultimo valor del XML
begDate = endDate - 86000

rrdtool.tune(fname, '--alpha', '0.1')  #tune permite cambiar el valor de alfa
ret = rrdtool.graph(
    "netPalphaBajoFallas.png",
    '--start',
    str(begDate),
    '--end',
    str(endDate),
    '--title=' + title,
    "--vertical-label=Bytes/s",
    '--slope-mode',
    "DEF:obs=" + fname + ":inoctets:AVERAGE",
    "DEF:outoctets=" + fname + ":outoctets:AVERAGE",
    "DEF:pred=" + fname + ":inoctets:HWPREDICT",
    "DEF:dev=" + fname + ":inoctets:DEVPREDICT",
    "DEF:fail=" + fname +
    ":inoctets:FAILURES",  #coleccion de fallas rrd failures

    #"RRA:DEVSEASONAL:1d:0.1:2",
    #"RRA:DEVPREDICT:5d:5",
    #"RRA:FAILURES:1d:7:9:5""
    "CDEF:scaledobs=obs,8,*",
    "CDEF:upper=pred,dev,2,*,+",
 def setMin(self, value):
     for d,_, files in os.walk(zenPath("perf")):
         for f in [f for f in files if rrd.match(f)]:
             rrdtool.tune(os.path.join(d, f), '-i', 'ds0:' + value)
def EjecutarP(hilo, comunidad, ip, port, name):
    agentPath = lbPathmc + name + "/"
    fname = "netPred.rrd"

    consulta = int(consultaSNMP(comunidad, ip, port, '1.3.6.1.2.1.2.2.1.10.1'))
    valor = "N:" + str(consulta)
    ret = rrdtool.update(str(agentPath + name + fname), valor)
    rrdtool.dump(str(agentPath + name + fname),
                 str(agentPath) + name + 'netP.xml')

    title = "Deteccion de comportamiento anomalo"

    ultimo = rrdtool.last(str(agentPath + name + fname))

    inicio = ultimo - 300
    ayerInicio = (inicio - 300)
    ayerFinal = ultimo - 300
    primero = rrdtool.first(str(agentPath + name + fname))
    #cambia el valor de alfa
    rrdtool.tune(str(agentPath + name + fname), '--alpha', '0.8')
    #rrdtool.tune(str(agentPath + name + fname),'--beta','0.1')
    #rrdtool.tune(str(agentPath + name + fname),'--gamma','0.1')

    ret = rrdtool.graphv(
        str(agentPath + name) + "prediccion.png",
        '--start',
        str(inicio),
        '--end',
        str(ultimo + 5),
        '--title=' + title,
        "--vertical-label=Bytes/s",
        '--slope-mode',
        "DEF:obs=" + str(agentPath + name + fname) + ":inoctets:AVERAGE",
        #"DEF:outoctets=" + str(agentPath + fname) + ":outoctets:AVERAGE",
        "DEF:pred=" + str(agentPath + name + fname) + ":inoctets:HWPREDICT",
        "DEF:dev=" + str(agentPath + name + fname) + ":inoctets:DEVPREDICT",
        "DEF:fail=" + str(agentPath + name + fname) + ":inoctets:FAILURES",
        "DEF:yvalue=" + str(agentPath + name + fname) +
        ":inoctets:AVERAGE:start=" + str(ayerInicio) + ":end=" +
        str(ayerFinal),
        'SHIFT:yvalue:300',
        #"RRA:DEVSEASONAL:1d:0.1:2",
        #"RRA:DEVPREDICT:5d:5",
        #"RRA:FAILURES:1d:7:9:5""
        "CDEF:scaledh=yvalue,8,*",
        "CDEF:scaledobs=obs,8,*",
        "CDEF:upper=pred,dev,2,*,+",
        "CDEF:lower=pred,dev,2,*,-",
        "CDEF:scaledupper=upper,8,*",
        "CDEF:scaledlower=lower,8,*",
        "CDEF:scaledpred=pred,8,*",
        "AREA:scaledh#C9C9C9:Yesterday",
        "TICK:fail#FDD017:1.0:FFallas",
        "LINE3:scaledobs#00FF00:In traffic",
        "LINE1:scaledpred#FF00FF:Prediccion\\n",
        #"LINE1:outoctets#0000FF:Out traffic",
        "LINE1:scaledupper#ff0000:Upper Bound Average bits in\\n",
        "LINE1:scaledlower#0000FF:Lower Bound Average bits in",
        "VDEF:lastfail=fail,LAST",
        #"VDEF:max=fail,MAXIMUM",
        #"VDEF:min=fail,MINIMUM",
        "PRINT:lastfail: %c :strftime",
        "PRINT:lastfail:%6.2lf %S ",
        'PRINT:fail:MIN:%1.0lf',
        'PRINT:fail:MAX:%1.0lf',
    )

    #bandera=0
    time_falla = ret['print[0]']
    ultima_falla = ret['print[1]']
    fmin = ret['print[2]']
    fmax = ret['print[3]']

    #f = open(str(agentPath)+"log.txt","a")
    #print("Fallas "+ str(ultima_falla) +"----"+ str(time_falla))

    if float(ultima_falla) == 1:
        if hilo.ban == 0:  # inicio de falla bandera de 0 a 1
            hilo.inicio = str(time_falla)
            hilo.ban = 1
            print("INICIO DE FALLA")
            if hilo.unaVez == 0:
                sendAlertEmail(
                    "Agente : " + name + " Inicio aberración : " +
                    str(hilo.inicio),
                    str(agentPath) + "prediccion.png",
                    str(agentPath + name + fname))
                hilo.unaVez = 1
        elif hilo.ban == 1:  # aun no termina la falla y gardo el ultimo tiempo
            hilo.fin = str(time_falla)
            print("CONTINUA" + hilo.fin)
    elif float(ultima_falla
               ) == 0 and hilo.ban == 1:  #termina la falla bandera de 1 a 0
        hilo.ban = 0

        f = open(str(lbPathmc) + "log.txt", "a")
        f.write(str("\tFalla " + name + "\n"))
        f.write("Inicio : " + str(hilo.inicio) + "\n")
        if hilo.fin == "":
            hilo.fin = str(time_falla)
            f.write("Fin: " + str(hilo.fin) + "\n")
        else:
            f.write("Fin: " + str(hilo.fin) + "\n")
        print("FIN DE FALLA" + hilo.fin)
        if hilo.unaVez == 1:
            sendAlertEmail(
                "Agente : " + name + " Fin aberración : " + str(hilo.fin),
                str(agentPath) + "prediccion.png",
                str(agentPath + name + fname))
            hilo.unaVez = 2
        hilo.fin = ""
        hilo.inicio = ""
        f.close()
Exemple #22
0
def addRRA(rrdFile, rraSpec):
    rrdtool.tune(rrdFile, rraSpec)
Exemple #23
0
def addDataSource(rrdFile, dsSpec):
    rrdtool.tune(rrdFile, dsSpec)
Exemple #24
0
 def setMin(self, value):
     for d, _, files in os.walk(zenPath("perf")):
         for f in [f for f in files if rrd.match(f)]:
             rrdtool.tune(os.path.join(d, f), '-i', 'ds0:' + value)
Exemple #25
0
        #if the address has not been already discovered, add it to newAddresses
        if not seen:
            newAddresses.append(address)

for a in newAddresses:
    #Build a string in the form of "[alias(empty)]:[address]:[timestamp]:[graph(y/n)]:[min-alarm]:[max-alarm]:[lasttemp]\n"
    sensorLine = ':' + a + ':' + str(int(mktime(localtime()))) + ':y:20:30:NaN\n'
    #Append it to the new file line array
    newFile.append(sensorLine)

if dbExists():
    for a in gAddresses:
        claimed = False #Has it been claimed in the RRD?
        foundUnclaimed = False #Has an unclaimed DS been found?
        firstUnclaimed = '-1' #ID of the first seen unclaimed DS
        for dsName in rrdtool.fetch(adbFilename, 'AVERAGE')[1]:
            if dsName == a:
                claimed = True
            if dsName.split('_')[0] == 'unclaimed' and not foundUnclaimed:
                foundUnclaimed = True
                firstUnclaimed = dsName.split('_')[1]
        if not claimed:
            rrdtool.tune(adbFilename, '--data-source-rename', 'unclaimed_'+firstUnclaimed+':'+a)
            rrdtool.tune(gdbFilename, '--data-source-rename', 'unclaimed_'+firstUnclaimed+':'+a)

newFile.sort()  #Sort the sensors alphabetically, by alias (first param on the line)
sFile = open(sFilename,'w') #sensors file, open for writing
sFile.writelines(newFile)
sFile.close()

Exemple #26
0
import time
import rrdtool

fname = "netPred.rrd"
pngfname = "predict.png"
title = "Deteccion de comportamiento anomalo, valor de Alpha 0.1"
endDate = rrdtool.last(fname)  #ultimo valor del XML
begDate = endDate - 86000

rrdtool.tune(fname, '--alpha', '0.1')
ret = rrdtool.graph(
    "netPalphaBajoFallas.png",
    '--start',
    str(begDate),
    '--end',
    str(endDate),
    '--title=' + title,
    "--vertical-label=Bytes/s",
    '--slope-mode',
    "DEF:obs=" + fname + ":inoctets:AVERAGE",
    "DEF:outoctets=" + fname + ":outoctets:AVERAGE",
    "DEF:pred=" + fname + ":inoctets:HWPREDICT",
    "DEF:dev=" + fname + ":inoctets:DEVPREDICT",
    "DEF:fail=" + fname + ":inoctets:FAILURES",

    #"RRA:DEVSEASONAL:1d:0.1:2",
    #"RRA:DEVPREDICT:5d:5",
    #"RRA:FAILURES:1d:7:9:5""
    "CDEF:scaledobs=obs,8,*",
    "CDEF:upper=pred,dev,2,*,+",
    "CDEF:lower=pred,dev,2,*,-",
Exemple #27
0
    def TuneHoltData(self, dp):
        # Alpha
        rrdtool.tune(self.context().path(dp), '--alpha', str(self.alpha))

        # Beta
        rrdtool.tune(self.context().path(dp), '--beta', str(self.beta))

        # Gamma
        rrdtool.tune(self.context().path(dp), '--gamma', str(self.gamma))
        rrdtool.tune(self.context().path(dp), '--gamma-deviation',
                     str(self.gamma))

        # Delta
        rrdtool.tune(self.context().path(dp), '--deltapos', str(self.delta))
        rrdtool.tune(self.context().path(dp), '--deltaneg', str(self.delta))

        # Check that these actually changed otherwise we will reset
        # violation counts to 0
        data = rrdtool.info(self.context().path(dp))
        rrasearch = re.compile('^rra\[(\d+)\]\.(\S+)')
        sorted_keys = data.keys()
        sorted_keys.sort()
        for key in sorted_keys:
            value = data[key]
            rra_match = rrasearch.search(key)
            if rra_match:
                rranum, rraprop = rra_match.groups()

                # Failure Threshold
                if rraprop == 'failure_threshold' and value != self.threshold:
                    rrdtool.tune(self.context().path(dp),
                                 '--failure-threshold', str(self.threshold))

                # Window Length
                if rraprop == 'window_length' and value != self.window:
                    rrdtool.tune(self.context().path(dp), '--window-length',
                                 str(self.window))
Exemple #28
0
def update_heartbeat(basename, heartbeat):
    print "Updating heartbeat with %d" % heartbeat
    rrdtool.tune(basename + ".rrd", "--heartbeat", "units:%d" % heartbeat)