mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix an agent bug if a process ran more than 999 days (#15411)
* Fix an agent bug if a process ran more than 999 days Increase it to 274 years before that happens ;) Fix a few other small bugs * Update schema check file
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('processes', function (Blueprint $table) {
|
||||
$table->string('cputime', 14)->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('processes', function (Blueprint $table) {
|
||||
$table->string('cputime', 12)->change();
|
||||
});
|
||||
}
|
||||
};
|
@@ -24,7 +24,7 @@
|
||||
* @subpackage Pages
|
||||
*/
|
||||
|
||||
switch ($vars['order']) {
|
||||
switch ($vars['order'] ?? '') {
|
||||
case 'vsz':
|
||||
$order = '`vsz`';
|
||||
break;
|
||||
@@ -50,7 +50,7 @@ switch ($vars['order']) {
|
||||
break;
|
||||
}//end switch
|
||||
|
||||
if ($vars['by'] == 'desc') {
|
||||
if (isset($vars['by']) && $vars['by'] == 'desc') {
|
||||
$by = 'desc';
|
||||
} else {
|
||||
$by = 'asc';
|
||||
|
@@ -28,6 +28,7 @@ if ($device['os_group'] == 'unix' || $device['os'] == 'windows') {
|
||||
// Set stream timeout (for timeouts during agent fetch
|
||||
stream_set_timeout($agent, \LibreNMS\Config::get('unix-agent.read-timeout'));
|
||||
$agentinfo = stream_get_meta_data($agent);
|
||||
$agent_raw = '';
|
||||
|
||||
// fetch data while not eof and not timed-out
|
||||
while ((! feof($agent)) && (! $agentinfo['timed_out'])) {
|
||||
@@ -76,14 +77,17 @@ if ($device['os_group'] == 'unix' || $device['os'] == 'windows') {
|
||||
global $agent_data;
|
||||
$agent_data = [];
|
||||
foreach (explode('<<<', $agent_raw) as $section) {
|
||||
[$section, $data] = explode('>>>', $section);
|
||||
[$sa, $sb] = explode('-', $section, 2);
|
||||
if (empty($section)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[$section, $data] = explode('>>>', $section);
|
||||
if (in_array($section, $agentapps)) {
|
||||
$agent_data['app'][$section] = trim($data);
|
||||
}
|
||||
|
||||
if (! empty($sa) && ! empty($sb)) {
|
||||
if (str_contains($section, '-')) {
|
||||
[$sa, $sb] = explode('-', $section, 2);
|
||||
$agent_data[$sa][$sb] = trim($data);
|
||||
} else {
|
||||
$agent_data[$section] = trim($data);
|
||||
@@ -109,9 +113,8 @@ if ($device['os_group'] == 'unix' || $device['os'] == 'windows') {
|
||||
dbDelete('processes', 'device_id = ?', [$device['device_id']]);
|
||||
$data = [];
|
||||
foreach (explode("\n", $agent_data['ps']) as $process) {
|
||||
$process = preg_replace('/\((.*),([0-9]*),([0-9]*),([0-9\:\.\-]*),([0-9]*)\)\ (.*)/', '\\1|\\2|\\3|\\4|\\5|\\6', $process);
|
||||
[$user, $vsz, $rss, $cputime, $pid, $command] = explode('|', $process, 6);
|
||||
if (! empty($command)) {
|
||||
if (preg_match('/\((.*),([0-9]*),([0-9]*),([-0-9:.]*),([0-9]*)\) (.+)/', $process, $process_matches)) {
|
||||
[, $user, $vsz, $rss, $cputime, $pid, $command] = $process_matches;
|
||||
$data[] = ['device_id' => $device['device_id'], 'pid' => $pid, 'user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'cputime' => $cputime, 'command' => $command];
|
||||
}
|
||||
}
|
||||
|
@@ -1740,7 +1740,7 @@ processes:
|
||||
- { Field: pid, Type: int, 'Null': false, Extra: '' }
|
||||
- { Field: vsz, Type: int, 'Null': false, Extra: '' }
|
||||
- { Field: rss, Type: int, 'Null': false, Extra: '' }
|
||||
- { Field: cputime, Type: varchar(12), 'Null': false, Extra: '' }
|
||||
- { Field: cputime, Type: varchar(14), 'Null': false, Extra: '' }
|
||||
- { Field: user, Type: varchar(50), 'Null': false, Extra: '' }
|
||||
- { Field: command, Type: text, 'Null': false, Extra: '' }
|
||||
Indexes:
|
||||
|
Reference in New Issue
Block a user