banshee is under active development: collectors will keep changing, and a version you publish will likely need adjustments. For stable use, wait for version 1.0.0.

Linux

banshee/linux-collection/linux/snmp/

processes

Processes of a Linux host by SNMP: their number, and the instances, memory and processor time of each one followed.

  • linux
  • snmp
  • process
  • net-snmp

by banshee1 installation2 versions

Keen 1.0.0 · 53 lines
// The processes of a Linux host, by SNMP: their total number, and for each process name followed ("sshd",
// "postgres") the number of its instances, their memory and their processor time, from hrSWRunTable and
// hrSWRunPerfTable (HOST-RESOURCES-MIB). net-snmp names a process as the kernel does, by its first 15
// characters: "kube-controller-manager" is followed as "kube-controller".
need('protocol:snmp');

per('process', 'Processes', array('only' => array('sshd', 'cron', 'crond')));
output('processes', 'number', array('label' => 'Number of processes'));
output('instances', 'number', array('label' => 'Number of instances', 'per' => 'process'));
output('memory', 'number', array('label' => 'Memory', 'unit' => 'MiB', 'per' => 'process'));
output('cpu', 'number', array('label' => 'Processor time, as a share of one processor', 'unit' => '%', 'per' => 'process'));

watch.missing('missing', 'Missing process', 'instances', array('critical' => array('sshd')));
watch.above('too-many', 'Too many processes', 'processes', array('enabled' => false));
watch.above('memory-high', 'Memory of a process', 'memory', array('enabled' => false));
watch.above('cpu-high', 'Processor of a process', 'cpu', array('warning' => 90, 'for' => '3 runs', 'enabled' => false));

// hrSystemProcesses: the number of processes loaded or running.
value('processes', snmp.get('1.3.6.1.2.1.25.1.6.0'));

// By hrSWRunIndex (the process ID): hrSWRunName, hrSWRunPerfCPU (processor time used since start, in
// hundredths of a second) and hrSWRunPerfMem (real memory, in KiB).
$run = snmp.table(array(
    'name'   => '1.3.6.1.2.1.25.4.2.1.2',
    'cpu'    => '1.3.6.1.2.1.25.5.1.1.1',
    'memory' => '1.3.6.1.2.1.25.5.1.1.2',
));

// Instances of the same name add up; a process that ended between two columns lacks some of its own,
// and counts as zero in what it lacks.
$count = array();
$memory = array();
$cpu = array();
foreach ($run as $row) {
    if (!list.has($row, 'name')) {
        continue;
    }
    $name = $row['name'];
    $count[$name] = list.get($count, $name, 0) + 1;
    $memory[$name] = list.get($memory, $name, 0) + list.get($row, 'memory', 0);
    $cpu[$name] = list.get($cpu, $name, 0) + list.get($row, 'cpu', 0);
}

foreach ($count as $name => $instances) {
    value('instances', $instances, $name);
    value('memory', number.round($memory[$name] / 1024, 1), $name);
    // Hundredths of a second used per second are percent of one processor. Nothing on the first run, nor
    // when an instance has ended and the sum has gone backwards.
    $rate = counter.rate('cpu', $cpu[$name], $name);
    if ($rate != '') {
        value('cpu', number.round($rate, 1), $name);
    }
}