def get_columns(self): cols = [] dat = get_file(self.proc_file) lines = deque(dat.split("\n")) nlines = len(lines) # expect at least one network interface + 2 header lines if nlines < 2: msg = "NetDev: cannot parse {0}" self.log.error(msg.format(self.proc_file)) self.enabled = False return cols # skip first line eg. Inter-| Receive lines.popleft() # next line has the header values hdr_vals = deque(lines.popleft().split("|")) # remove eg. face hdr_vals.popleft() if len(hdr_vals) != 2: msg = "NetDev: cannot parse {0}" self.log.error(msg.format(self.proc_files)) self.enabled = False return cols # values are receive then transmit hdrs = dict(zip(["rx", "tx"], hdr_vals)) for pfx, metrics in hdrs.items(): for metric in metrics.split(): if metric in NetDev.rename: metric = NetDev.rename[metric] cols.append("{0}_{1}".format(pfx, metric)) return cols
def __init__(self, log, config): """Plugin to measure various kernel metrics from /proc. :param log: A logger :type log: logging.RootLogger :param config: a plumd.config.Conf configuration helper instance. :type config: plumd.config.Conf """ super(DiskStats, self).__init__(log, config) config.defaults(DiskStats.defaults) self.calc = Differential() self.proc_file = "{0}/diskstats".format(config.get("proc_path")) self.diskstats_dev_re = re.compile(config.get("diskstats_dev_re")) self.diskstats_cols = self.config.get("diskstats_cols") self.devices = [] # list of device names to record metrics for self.enabled = True # get list of available devices: dat = get_file_map(self.proc_file, 2, 0) # key is the device name, exclude ones matching the re for key, val in dat.items(): if not self.diskstats_dev_re.match(key): self.devices.append(key) # check format of proc file ncols = len(get_file(self.proc_file).split("\n")[0].split()) self.enabled = ncols == DiskStats.proc_colums if not self.enabled: msg = "DiskStats: invalid format: {0} has {1} cols, not {2}" self.log.error(msg.format(self.proc_file, ncols, DiskStats.proc_colums))
def check(self): """Return current conntrack count and max. :rtype: plumd.Result """ result = plumd.Result("conntrack") if not self.enabled: return [result] curr_val = 0 max_val = 0 # read and process /proc/stat curr_val = get_file(self.fname_cnt) max_val = get_file(self.fname_max) result.add(plumd.Int("cur", curr_val)) result.add(plumd.Int("max", max_val)) return [result]
def check(self): """Return uptime from proc file swap. :rtype: list """ result = plumd.Result("uptime") # read and process /proc/stat up, idle = get_file(self.proc_file).strip().split() pidle = float(idle) / float(up) * 100 / multiprocessing.cpu_count() result.add(plumd.Float("up", up)) result.add(plumd.Float("idle", idle)) result.add(plumd.Float("idle_percent", pidle)) return [result]
def check(self): """Return network socket metrics from proc file net/sockstat. Note: sockstat.TCP.mem is measured in pages, you can get the system page size from os.sysconf("SC_PAGESIZE") Note: FRAG: ip fragmentation :rtype: plumd.Result """ result = plumd.Result("sockstat") # read and process - dat is a list of lines from fname dat = get_file_map_list(self.proc_file, 0, 0) ts = time.time() # each entry is a key: [metric, val, metric, val] for key, val in dat.items(): mstr = key[:-1] mnames = val[::2] # 1::2 - every second item mvals = deque([int(i) for i in val[1::2]]) for mname in mnames: metric = "{0}.{1}".format(mstr, mname) result.add(plumd.Int(metric, mvals.popleft())) # also record configured tcp mem limits dat = get_file(self.fname_limits).split() if len(dat) == 3: # eg. for alerting/dashboard on pages allocated vs max values result.add(plumd.Int("TCP.mem_min", dat[0])) result.add(plumd.Int("TCP.mem_pressure", dat[1])) result.add(plumd.Int("TCP.mem_max", dat[1])) # and max orphans dat = get_file(self.fname_orph) result.add(plumd.Int("TCP.orphan_max", dat)) return [result]
def check(self): """Return 1, 5 and 15 minute load averages from proc file loadavg. :rtype: plumd.Result """ result = plumd.Result("loadavg") if not self.enabled: return result dat = [] # read and process /proc/stat dat = get_file(self.proc_file).split() if len(dat) >= 3: result.add(plumd.Float("1", dat[0])) result.add(plumd.Float("5", dat[1])) result.add(plumd.Float("15", dat[2])) return [result]
def __init__(self, log, config): """Plugin to measure various kernel metrics from /proc. :param log: A logger :type log: logging.RootLogger :param config: a plumd.config.Conf configuration helper instance. :type config: plumd.config.Conf """ super(LoadAverage, self).__init__(log, config) config.defaults(LoadAverage.defaults) self.proc_file = "{0}/loadavg".format(config.get('proc_path')) ncols = len(get_file(self.proc_file).strip().split()) self.enabled = ncols == LoadAverage.proc_colums if not self.enabled: msg = "LoadAverage: invalid: {0} has {1} cols, expected {2}" self.log.error(msg.format(self.proc_path, ncols, LoadAverage.proc_colums))