mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -82,6 +82,15 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) | ||||
|   </li>'); | ||||
|     } | ||||
|  | ||||
|     if (@dbFetchCell("SELECT 1 FROM processes WHERE device_id = '" . $device['device_id'] . "'") > '0') | ||||
|     { | ||||
|       echo('<li class="' . $select['processes'] . '"> | ||||
|     <a href="'.generate_device_url($device, array('tab' => 'processes')).'"> | ||||
|       <img src="images/16/application_osx_terminal.png" align="absmiddle" border="0" /> Processes | ||||
|     </a> | ||||
|   </li>'); | ||||
|     } | ||||
|  | ||||
|     if (isset($config['collectd_dir']) && is_dir($config['collectd_dir'] . "/" . $device['hostname'] ."/")) | ||||
|     { | ||||
|       echo('<li class="' . $select['collectd'] . '"> | ||||
|   | ||||
							
								
								
									
										98
									
								
								html/pages/device/processes.inc.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								html/pages/device/processes.inc.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,98 @@ | ||||
| <?php | ||||
| /* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.org> | ||||
|  * 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 <http://www.gnu.org/licenses/>. */ | ||||
|  | ||||
| /** | ||||
|  * Alerts Tracking | ||||
|  * @author Daniel Preussker <f0o@devilcode.org> | ||||
|  * @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 "<div class='table-responsive'><table class='table table-hover'><thead><tr>"; | ||||
| 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 '<th><a href="/device/device='.$device['device_id'].'/tab=processes/order='.$lhead.'/by='.$bhead.'"><span'.$icon.'> '; | ||||
| 	if( !empty($extra) ) { | ||||
| 		echo "<abbr title='$extra'>$head</abbr>"; | ||||
| 	} else { | ||||
| 		echo $head; | ||||
| 	} | ||||
| 	echo '</span></a></th>'; | ||||
| } | ||||
| echo "</tr></thead><tbody>"; | ||||
|  | ||||
| foreach (dbFetchRows("SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY ".$order." ".$by, array($device['device_id'])) as $entry) { | ||||
| 	echo '<tr>'; | ||||
| 	echo '<td>'.$entry['pid'].'</td>'; | ||||
| 	echo '<td>'.format_si($entry['vsz']*1024).'</td>'; | ||||
| 	echo '<td>'.format_si($entry['rss']*1024).'</td>'; | ||||
| 	echo '<td>'.$entry['cputime'].'</td>'; | ||||
| 	echo '<td>'.$entry['user'].'</td>'; | ||||
| 	echo '<td>'.$entry['command'].'</td>'; | ||||
| 	echo '</tr>'; | ||||
| } | ||||
| echo"</tbody></table></div>"; | ||||
|  | ||||
| ?> | ||||
| @@ -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"); | ||||
|     } | ||||
|  | ||||
|   | ||||
							
								
								
									
										1
									
								
								sql-schema/039.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								sql-schema/039.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||
		Reference in New Issue
	
	Block a user