Exemplo n.º 1
0
    def run(self, storage, controller):
        prog = self.create_program()
        funcs = self.module_config.get("funcs")

        try:
            # Compile and load eBPF program to kernel
            b = BPF(text=prog)
            for f in funcs:
                b.attach_uprobe(name=config.get("executable"),
                                sym=f,
                                fn_name="%s_on_enter" % f)

            while (True):
                count = b.get_table("count")
                ts = time.time()

                for k, v in count.iteritems():
                    storage.store(funcs[k.value], v.value, ts)

                count.clear()
                time.sleep(1)

                if controller.stopped:
                    break
        except Exception as e:
            # stop all other threads
            controller.stopped = True
            raise e
Exemplo n.º 2
0
    def store(self, metric, value, timestamp=None):
        prefix = GlobalConfig.get('prefix', 'ajtest')

        msg = '{}.{} {} {}\n'.format(
            prefix, metric, value,
            timestamp if timestamp else int(time.time()))

        self.sock.sendall(msg.encode())
        logging.debug(msg)
Exemplo n.º 3
0
    def run(self, storage, controller):
        prog = self.create_program()
        probe_start = self.module_config['probe_start']
        probe_end = self.module_config.get('probe_end')

        try:
            # Compile and load eBPF program to kernel
            bpf = BPF(text=prog)
            path = config.get("executable")

            bpf.attach_uprobe(name=path,
                              sym=probe_start,
                              fn_name='probe_start')
            if probe_start == probe_end or not probe_end:
                bpf.attach_uretprobe(name=path,
                                     sym=probe_start,
                                     fn_name='probe_end')
            else:
                bpf.attach_uprobe(name=path,
                                  sym=probe_end,
                                  fn_name='probe_end')

            while (True):
                stats = bpf.get_table("stats")
                ts = time.time()

                for k, v in stats.iteritems():
                    if v.value:
                        metric = '%s.%s' % (probe_start, pow(2, k.value))
                        storage.store(metric, v.value, ts)

                stats.clear()
                time.sleep(1)

                if controller.stopped:
                    break
        except Exception as e:
            # stop all other threads
            controller.stopped = True
            raise e