Beispiel #1
0
def save_data(meta, data):
    for v in data:
        result = Data(metadata=meta,
                      time=v['timeValue'],
                      value=v['value'],
                      units=v['valueUnits'])
        result.save()
Beispiel #2
0
def get_all_ma(host, port, uri, period, window=None, type="default"):
    """
    Get all values measurements values from the measurement archive.
    """
    urns = UrnStub.objects.filter(source="MA")
    
    curr_time = int(time.time())

    if (window == None):
        start = curr_time - period
        drop_time = datetime.fromtimestamp(float(start))
    else:
        start = curr_time - window
        drop_time = datetime.fromtimestamp(float(curr_time - period))
    
    print "Getting new data for ma", datetime.fromtimestamp(float(start)), "to", datetime.fromtimestamp(float(curr_time)) 

    for u in urns:
        
        if (type == "lamp"):
            body = makeSNMPMA_lamp_message(ifAddress=u.ifAddress, type=u.type, startTime=start)
        else:
            body = makeSNMPMAmessage(ifAddress=u.ifAddress, ifIndex=u.ifIndex, ifName=u.ifName, startTime=start)    

        response=None

        try:
            client = SimpleClient(host=host, port=port, uri=uri)
            if type == "lamp":
                response = client.send_request(body)
            else:
                response = client.send_request(body.tostring())
        except:
            print "could not poll ma!"
            continue

        values = parse_snmp_response(response, type)
        
        event = EventTypes.objects.get(event_type='http://ggf.org/ns/nmwg/characteristic/utilization/2.0')
        
        unit= None
        if len(values) > 0:
            if type=="lamp":
                unit = Units.objects.get(unit="psed")
            else:
                unit = Units.objects.get(unit=values[0]['valueUnits'])
            
        for v in values:
            m = Data(urn=u.urn, event_type=event, time=v['timeValue'], value=v['value'], units=unit)
            m.save()

    measurement_data = Data.objects.filter(time__lt=drop_time)
    for data in measurement_data:
        data.delete()

    print "Dropped measurements older than", drop_time
Beispiel #3
0
def save_data(meta, data):
    for v in data:
        result = Data(metadata=meta, time=v['timeValue'], value=v['value'], units=v['valueUnits'])
        result.save()
Beispiel #4
0
def get_all_mp(host, port, uri, period, window=None):
    """
    Get all values measurements values from the measurement point.
    """
    urns = UrnStub.objects.all()
    active_paths = PathDataModel.objects.filter(status="active")

    if (len(active_paths) < 1):
        return

    curr_time = int(time.time())

    if (window == None):
        start = curr_time - period
        drop_time = datetime.fromtimestamp(float(start))
    else:
        start = curr_time - window
        drop_time = datetime.fromtimestamp(float(curr_time - period))

    print "Getting new data for mp", datetime.fromtimestamp(
        float(start)), "to", datetime.fromtimestamp(float(curr_time))

    # this is horrible, but for now we assume the only interface we monitor is netqos02->qtr2 (GigabitEthernet9/23)
    # eventually we need a clean way to get the interface that the MP should query based on the path source
    for a in active_paths:
        ids = a.path_id
        ids += " GigabitEthernet9/23"

        #ids = ids[:-1]

        mp_query = msg_mp % ("198.124.220.3", "show terapaths", ids)

        try:
            client = SimpleClient(host=host, port=port, uri=uri)
            response = client.send_request(mp_query)
        except:
            print "could not poll mp!"
            return

        reader = psMessageReader(response)
        values = []
        for i in reader.getDataBlockIds():
            d = reader.getData(i)
            values = d.datumValues

            event = EventTypes.objects.get(
                event_type='http://ggf.org/ns/nmwg/tools/ciscossh/2.0/')

            unit = None
            if len(values) > 0:
                unit = Units.objects.get(id=0)

                # the MP is now returning packets that matched the policy-map on Qtr2
                # Qtr1 gives bytes in the reverse direction only...*sigh*
                # MTU is 1500, so we do some rough calculation to get bytes
                i = 0
                for v in values:
                    rate = None
                    prev = None

                    try:
                        prev = RawData.objects.filter(
                            urn=a.path_id).latest('time')
                    except (RawData.DoesNotExist):
                        print "no previous raw path measurement"

                    if ((not prev) or (v['value'] == 0)):
                        rate = 0
                    elif (v['value'] < prev.value):
                        rate = 0
                    else:
                        if ((float(curr_time) -
                             time.mktime(prev.time.timetuple())) < 30):
                            return
                        rate = ((float(v['value']) - float(prev.value)) *
                                1500) / (float(v['timeValue']) -
                                         time.mktime(prev.time.timetuple()))

                    m = Data(urn=a.path_id,
                             event_type=event,
                             time=datetime.fromtimestamp(float(
                                 v['timeValue'])),
                             value=rate,
                             units=unit)
                    m.save()

                    m = RawData(urn=a.path_id,
                                event_type=event,
                                time=datetime.fromtimestamp(
                                    float(v['timeValue'])),
                                value=v['value'],
                                units=unit)

                    m.save()
