mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix last polled (#15396)
* Only update last_polled if polled Because availability now runs always, we need to check if we ran any other modules successfully, if so, we can update last_polled * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
@@ -100,22 +100,17 @@ class Poller
|
||||
$helper->saveMetrics();
|
||||
$helper->isUp(); // check and save status
|
||||
|
||||
$this->pollModules();
|
||||
$polled_modules = $this->pollModules();
|
||||
|
||||
$measurement->end();
|
||||
|
||||
// if modules are not overridden, record performance
|
||||
if (empty($this->module_override)) {
|
||||
// record performance
|
||||
$measurement->manager()->record('device', $measurement);
|
||||
$this->device->last_polled = Carbon::now();
|
||||
$this->device->last_polled_timetaken = $measurement->getDuration();
|
||||
app('Datastore')->put($this->deviceArray, 'poller-perf', [
|
||||
'rrd_def' => RrdDefinition::make()->addDataset('poller', 'GAUGE', 0),
|
||||
'module' => 'ALL',
|
||||
], [
|
||||
'poller' => $measurement->getDuration(),
|
||||
]);
|
||||
$this->os->enableGraph('poller_perf');
|
||||
// check that we ran some modules (exclude availabliltiy because it always runs)
|
||||
$valid_polled_modules = array_filter($polled_modules, fn ($module) => $module !== 'availability');
|
||||
if (! empty($valid_polled_modules)) {
|
||||
$this->recordPerformance($measurement);
|
||||
}
|
||||
|
||||
if ($helper->canPing()) {
|
||||
$this->os->enableGraph('ping_perf');
|
||||
@@ -160,7 +155,7 @@ class Poller
|
||||
return $this->buildDeviceQuery()->count();
|
||||
}
|
||||
|
||||
private function pollModules(): void
|
||||
private function pollModules(): array
|
||||
{
|
||||
// update $device array status
|
||||
$this->deviceArray['status'] = $this->device->status;
|
||||
@@ -173,6 +168,7 @@ class Poller
|
||||
include_once base_path('includes/snmp.inc.php');
|
||||
|
||||
$datastore = app('Datastore');
|
||||
$polled_modules = [];
|
||||
|
||||
foreach (array_keys(Config::get('poller_modules')) as $module) {
|
||||
$module_status = Module::status($module, $this->device, $this->isModuleManuallyEnabled($module));
|
||||
@@ -189,6 +185,7 @@ class Poller
|
||||
$this->logger->debug($module_status);
|
||||
|
||||
$instance->poll($this->os, $datastore);
|
||||
$polled_modules[] = $module;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
// isolate module exceptions so they don't disrupt the polling process
|
||||
@@ -204,6 +201,8 @@ class Poller
|
||||
$this->logger->info("#### Unload poller module $module ####\n");
|
||||
}
|
||||
}
|
||||
|
||||
return $polled_modules;
|
||||
}
|
||||
|
||||
private function saveModulePerformance(string $module, float $start_time, int $start_memory): void
|
||||
@@ -339,4 +338,20 @@ EOH, $this->device->hostname, $group ? " ($group)" : '', $this->device->device_i
|
||||
$this->logger->info(Version::get()->header());
|
||||
}
|
||||
}
|
||||
|
||||
private function recordPerformance(Measurement $measurement): void
|
||||
{
|
||||
$measurement->manager()->record('device', $measurement);
|
||||
|
||||
$this->device->last_polled = Carbon::now();
|
||||
$this->device->last_polled_timetaken = $measurement->getDuration();
|
||||
|
||||
app('Datastore')->put($this->deviceArray, 'poller-perf', [
|
||||
'rrd_def' => RrdDefinition::make()->addDataset('poller', 'GAUGE', 0),
|
||||
'module' => 'ALL',
|
||||
], [
|
||||
'poller' => $measurement->getDuration(),
|
||||
]);
|
||||
$this->os->enableGraph('poller_perf');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user