mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
committed by
Tony Murray
parent
ef90da2a31
commit
96f7f142ba
@@ -1443,6 +1443,33 @@ function get_postgres_databases($device_id)
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all mdadm arrays from the collected
|
||||
* rrd files.
|
||||
*
|
||||
* @param array $device device for which we get the rrd's
|
||||
* @param int $app_id application id on the device
|
||||
* @return array list of disks
|
||||
*/
|
||||
function get_arrays_with_mdadm($device, $app_id)
|
||||
{
|
||||
$arrays = array();
|
||||
|
||||
$pattern = sprintf('%s/%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', 'mdadm', $app_id);
|
||||
|
||||
foreach (glob($pattern) as $rrd) {
|
||||
$filename = basename($rrd, '.rrd');
|
||||
|
||||
list(,,, $array_name) = explode("-", $filename, 4);
|
||||
|
||||
if ($array_name) {
|
||||
array_push($arrays, $array_name);
|
||||
}
|
||||
}
|
||||
|
||||
return $arrays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all disks (disk serial numbers) from the collected
|
||||
* rrd files.
|
||||
|
31
includes/html/graphs/application/mdadm-common.inc.php
Normal file
31
includes/html/graphs/application/mdadm-common.inc.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
$name = 'mdadm';
|
||||
$app_id = $app['app_id'];
|
||||
$colours = 'mega';
|
||||
$dostack = 0;
|
||||
$printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 15;
|
||||
|
||||
if (isset($vars['array'])) {
|
||||
$arrays=array($vars['array']);
|
||||
} else {
|
||||
$arrays=get_arrays_with_mdadm($device, $app['app_id']);
|
||||
}
|
||||
|
||||
$int=0;
|
||||
while (isset($arrays[$int])) {
|
||||
$array=$arrays[$int];
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
|
||||
|
||||
if (rrdtool_check_rrd_exists($rrd_filename)) {
|
||||
$rrd_list[]=array(
|
||||
'filename' => $rrd_filename,
|
||||
'descr' => $array,
|
||||
'ds' => $rrdVar,
|
||||
);
|
||||
}
|
||||
$int++;
|
||||
}
|
||||
|
||||
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
|
9
includes/html/graphs/application/mdadm_degraded.inc.php
Normal file
9
includes/html/graphs/application/mdadm_degraded.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$unit_text = 'degraded';
|
||||
$unitlen = 10;
|
||||
$bigdescrlen = 15;
|
||||
$smalldescrlen = 15;
|
||||
|
||||
$rrdVar='degraded';
|
||||
|
||||
require 'mdadm-common.inc.php';
|
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$unit_text = 'Disc Count';
|
||||
$unitlen = 10;
|
||||
$bigdescrlen = 15;
|
||||
$smalldescrlen = 15;
|
||||
|
||||
$rrdVar='disc_count';
|
||||
|
||||
require 'mdadm-common.inc.php';
|
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$unit_text = 'Hotspare Disc Count';
|
||||
$unitlen = 10;
|
||||
$bigdescrlen = 15;
|
||||
$smalldescrlen = 15;
|
||||
|
||||
$rrdVar='hotspare_count';
|
||||
|
||||
require 'mdadm-common.inc.php';
|
9
includes/html/graphs/application/mdadm_level.inc.php
Normal file
9
includes/html/graphs/application/mdadm_level.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$unit_text = 'RAID Level';
|
||||
$unitlen = 10;
|
||||
$bigdescrlen = 15;
|
||||
$smalldescrlen = 15;
|
||||
|
||||
$rrdVar='level';
|
||||
|
||||
require 'mdadm-common.inc.php';
|
9
includes/html/graphs/application/mdadm_size.inc.php
Normal file
9
includes/html/graphs/application/mdadm_size.inc.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$unit_text = 'RAID Size';
|
||||
$unitlen = 10;
|
||||
$bigdescrlen = 15;
|
||||
$smalldescrlen = 15;
|
||||
|
||||
$rrdVar='size';
|
||||
|
||||
require 'mdadm-common.inc.php';
|
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$unit_text = 'Sync completed (%)';
|
||||
$unitlen = 10;
|
||||
$bigdescrlen = 15;
|
||||
$smalldescrlen = 15;
|
||||
|
||||
$rrdVar='sync_completed';
|
||||
|
||||
require 'mdadm-common.inc.php';
|
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$unit_text = 'Sync Speed (kB/s)';
|
||||
$unitlen = 10;
|
||||
$bigdescrlen = 15;
|
||||
$smalldescrlen = 15;
|
||||
|
||||
$rrdVar='sync_speed';
|
||||
|
||||
require 'mdadm-common.inc.php';
|
@@ -230,6 +230,15 @@ $graphs['smart'] = array(
|
||||
'id231',
|
||||
'id233',
|
||||
);
|
||||
$graphs['mdadm'] = array(
|
||||
'level',
|
||||
'size',
|
||||
'disc_count',
|
||||
'hotspare_count',
|
||||
'degraded',
|
||||
'sync_speed',
|
||||
'sync_completed',
|
||||
);
|
||||
$graphs['sdfsinfo'] = array(
|
||||
'volume',
|
||||
'blocks',
|
||||
|
63
includes/html/pages/device/apps/mdadm.inc.php
Normal file
63
includes/html/pages/device/apps/mdadm.inc.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
$mdadm_arrays = get_arrays_with_mdadm($device, $app['app_id']);
|
||||
|
||||
print_optionbar_start();
|
||||
|
||||
$link_array = array(
|
||||
'page' => 'device',
|
||||
'device' => $device['device_id'],
|
||||
'tab' => 'apps',
|
||||
'app' => 'mdadm',
|
||||
);
|
||||
|
||||
$array_list = array();
|
||||
|
||||
foreach ($mdadm_arrays as $label) {
|
||||
$array = $label;
|
||||
|
||||
if ($vars['array'] == $array) {
|
||||
$label = sprintf('⚫ %s', $label);
|
||||
}
|
||||
|
||||
array_push($array_list, generate_link($label, $link_array, array('array' => $array)));
|
||||
}
|
||||
|
||||
printf("%s | arrays: %s", generate_link('All RAID Arrays', $link_array), implode(', ', $array_list));
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
$graphs = array(
|
||||
'mdadm_level' => 'RAID level',
|
||||
'mdadm_size' => 'RAID Size',
|
||||
'mdadm_disc_count' => 'RAID Disc count',
|
||||
'mdadm_hotspare_count' => 'RAID Hotspare Disc count',
|
||||
'mdadm_degraded' => 'RAID degraded',
|
||||
'mdadm_sync_speed' => 'RAID Sync speed',
|
||||
'mdadm_sync_completed' => 'RAID Sync completed',
|
||||
);
|
||||
|
||||
|
||||
foreach ($graphs as $key => $text) {
|
||||
$graph_type = $key;
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = time();
|
||||
$graph_array['id'] = $app['app_id'];
|
||||
$graph_array['type'] = 'application_'.$key;
|
||||
|
||||
if (isset($vars['array'])) {
|
||||
$graph_array['array']=$vars['array'];
|
||||
}
|
||||
|
||||
echo '<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.$text.'</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">';
|
||||
include 'includes/html/print-graphrow.inc.php';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
61
includes/polling/applications/mdadm.inc.php
Normal file
61
includes/polling/applications/mdadm.inc.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
use LibreNMS\Exceptions\JsonAppMissingKeysException;
|
||||
use LibreNMS\Exceptions\JsonAppException;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
|
||||
$name = 'mdadm';
|
||||
$app_id = $app['app_id'];
|
||||
$output = 'OK';
|
||||
|
||||
try {
|
||||
$mdadm_data = json_app_get($device, $name, 1)['data'];
|
||||
} catch (JsonAppMissingKeysException $e) {
|
||||
$mdadm_data = $e->getParsedJson();
|
||||
} catch (JsonAppException $e) {
|
||||
echo PHP_EOL . $name . ':' .$e->getCode().':'. $e->getMessage() . PHP_EOL;
|
||||
update_application($app, $e->getCode().':'.$e->getMessage(), []); // Set empty metrics and error message
|
||||
return;
|
||||
}
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('level', 'GAUGE', 0)
|
||||
->addDataset('size', 'GAUGE', 0)
|
||||
->addDataset('disc_count', 'GAUGE', 0)
|
||||
->addDataset('hotspare_count', 'GAUGE', 0)
|
||||
->addDataset('degraded', 'GAUGE', 0)
|
||||
->addDataset('sync_speed', 'GAUGE', 0)
|
||||
->addDataset('sync_completed', 'GAUGE', 0);
|
||||
|
||||
$metrics = array();
|
||||
foreach ($mdadm_data as $data) {
|
||||
$array_name = $data['name'];
|
||||
$level = $data['level'];
|
||||
$size = $data['size'];
|
||||
$device_list = $data['device_list'];
|
||||
$missing_device_list = $data['missing_device_list'];
|
||||
$disc_count = $data['disc_count'];
|
||||
$hotspare_count = $data['hotspare_count'];
|
||||
$degraded = $data['degraded'];
|
||||
$sync_speed = $data['sync_speed'];
|
||||
$sync_completed = $data['sync_completed'];
|
||||
|
||||
$rrd_name = array('app', $name, $app_id, $array_name);
|
||||
|
||||
$array_level = str_replace('raid', '', $level);
|
||||
|
||||
$fields = array(
|
||||
'level' => $array_level,
|
||||
'size' => $size,
|
||||
'disc_count' => $disc_count,
|
||||
'hotspare_count' => $hotspare_count,
|
||||
'degraded' => $degraded,
|
||||
'sync_speed' => $sync_speed,
|
||||
'sync_completed' => $sync_completed
|
||||
);
|
||||
|
||||
$metrics[$array_name] = $fields;
|
||||
$tags = array('name' => $array_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}
|
||||
update_application($app, $output, $metrics);
|
Reference in New Issue
Block a user