Exemplo n.º 1
0
    def register_metrics(self):
        """register control metrics"""
        self.add_metric(
            'bpftrace.control.register',
            pmdaMetric(
                self.pmid(Consts.Control.Cluster,
                          Consts.Control.Register), c_api.PM_TYPE_STRING,
                c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT, pmUnits()),
            "register a new bpftrace script")

        self.add_metric(
            'bpftrace.control.deregister',
            pmdaMetric(
                self.pmid(Consts.Control.Cluster,
                          Consts.Control.Deregister), c_api.PM_TYPE_STRING,
                c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT, pmUnits()),
            "deregister a bpftrace script")

        self.add_metric(
            'bpftrace.control.start',
            pmdaMetric(self.pmid(Consts.Control.Cluster,
                                 Consts.Control.Start), c_api.PM_TYPE_STRING,
                       c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT, pmUnits()),
            "start a stopped bpftrace script")

        self.add_metric(
            'bpftrace.control.stop',
            pmdaMetric(self.pmid(Consts.Control.Cluster,
                                 Consts.Control.Stop), c_api.PM_TYPE_STRING,
                       c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT, pmUnits()),
            "stop a running bpftrace script")

        self.add_metric(
            'bpftrace.info.scripts',
            pmdaMetric(self.pmid(Consts.Info.Cluster,
                                 Consts.Info.Scripts), c_api.PM_TYPE_STRING,
                       self.script_indom.indom_id, c_api.PM_SEM_INSTANT,
                       pmUnits()), "list all registered bpftrace scripts")

        self.add_metric(
            'bpftrace.info.scripts_json',
            pmdaMetric(self.pmid(Consts.Info.Cluster, Consts.Info.ScriptsJson),
                       c_api.PM_TYPE_STRING, c_api.PM_INDOM_NULL,
                       c_api.PM_SEM_INSTANT, pmUnits()),
            "expose all scripts in JSON format")

        self.add_metric(
            'bpftrace.info.tracepoints',
            pmdaMetric(self.pmid(Consts.Info.Cluster, Consts.Info.Tracepoints),
                       c_api.PM_TYPE_STRING, c_api.PM_INDOM_NULL,
                       c_api.PM_SEM_INSTANT, pmUnits()),
            "list all available tracepoints")
Exemplo n.º 2
0
 def extract(self, descs, result):
     """ Extract the set of metric values from a given pmResult """
     values = []
     for index in range(len(descs)):
         if result.contents.get_numval(index) > 0:
             atom = self.context.pmExtractValue(
                             result.contents.get_valfmt(index),
                             result.contents.get_vlist(index, 0),
                             descs[index].contents.type, PM_TYPE_U64)
             atom = self.context.pmConvScale(PM_TYPE_U64, atom, descs, index,
                             pmapi.pmUnits(1, 0, 0, PM_SPACE_KBYTE, 0, 0))
             values.append(long(atom.ull))
         else:
             values.append(long(0))
     return values
Exemplo n.º 3
0
 def extract(self, descs, result):
     """ Extract the set of metric values from a given pmResult """
     values = []
     for index in range(len(descs)):
         if result.contents.get_numval(index) > 0:
             atom = self.context.pmExtractValue(
                             result.contents.get_valfmt(index),
                             result.contents.get_vlist(index, 0),
                             descs[index].contents.type, PM_TYPE_U64)
             atom = self.context.pmConvScale(PM_TYPE_U64, atom, descs, index,
                             pmapi.pmUnits(1, 0, 0, PM_SPACE_KBYTE, 0, 0))
             values.append(long(atom.ull))
         else:
             values.append(long(0))
     return values
Exemplo n.º 4
0
 def setup_ping_metrics(self, name):
     '''
     Setup the metric table - ensure a values hash entry is setup for
     each metric; that way we don't need to worry about KeyErrors in
     the fetch callback routine (e.g. if the kernel interface changes).
     '''
     self.values['ping'] = 0
     # This class inherits from PDMA which includes these methods
     # pylint: disable=no-member
     self.add_metric(name + '.ping',
                     pmdaMetric(self.pmid(0, 0),
                                c_api.PM_TYPE_U32,
                                c_api.PM_INDOM_NULL,
                                c_api.PM_SEM_INSTANT,
                                pmUnits(0, 0, 0, 0, 0, 0)),
                     'Http ping to google.com http status codde')
Exemplo n.º 5
0
from modules.pcpbcc import PCPBCCBase
from pcp.pmapi import pmUnits
from cpmapi import PM_TYPE_U64, PM_SEM_COUNTER, PM_SPACE_BYTE
from cpmapi import PM_ERR_AGAIN

#
# BPF program
#
bpf_src = "modules/tcplife.bpf"

#
# PCP BCC PMDA constants
#
MODULE = 'tcplife'
BASENS = 'proc.io.net.tcp.'
units_bytes = pmUnits(1, 0, 0, PM_SPACE_BYTE, 0, 0)

TASK_COMM_LEN = 16  # linux/sched.h


class Data_ipv4(ct.Structure):
    """ IPv4 data struct """
    _fields_ = [("ts_us", ct.c_ulonglong), ("pid", ct.c_ulonglong),
                ("saddr", ct.c_ulonglong), ("daddr", ct.c_ulonglong),
                ("ports", ct.c_ulonglong), ("rx_b", ct.c_ulonglong),
                ("tx_b", ct.c_ulonglong), ("span_us", ct.c_ulonglong),
                ("task", ct.c_char * TASK_COMM_LEN)]


