コード例 #1
0
def get_all_info_since(seqnumber):
    """
    return all the information in the log file since the last seen seq number as a list
    Attach the current client timestamp, and time since the information was monitored (relative_timestamp)
    """
    file_names = []
    last_seen_seq = seqnumber
    system_info= {}


    for path, dir, files in os.walk(config.PATH):
        for name in files:
            if name != 'current_sequence' and name != 'last_seen':
                file_names.append(int(name))

    file_current_sequence_number = open(config.PATH+'/current_sequence', 'r')

    for seq in xrange(last_seen_seq+1, int(file_current_sequence_number.read()) +1):
        path = config.PATH + '/'+str(seq)
        if os.path.exists(path):
            temp_file = open (config.PATH + '/'+str(seq), 'r')
            value = ast.literal_eval(temp_file.read())
            # Do not persist current_timestamp and relative_timestamp. They are calculated every time a request is received in order to account for newer calculations in case of network partitions.
            value['relative_timestamp'] = config.get_current_system_timestamp()-value['monitored_timestamp']
            system_info[str(seq)] = value
            temp_file.close()
        else:
            print "[ERROR]: A file with sequence number not seen has been deleted:: ", seq
    file_current_sequence_number.close()
    write_last_seen_sequence_number(last_seen_seq)

    #print system_info.items()
    return system_info
コード例 #2
0
def monitorStore():
    """
    Get monitored information
    Attach the sequence number
    Attach timestamp
    Store in the log file
    delete seen entries
    """
    # commented to use psutil system info system_info = systeminfo.get_all_info()

    system_info = nodeinfo.node_all()

    system_info ['monitored_timestamp'] = config.get_current_system_timestamp()

    # Attach node api info to system info
    rd_tags = getapi.get_nodeinfo_from_API()
    if rd_tags is not None:
        system_info.update(rd_tags)

    # Attach sliver info to system info
    system_info.update(sliverinfo.collectAllDataAPI())


    ## Write current sequence number to file "current_sequence"
    if os.path.exists(config.PATH + '/current_sequence'):
        file_current_sequence_number = open(config.PATH+'/current_sequence', 'r+')
        print "File exists"
        current_sequence_number = int(file_current_sequence_number.read()) +1
    else:
        file_current_sequence_number = open(config.PATH+'/current_sequence', 'w+')
        current_sequence_number = 1

    file_current_sequence_number.close()
    print "Current: ", current_sequence_number

    file_current_sequence_number = open(config.PATH+'/current_sequence', 'r+')
    open(config.PATH+'/current_sequence', 'w').close() #empty the contents of current sequence file before writing in

    file_current_sequence_number.write(str(current_sequence_number))
    file_current_sequence_number.close()

    # write monitored values to a file with name as the current sequence number
    file_content = open (config.PATH + '/'+str(current_sequence_number), 'w')
    file_content.write(str(system_info))
    file_content.close()

    delete_seen_entries()
コード例 #3
0
def monitorStore():
    """
    Get monitored information
    Attach the sequence number
    Attach timestamp
    Store in the log file
    delete seen entries
    """
    # commented to use psutil system info system_info = systeminfo.get_all_info()

    system_info = nodeinfo.node_all()
    system_info['monitored_timestamp'] = config.get_current_system_timestamp()

    # Attach sliver info to system info
    system_info.update(sliverinfo.collectAllDataAPI())

    s = shelve.open('log_shelf.db', writeback=True)

    while (1):
        try:
            try:
                if s.has_key('current_seq_number'):
                    #Update current sequence number
                    s['current_seq_number'] += 1
                    current_seq = s['current_seq_number']
                else:
                    current_seq = 1
                    s['current_seq_number'] = current_seq

                print("writing to file: " + str(current_seq))

                #  print("writing to file" + str(system_info))
                s[str(current_seq)] = system_info

            finally:
                s.close()
                break

        except OSError:
            # In some research devices, the underlying dbm has a bug which needs to be handled explicitly
            print(
                "Exception caught while handling shelve file!! OS Error: file not found. Trying again in 1 second"
            )
            time.sleep(1)
            continue

    delete_seen_entries()