Beispiel #5
0
def get_all_ma(host, port, uri, period, window=None, type="default"):
    """
    Get all values measurements values from the measurement archive.
    """
    urns = UrnStub.objects.filter(source="MA")

    curr_time = int(time.time())

    if (window == None):
        start = curr_time - period
        drop_time = datetime.fromtimestamp(float(start))
    else:
        start = curr_time - window
        drop_time = datetime.fromtimestamp(float(curr_time - period))

    print "Getting new data for ma", datetime.fromtimestamp(
        float(start)), "to", datetime.fromtimestamp(float(curr_time))

    for u in urns:

        if (type == "lamp"):
            body = makeSNMPMA_lamp_message(ifAddress=u.ifAddress,
                                           type=u.type,
                                           startTime=start)
        else:
            body = makeSNMPMAmessage(ifAddress=u.ifAddress,
                                     ifIndex=u.ifIndex,
                                     ifName=u.ifName,
                                     startTime=start)

        response = None

        try:
            client = SimpleClient(host=host, port=port, uri=uri)
            if type == "lamp":
                response = client.send_request(body)
            else:
                response = client.send_request(body.tostring())
        except:
            print "could not poll ma!"
            continue

        values = parse_snmp_response(response, type)

        event = EventTypes.objects.get(
            event_type='http://ggf.org/ns/nmwg/characteristic/utilization/2.0')

        unit = None
        if len(values) > 0:
            if type == "lamp":
                unit = Units.objects.get(unit="psed")
            else:
                unit = Units.objects.get(unit=values[0]['valueUnits'])

        for v in values:
            m = Data(urn=u.urn,
                     event_type=event,
                     time=v['timeValue'],
                     value=v['value'],
                     units=unit)
            m.save()

    measurement_data = Data.objects.filter(time__lt=drop_time)
    for data in measurement_data:
        data.delete()

    print "Dropped measurements older than", drop_time
Beispiel #6
0
def get_all_mp(host, port, uri,period, window=None):
    """
    Get all values measurements values from the measurement point.
    """
    urns = UrnStub.objects.all()
    active_paths = PathDataModel.objects.filter(status="active");

    if (len(active_paths) < 1):
        return

    curr_time = int(time.time())
    
    if (window == None):
        start = curr_time - period
        drop_time = datetime.fromtimestamp(float(start))
    else:
        start = curr_time - window
        drop_time = datetime.fromtimestamp(float(curr_time - period))

    print "Getting new data for mp", datetime.fromtimestamp(float(start)), "to", datetime.fromtimestamp(float(curr_time)) 

    # this is horrible, but for now we assume the only interface we monitor is netqos02->qtr2 (GigabitEthernet9/23)
    # eventually we need a clean way to get the interface that the MP should query based on the path source
    for a in active_paths:
        ids = a.path_id
        ids += " GigabitEthernet9/23"

        #ids = ids[:-1]

        mp_query = msg_mp % ("198.124.220.3", "show terapaths", ids)

        try:
            client = SimpleClient(host=host, port=port, uri=uri)
            response = client.send_request(mp_query)
        except: 
            print "could not poll mp!"
            return

        reader= psMessageReader(response)
        values = []
        for i in reader.getDataBlockIds():
            d = reader.getData(i)
            values = d.datumValues
                
            event = EventTypes.objects.get(event_type='http://ggf.org/ns/nmwg/tools/ciscossh/2.0/')
            
            unit = None
            if len(values) > 0:
                unit = Units.objects.get(id=0)
                
                # the MP is now returning packets that matched the policy-map on Qtr2
                # Qtr1 gives bytes in the reverse direction only...*sigh*
                # MTU is 1500, so we do some rough calculation to get bytes
                i = 0              
                for v in values:
                    rate=None
                    prev=None

                    try:
                        prev = RawData.objects.filter(urn=a.path_id).latest('time')
                    except (RawData.DoesNotExist):
                        print "no previous raw path measurement"

                    if ((not prev) or (v['value'] == 0)):
                        rate = 0
                    elif (v['value'] < prev.value):
                        rate = 0
                    else:
                        if ((float(curr_time) - time.mktime(prev.time.timetuple())) < 30):
                            return
                        rate = ((float(v['value'])-float(prev.value))*1500)/(float(v['timeValue'])-time.mktime(prev.time.timetuple()))
                        
                    m = Data(urn=a.path_id, 
                             event_type=event, 
                             time=datetime.fromtimestamp(float(v['timeValue'])),
                             value=rate,
                             units=unit)
                    m.save()

                    m = RawData(urn=a.path_id,
                                event_type=event,
                                time=datetime.fromtimestamp(float(v['timeValue'])),
                                value=v['value'],
                                units=unit)

                    m.save()