class Data_ipv6(ct.Structure):
    """ IPv6 data struct """
Exemplo n.º 6
0
from modules.pcpbcc import PCPBCCBase
from pcp.pmapi import pmUnits
from cpmapi import PM_TYPE_U64, PM_SEM_COUNTER, PM_COUNT_ONE
from cpmapi import PM_ERR_AGAIN

#
# BPF program
#
bpf_src = "modules/sysfork.bpf"

#
# PCP BCC PMDA constants
#
MODULE = 'sysfork'
METRIC = 'proc.sysfork'
units_count = pmUnits(0, 0, 1, 0, 0, PM_COUNT_ONE)

#
# PCP BCC Module
#
class PCPBCCModule(PCPBCCBase):
    """ PCP BCC biotop module """
    def __init__(self, config, log, err):
        """ Constructor """
        PCPBCCBase.__init__(self, MODULE, config, log, err)

        self.value = 0

        self.log("Initialized.")

    def metrics(self):
Exemplo n.º 7
0
    def register_metrics(self):
        """register metrics for this bpftrace instance"""
        self.status_metric = pmdaMetric(
            self.pmda.pmid(self.cluster_id, Consts.Script.Status),
            c_api.PM_TYPE_STRING, c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT,
            pmUnits())
        self.pmda.add_metric(f'bpftrace.scripts.{self.name}.status',
                             self.status_metric, "status of bpftrace script")

        self.pid_metric = pmdaMetric(
            self.pmda.pmid(self.cluster_id, Consts.Script.Pid),
            c_api.PM_TYPE_U32, c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT,
            pmUnits())
        self.pmda.add_metric(f'bpftrace.scripts.{self.name}.pid',
                             self.pid_metric, "pid of bpftrace process")

        self.exit_code_metric = pmdaMetric(
            self.pmda.pmid(self.cluster_id, Consts.Script.ExitCode),
            c_api.PM_TYPE_32, c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT,
            pmUnits())
        self.pmda.add_metric(f'bpftrace.scripts.{self.name}.exit_code',
                             self.exit_code_metric,
                             "exit code of bpftrace process")

        self.error_metric = pmdaMetric(
            self.pmda.pmid(self.cluster_id, Consts.Script.Error),
            c_api.PM_TYPE_STRING, c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT,
            pmUnits())
        self.pmda.add_metric(f'bpftrace.scripts.{self.name}.error',
                             self.error_metric,
                             "errors of the bpftrace script")

        self.probes_metric = pmdaMetric(
            self.pmda.pmid(self.cluster_id, Consts.Script.Probes),
            c_api.PM_TYPE_U32, c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT,
            pmUnits())
        self.pmda.add_metric(f'bpftrace.scripts.{self.name}.probes',
                             self.probes_metric, "number of attached probes")

        self.code_metric = pmdaMetric(
            self.pmda.pmid(self.cluster_id, Consts.Script.Code),
            c_api.PM_TYPE_STRING, c_api.PM_INDOM_NULL, c_api.PM_SEM_INSTANT,
            pmUnits())
        self.pmda.add_metric(f'bpftrace.scripts.{self.name}.code',
                             self.code_metric, "bpftrace script")

        item_no = Consts.Script.First_BPFtrace_Variable
        for var_name, var_def in self.script.variables.items():
            if var_def.single:
                indom_id = c_api.PM_INDOM_NULL
            else:
                # serial needs to be unique across PMDA
                indom = UncachedIndom(self.pmda,
                                      self.cluster_id * 1000 + item_no)
                indom_id = indom.indom_id
                self.indoms[var_name] = indom

            pmid = self.pmda.pmid(self.cluster_id, item_no)
            metric = pmdaMetric(pmid, var_def.datatype, indom_id,
                                var_def.semantics, pmUnits())
            normalized_var_name = self.normalize_variable_name(var_name)
            metric_name = f'bpftrace.scripts.{self.name}.data.{normalized_var_name}'
            self.pmda.add_metric(metric_name, metric,
                                 f"{var_name} variable of bpftrace script")
            self.metrics[metric_name] = metric
            self.pmid_to_var[pmid] = var_name
            self.item_to_var[item_no] = var_name
            item_no += 1
Exemplo n.º 8
0
    import configparser as ConfigParser
except ImportError:
    import ConfigParser
import termios, struct, atexit, fcntl, sched, errno, time, sys, os

# PCP Python PMAPI
from pcp import pmapi, pmconfig
from cpmapi import PM_CONTEXT_ARCHIVE, PM_CONTEXT_HOST, PM_CONTEXT_LOCAL
from cpmapi import PM_TYPE_32, PM_TYPE_U32, PM_TYPE_64, PM_TYPE_U64
from cpmapi import PM_TYPE_DOUBLE, PM_TYPE_FLOAT
from cpmapi import PM_ERR_EOL, PM_DEBUG_APPL1, pmUsageMessage

if sys.version >= '3':
    long = int

NOUNITS = pmapi.pmUnits()

THEME = { 'default': '' }

COLOR = {
    'black': '\033[0;30m',
    'darkred': '\033[0;31m',
    'darkgreen': '\033[0;32m',
    'darkyellow': '\033[0;33m',
    'darkblue': '\033[0;34m',
    'darkmagenta': '\033[0;35m',
    'darkcyan': '\033[0;36m',
    'gray': '\033[0;37m',

    'darkgray': '\033[1;30m',
    'red': '\033[1;31m',