1<?php
2/*
3 * Copyright (C) 2015 Daniel Preussker <f0o@devilcode.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Process Listing
20 * @author Daniel Preussker <f0o@devilcode.org>
21 * @copyright 2015 f0o, LibreNMS
22 * @license GPL
23 * @package LibreNMS
24 * @subpackage Pages
25 */
26
27switch ($vars['order']) {
28    case 'vsz':
29        $order = '`vsz`';
30        break;
31
32    case 'rss':
33        $order = '`rss`';
34        break;
35
36    case 'cputime':
37        $order = '`cputime`';
38        break;
39
40    case 'user':
41        $order = '`user`';
42        break;
43
44    case 'command':
45        $order = '`command`';
46        break;
47
48    default:
49        $order = '`pid`';
50        break;
51}//end switch
52
53if ($vars['by'] == 'desc') {
54    $by = 'desc';
55} else {
56    $by = 'asc';
57}
58
59$heads = [
60    'PID'     => '',
61    'VSZ'     => 'Virtual Memory',
62    'RSS'     => 'Resident Memory',
63    'cputime' => '',
64    'user'    => '',
65    'command' => '',
66];
67
68echo "<div class='table-responsive'><table class='table table-hover'><thead><tr>";
69foreach ($heads as $head => $extra) {
70    unset($lhead, $bhead);
71    $lhead = strtolower($head);
72    $bhead = 'asc';
73    $icon = '';
74    if ('`' . $lhead . '`' == $order) {
75        $icon = " class='fa fa-chevron-";
76        if ($by == 'asc') {
77            $bhead = 'desc';
78            $icon .= 'up';
79        } else {
80            $icon .= 'down';
81        }
82
83        $icon .= "'";
84    }
85
86    echo '<th><a href="' . \LibreNMS\Util\Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'processes', 'order' => $lhead, 'by' => $bhead]) . '"><span' . $icon . '>&nbsp;';
87    if (! empty($extra)) {
88        echo "<abbr title='$extra'>$head</abbr>";
89    } else {
90        echo $head;
91    }
92
93    echo '</span></a></th>';
94}//end foreach
95
96echo '</tr></thead><tbody>';
97
98foreach (dbFetchRows('SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY ' . $order . ' ' . $by, [$device['device_id']]) as $entry) {
99    echo '<tr>';
100    echo '<td>' . $entry['pid'] . '</td>';
101    echo '<td>' . \LibreNMS\Util\Number::formatSi(($entry['vsz'] * 1024), 2, 3, '') . '</td>';
102    echo '<td>' . \LibreNMS\Util\Number::formatSi(($entry['rss'] * 1024), 2, 3, '') . '</td>';
103    echo '<td>' . $entry['cputime'] . '</td>';
104    echo '<td>' . $entry['user'] . '</td>';
105    echo '<td>' . $entry['command'] . '</td>';
106    echo '</tr>';
107}
108
109echo '</tbody></table></div>';
110