mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Systemd Application Code Cleanup and new Systemd Unit State Metrics. (#15848)
This commit is contained in:
@@ -30,7 +30,7 @@ if (Rrd::checkRrdExists($rrd_filename)) {
|
||||
];
|
||||
}
|
||||
} else {
|
||||
d_echo('RRD ' . $rrd_filename . ' not found');
|
||||
graph_error('No Data file ' . basename($rrd_filename), 'No Data');
|
||||
}
|
||||
|
||||
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
|
||||
|
@@ -16,12 +16,16 @@ if (isset($vars['sn'])) {
|
||||
|
||||
$rrd_list = [];
|
||||
|
||||
if (! $sn_list) {
|
||||
graph_error('No Data to Display', 'No Data');
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
while (isset($sn_list[$i])) {
|
||||
$sn = $sn_list[$i];
|
||||
$rrd_filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, $sn]);
|
||||
|
||||
$j = 0;
|
||||
if (Rrd::checkRrdExists($rrd_filename)) {
|
||||
foreach ($rrdArray as $ds => $var) {
|
||||
$rrd_list[$j]['filename'] = $rrd_filename;
|
||||
@@ -29,6 +33,8 @@ while (isset($sn_list[$i])) {
|
||||
$rrd_list[$j]['ds'] = $ds;
|
||||
$j++;
|
||||
}
|
||||
} else {
|
||||
graph_error('No Data file ' . basename($rrd_filename), 'No Data');
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
@@ -11,8 +11,13 @@ $smalldescrlen = 20;
|
||||
|
||||
$rrd_list = [];
|
||||
|
||||
if (! $rrdArray) {
|
||||
graph_error('No Data to Display', 'No Data');
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach (array_keys($rrdArray) as $state_type) {
|
||||
$rrd_filename = Rrd::name($device['hostname'], [
|
||||
$shared_rrd_filename = Rrd::name($device['hostname'], [
|
||||
$polling_type,
|
||||
$name,
|
||||
$app->app_id,
|
||||
@@ -20,15 +25,25 @@ foreach (array_keys($rrdArray) as $state_type) {
|
||||
]);
|
||||
|
||||
if (Rrd::checkRrdExists($rrd_filename)) {
|
||||
$i = 0;
|
||||
foreach ($rrdArray[$state_type] as $state_status => $state_status_desc) {
|
||||
$rrd_list[$i]['filename'] = $rrd_filename;
|
||||
$rrd_list[$i]['descr'] = $state_status_desc['descr'];
|
||||
foreach ($rrdArray[$state_type] as $state_status => $state_status_aa) {
|
||||
if ($state_status_aa['rrd_location'] === 'individual') {
|
||||
$individual_rrd_filename = Rrd::name($device['hostname'], [
|
||||
$polling_type,
|
||||
$name,
|
||||
$app->app_id,
|
||||
$state_type,
|
||||
$state_status,
|
||||
]);
|
||||
$rrd_list[$i]['filename'] = $individual_rrd_filename;
|
||||
} else {
|
||||
$rrd_list[$i]['filename'] = $shared_rrd_filename;
|
||||
}
|
||||
$rrd_list[$i]['descr'] = $state_status_aa['descr'];
|
||||
$rrd_list[$i]['ds'] = $state_status;
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
d_echo('RRD ' . $rrd_filename . ' not found');
|
||||
graph_error('No Data file ' . basename($rrd_filename), 'No Data');
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,8 +3,13 @@
|
||||
require_once 'includes/systemd-shared.inc.php';
|
||||
|
||||
$rrdArray = [];
|
||||
foreach ($systemd_mapper['active'] as $state_status) {
|
||||
$rrdArray['active'][$state_status] = ['descr' => $state_status];
|
||||
$state_type = 'active';
|
||||
|
||||
foreach ($systemd_mapper[$state_type] as $state_status => $rrd_location) {
|
||||
$rrdArray[$state_type][$state_status] = [
|
||||
'descr' => $state_status,
|
||||
'rrd_location' => $rrd_location,
|
||||
];
|
||||
}
|
||||
|
||||
require 'systemd-common.inc.php';
|
||||
|
19
includes/html/graphs/application/systemd_all.inc.php
Normal file
19
includes/html/graphs/application/systemd_all.inc.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once 'includes/systemd-shared.inc.php';
|
||||
|
||||
$rrdArray = [];
|
||||
|
||||
foreach ($systemd_mapper as $flattened_type => $state_statuses) {
|
||||
foreach (
|
||||
$systemd_mapper[$flattened_type]
|
||||
as $state_status => $rrd_location
|
||||
) {
|
||||
$rrdArray[$flattened_type][$state_status] = [
|
||||
'descr' => $flattened_type . '_' . $state_status,
|
||||
'rrd_location' => $rrd_location,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
require 'systemd-common.inc.php';
|
@@ -3,8 +3,13 @@
|
||||
require_once 'includes/systemd-shared.inc.php';
|
||||
|
||||
$rrdArray = [];
|
||||
foreach ($systemd_mapper['load'] as $state_status) {
|
||||
$rrdArray['load'][$state_status] = ['descr' => $state_status];
|
||||
$state_type = 'load';
|
||||
|
||||
foreach ($systemd_mapper[$state_type] as $state_status => $rrd_location) {
|
||||
$rrdArray[$state_type][$state_status] = [
|
||||
'descr' => $state_status,
|
||||
'rrd_location' => $rrd_location,
|
||||
];
|
||||
}
|
||||
|
||||
require 'systemd-common.inc.php';
|
||||
|
@@ -3,19 +3,44 @@
|
||||
require_once 'includes/systemd-shared.inc.php';
|
||||
|
||||
$rrdArray = [];
|
||||
$state_type = 'sub';
|
||||
|
||||
// This pulls the service sub state type
|
||||
// given by the opened page. Otherwise, 'service'
|
||||
// is the default for the Application overview
|
||||
// pages.
|
||||
$sub_state_type = $vars['sub_state_type'] ?? 'service';
|
||||
if (isset($vars['sub_state_type'])) {
|
||||
// This section draws the individual graphs in the device application page
|
||||
// displaying the SPECIFIED service type's sub states.
|
||||
$flattened_type = $vars['sub_state_type'];
|
||||
|
||||
$sub_flattened_name = 'sub_' . $sub_state_type;
|
||||
foreach (
|
||||
$systemd_mapper[$flattened_type]
|
||||
as $sub_state_status => $rrd_location
|
||||
) {
|
||||
$rrdArray[$flattened_type][$sub_state_status] = [
|
||||
'descr' => $sub_state_status,
|
||||
'rrd_location' => $rrd_location,
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// This section draws the graph for the application-specific pages
|
||||
// displaying ALL of the service type's sub states.
|
||||
foreach ($systemd_mapper as $flattened_type => $state_statuses) {
|
||||
// Ternary-depth systemd type check.
|
||||
if (! preg_match('/^(.+)_(.+)$/', $flattened_type, $regex_matches)) {
|
||||
continue;
|
||||
}
|
||||
if ($regex_matches[1] !== $state_type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($systemd_mapper['sub'][$sub_state_type] as $sub_state_status) {
|
||||
$rrdArray[$sub_flattened_name][$sub_state_status] = [
|
||||
'descr' => $sub_state_status,
|
||||
];
|
||||
foreach (
|
||||
$systemd_mapper[$flattened_type]
|
||||
as $sub_state_status => $rrd_location
|
||||
) {
|
||||
$rrdArray[$flattened_type][$sub_state_status] = [
|
||||
'descr' => $flattened_type . '_' . $sub_state_status,
|
||||
'rrd_location' => $rrd_location,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require 'systemd-common.inc.php';
|
||||
|
Reference in New Issue
Block a user