Ejemplo n.º 1
0
def Main():
    if lib_util.is_snapshot_behaviour():
        Snapshot()
    else:
        while True:
            Snapshot(1000000)
            time.sleep(20)
def Main():
    if lib_util.is_snapshot_behaviour():
        logging.debug("system calls snapshot")
        Snapshot()
    else:
        logging.debug("system calls events")
        try:
            SendEvents()
        except Exception as err:
            logging.error("Caught:%s" % err)
            raise
def Main():
    if lib_util.is_snapshot_behaviour():
        Snapshot()
    else:
        while True:
            Snapshot()
            # TODO: This should be a parameter. How to modify it when the process is started ?
            # TODO: For deamons, the parameters could simply be written in a file each time they
            # TODO: are updated, then they would be read again: This is very fast and reliable.
            # TODO: Possibly store the parameters in the triple-store.
            time.sleep(20)
def Main():
    if lib_util.is_snapshot_behaviour():
        logger = logging.getLogger()
        logger.setLevel(logging.DEBUG)
        Snapshot()
    else:
        # This runs in the daemon process.
        logger = logging.getLogger()
        logger.setLevel(logging.DEBUG)

        while True:
            try:
                send_events_once()
            except Exception as exc:
                logging.warning("caught: %s" % exc)
Ejemplo n.º 5
0
def Main():
    proc_open = None

    # procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
    #  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
    #  0  0 217344 152232 112880 1573408    0    0     1    43    0    1  1  1 98  0  0
    def _vmstat_to_graph(cgiEnv, vmstat_header, input_line):
        grph = cgiEnv.ReinitGraph()
        split_header = vmstat_header.split()
        split_line = input_line.split()

        if len(split_header) != len(split_line):
            logging.error("Different lengths: [%s] / [%s]" %
                          (split_header, split_line))
            return

        current_node_hostname = lib_uris.gUriGen.HostnameUri(
            lib_util.currentHostname)
        property_vmstat = lib_properties.MakeProp("vmstat")

        sample_root_node = rdflib.BNode()
        grph.add((current_node_hostname, property_vmstat, sample_root_node))

        timestamp_node = lib_kbase.time_stamp_now_node()
        grph.add((sample_root_node, pc.property_information, timestamp_node))

        for column_name, column_value in zip(split_header, split_line):
            if column_name == "":
                continue
            # Column name is binary and converted to unicode.
            property_node = lib_properties.MakeProp("vmstat.%s" %
                                                    column_name.decode())
            # TODO: Add a timestamp.
            grph.add((sample_root_node, property_node,
                      lib_util.NodeLiteral(column_value)))
        cgiEnv.OutCgiRdf("LAYOUT_RECT", [property_vmstat])

    def main_snapshot():
        vmstat_cmd = [
            "vmstat",
        ]

        cgiEnv = lib_common.ScriptEnvironment()

        logging.debug(__file__ +
                      " Snapshot Starting process:%s" % str(vmstat_cmd))
        Main.proc_popen = subprocess.Popen(vmstat_cmd,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE,
                                           shell=False)
        result_lines = Main.proc_popen.stdout.readlines()
        _vmstat_to_graph(cgiEnv, result_lines[1], result_lines[2])

    def main_events():
        # TODO: The delay could be a parameter.
        vmstat_cmd = [
            "vmstat",
            "1",
        ]

        cgiEnv = lib_common.ScriptEnvironment()

        logging.debug(__file__ +
                      " Events Starting process:%s" % str(vmstat_cmd))
        Main.proc_popen = subprocess.Popen(vmstat_cmd,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE,
                                           shell=False)
        logging.debug(__file__ + " Events Started")

        line_counter = 0
        while True:
            current_line = Main.proc_popen.stdout.readline()
            logging.debug(__file__ + " Events Read:%s" % current_line)
            line_counter += 1
            if line_counter == 1:
                continue
            if line_counter == 2:
                # Contains the last header read.
                vmstat_header = current_line
                continue

            if not current_line:
                continue

            _vmstat_to_graph(cgiEnv, vmstat_header, current_line)

    try:
        if lib_util.is_snapshot_behaviour():
            main_snapshot()
        else:
            logging.debug(__file__ + " events")
            main_events()
    except Exception as exc:
        lib_common.ErrorMessageHtml("vmstat error:%s" % str(exc))
    finally:
        if proc_open:
            proc_open.kill()
            proc_open.communicate()
            proc_open.terminate()
Ejemplo n.º 6
0
            if spl[0] == 'Device:':
                iostat_header = spl
                return

            grph = cgiEnv.ReinitGraph()

            _io_stat_to_graph(grph, spl, iostat_header)

            cgiEnv.OutCgiRdf()

            loop_number -= 1
            if loop_number == 0:
                break
    except Exception as exc:
        logging.error("Caught:%s" % exc)
        lib_common.ErrorMessageHtml("iostat error:%s" % str(exc))
    finally:
        if proc_open:
            proc_open.kill()
            proc_open.communicate()
            proc_open.terminate()


if __name__ == '__main__':
    logging.debug("Starting")
    if lib_util.is_snapshot_behaviour():
        Main()
    else:
        while True:
            Main(1000000)