From 42de11884e2d6cdc71c0ac6550874a7dd5e7c301 Mon Sep 17 00:00:00 2001 From: f0o Date: Thu, 15 Jan 2015 07:18:10 +0000 Subject: [PATCH] Added: 039.sql: create a new table processes processes.inc.php: show all processes from given device including sort-options Changed: unix-agent.inc.php: insert all processes reported by check_mk_agent device.inc.php: added tab with link to process-list --- html/pages/device.inc.php | 9 +++ html/pages/device/processes.inc.php | 98 +++++++++++++++++++++++++++++ includes/polling/unix-agent.inc.php | 10 +-- sql-schema/039.sql | 1 + 4 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 html/pages/device/processes.inc.php create mode 100644 sql-schema/039.sql diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index b1a825f021..3ab398d49f 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -82,6 +82,15 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) '); } + if (@dbFetchCell("SELECT 1 FROM processes WHERE device_id = '" . $device['device_id'] . "'") > '0') + { + echo('
  • + + Processes + +
  • '); + } + if (isset($config['collectd_dir']) && is_dir($config['collectd_dir'] . "/" . $device['hostname'] ."/")) { echo('
  • diff --git a/html/pages/device/processes.inc.php b/html/pages/device/processes.inc.php new file mode 100644 index 0000000000..63944e82e0 --- /dev/null +++ b/html/pages/device/processes.inc.php @@ -0,0 +1,98 @@ + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +/** + * Alerts Tracking + * @author Daniel Preussker + * @copyright 2015 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Pages + */ + +switch( $vars['order'] ) { + case "vsz": + $order = "`vsz`"; + break; + case "rss": + $order = "`rss`"; + break; + case "cputime": + $order = "`cputime`"; + break; + case "user": + $order = "`user`"; + break; + case "command": + $order = "`command`"; + break; + default: + $order = "`pid`"; + break; +} +if( $vars['by'] == "desc" ) { + $by = "desc"; +} else { + $by = "asc"; +} + +$heads = array( + 'PID' => '', + 'VSZ' => 'Virtual Memory', + 'RSS' => 'Resident Memory', + 'cputime' => '', + 'user' => '', + 'command' => '' +); + +echo "
    "; +foreach( $heads as $head=>$extra ) { + unset($lhead, $bhead); + $lhead = strtolower($head); + $bhead = 'asc'; + $icon = ""; + if( '`'.$lhead.'`' == $order ) { + $icon = " class='glyphicon glyphicon-chevron-"; + if( $by == 'asc' ) { + $bhead = 'desc'; + $icon .= 'up'; + } else { + $icon .= 'down'; + } + $icon .= "'"; + } + echo ''; +} +echo ""; + +foreach (dbFetchRows("SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY ".$order." ".$by, array($device['device_id'])) as $entry) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; +} +echo"
     '; + if( !empty($extra) ) { + echo "$head"; + } else { + echo $head; + } + echo '
    '.$entry['pid'].''.format_si($entry['vsz']*1024).''.format_si($entry['rss']*1024).''.$entry['cputime'].''.$entry['user'].''.$entry['command'].'
    "; + +?> diff --git a/includes/polling/unix-agent.inc.php b/includes/polling/unix-agent.inc.php index b413501d89..ac4623cb44 100755 --- a/includes/polling/unix-agent.inc.php +++ b/includes/polling/unix-agent.inc.php @@ -82,13 +82,15 @@ if ($device['os_group'] == "unix") if (!empty($agent_data['ps'])) { echo("Processes: "); + dbDelete('processes', 'device_id = ?', array($device['device_id'])); foreach (explode("\n", $agent_data['ps']) as $process) { - $process = preg_replace("/\((.*),([0-9]*),([0-9]*),([0-9\.]*)\)\ (.*)/", "\\1|\\2|\\3|\\4|\\5", $process); - list($user, $vsz, $rss, $pcpu, $command) = explode("|", $process, 5); - $processlist[] = array('user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'pcpu' => $pcpu, 'command' => $command); + $process = preg_replace("/\((.*),([0-9]*),([0-9]*),([0-9\:]*),([0-9]*)\)\ (.*)/", "\\1|\\2|\\3|\\4|\\5|\\6", $process); + list($user, $vsz, $rss, $cputime, $pid, $command) = explode("|", $process, 6); + if( !empty($command) ) { + dbInsert(array('device_id' => $device['device_id'], 'pid' => $pid, 'user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'cputime' => $cputime, 'command' => $command), 'processes'); + } } - #print_r($processlist); echo("\n"); } diff --git a/sql-schema/039.sql b/sql-schema/039.sql new file mode 100644 index 0000000000..c9f2c7a8f3 --- /dev/null +++ b/sql-schema/039.sql @@ -0,0 +1 @@ +CREATE TABLE IF NOT EXISTS `processes` ( `device_id` int(11) NOT NULL, `pid` int(255) NOT NULL, `vsz` int(255) NOT NULL, `rss` int(255) NOT NULL, `cputime` varchar(12) NOT NULL, `user` varchar(50) NOT NULL, `command` varchar(255) NOT NULL, KEY `device_id` (`device_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;