コード例 #4
0
ファイル: store.py プロジェクト: confine-project/confine-dist
def monitorStore():
    """
    Get monitored information
    Attach the sequence number
    Attach timestamp
    Store in the log file
    delete seen entries
    """
   # commented to use psutil system info system_info = systeminfo.get_all_info()

    system_info = nodeinfo.node_all()
    system_info ['monitored_timestamp'] = config.get_current_system_timestamp()

    # Attach sliver info to system info
    system_info.update(sliverinfo.collectAllDataAPI())

    s = shelve.open('log_shelf.db', writeback = True)

    while(1):
        try:
            try:
                if s.has_key('current_seq_number'):
                    #Update current sequence number
                    s['current_seq_number']+= 1
                    current_seq = s['current_seq_number']
                else:
                    current_seq = 1
                    s['current_seq_number']= current_seq

                print("writing to file: " + str(current_seq))

            #  print("writing to file" + str(system_info))
                s[str(current_seq)]= system_info


            finally:
                s.close()
                break

        except OSError:
            # In some research devices, the underlying dbm has a bug which needs to be handled explicitly
            print("Exception caught while handling shelve file!! OS Error: file not found. Trying again in 1 second")
            time.sleep(1)
            continue

    delete_seen_entries()
コード例 #5
0
ファイル: storefile.py プロジェクト: awmn/confine-dist
def monitorStore():
    """
    Get monitored information
    Attach the sequence number
    Attach timestamp
    Store in the log file
    delete seen entries
    """
    # commented to use psutil system info system_info = systeminfo.get_all_info()

    system_info = nodeinfo.node_all()
    system_info['monitored_timestamp'] = config.get_current_system_timestamp()

    # Attach sliver info to system info
    system_info.update(sliverinfo.collectAllDataAPI())

    ## Write current sequence number to file "current_sequence"
    if os.path.exists(config.PATH + '/current_sequence'):
        file_current_sequence_number = open(config.PATH + '/current_sequence',
                                            'r+')
        print "File exists"
        current_sequence_number = int(file_current_sequence_number.read()) + 1
    else:
        file_current_sequence_number = open(config.PATH + '/current_sequence',
                                            'w+')
        current_sequence_number = 1

    file_current_sequence_number.close()
    print "Current: ", current_sequence_number

    file_current_sequence_number = open(config.PATH + '/current_sequence',
                                        'r+')
    open(config.PATH + '/current_sequence', 'w').close(
    )  #empty the contents of current sequence file before writing in

    file_current_sequence_number.write(str(current_sequence_number))
    file_current_sequence_number.close()

    # write monitored values to a file with name as the current sequence number
    file_content = open(config.PATH + '/' + str(current_sequence_number), 'w')
    file_content.write(str(system_info))
    file_content.close()

    delete_seen_entries()
コード例 #6
0
def monitorStore():
    """
    Get monitored information
    Attach the sequence number
    Attach timestamp
    Store in the log file
    delete seen entries
    """
    trace_info = {}
    trace_info['trace'] = tracerouteparser.get_trace_info()

    trace_info['inter-trace'] = tracerouteparser.get_inter_node_trace()

    trace_info ['monitored_timestamp'] = config.get_current_system_timestamp()
    print trace_info

    ## Write current sequence number to file "current_sequence"
    if os.path.exists(config.PATH + '/current_sequence'):
        file_current_sequence_number = open(config.PATH+'/current_sequence', 'r+')
        current_sequence_number = int(file_current_sequence_number.read()) +1
    else:
        file_current_sequence_number = open(config.PATH+'/current_sequence', 'w+')
        current_sequence_number = 1

    file_current_sequence_number.close()
    print "Current: ", current_sequence_number

    file_current_sequence_number = open(config.PATH+'/current_sequence', 'r+')
    open(config.PATH+'/current_sequence', 'w').close() #empty the contents of current sequence file before writing in

    file_current_sequence_number.write(str(current_sequence_number))
    file_current_sequence_number.close()

    # write monitored values to a file with name as the current sequence number
    file_content = open (config.PATH + '/'+str(current_sequence_number), 'w')
    file_content.write(str(trace_info))
    file_content.close()

    delete_seen_entries()