mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
add multi DB support to the Postgres app (#6222)
* now creates a component with all the DBs in it * add the function get_postgres_databases * add multi DB support to the Postgres device app page * add multi DB support to the Postgres graphs * whoops removed the udpate bit, readd it * white space cleanup * now use json for storing DB names * provide the list of DBs in a cleaner manner * Update postgres.inc.php
This commit is contained in:
@@ -1516,6 +1516,31 @@ function get_fail2ban_jails($device_id)
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Postgres databases for a device... just requires the device ID
|
||||
* an empty return means Postres is not in use
|
||||
* @param $device_id
|
||||
* @return array
|
||||
*/
|
||||
function get_postgres_databases($device_id)
|
||||
{
|
||||
$options=array(
|
||||
'filter' => array(
|
||||
'type' => array('=', 'postgres'),
|
||||
),
|
||||
);
|
||||
|
||||
$component=new LibreNMS\Component();
|
||||
$pgc=$component->getComponents($device_id, $options);
|
||||
|
||||
if (isset($pgc[$device_id])) {
|
||||
$id = $component->getFirstComponentID($pgc, $device_id);
|
||||
return json_decode($pgc[$device_id][$id]['databases']);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
// takes the device array and app_id
|
||||
function get_disks_with_smart($device, $app_id)
|
||||
{
|
||||
|
@@ -12,7 +12,13 @@ $printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 15;
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
|
||||
if (isset($vars['database'])) {
|
||||
$rrd_name_array=array('app', $name, $app_id, $vars['database']);
|
||||
} else {
|
||||
$rrd_name_array=array('app', $name, $app_id);
|
||||
}
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], $rrd_name_array);
|
||||
|
||||
if (is_file($rrd_filename)) {
|
||||
$rrd_list = array(
|
||||
|
@@ -12,7 +12,13 @@ $printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 15;
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
|
||||
if (isset($vars['database'])) {
|
||||
$rrd_name_array=array('app', $name, $app_id, $vars['database']);
|
||||
} else {
|
||||
$rrd_name_array=array('app', $name, $app_id);
|
||||
}
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], $rrd_name_array);
|
||||
|
||||
if (is_file($rrd_filename)) {
|
||||
$rrd_list = array(
|
||||
|
@@ -12,7 +12,14 @@ $printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 15;
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
|
||||
|
||||
if (isset($vars['database'])) {
|
||||
$rrd_name_array=array('app', $name, $app_id, $vars['database']);
|
||||
} else {
|
||||
$rrd_name_array=array('app', $name, $app_id);
|
||||
}
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], $rrd_name_array);
|
||||
|
||||
if (is_file($rrd_filename)) {
|
||||
$rrd_list = array(
|
||||
|
@@ -12,7 +12,13 @@ $printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 15;
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
|
||||
if (isset($vars['database'])) {
|
||||
$rrd_name_array=array('app', $name, $app_id, $vars['database']);
|
||||
} else {
|
||||
$rrd_name_array=array('app', $name, $app_id);
|
||||
}
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], $rrd_name_array);
|
||||
|
||||
if (is_file($rrd_filename)) {
|
||||
$rrd_list = array(
|
||||
|
@@ -12,7 +12,13 @@ $printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 15;
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
|
||||
if (isset($vars['database'])) {
|
||||
$rrd_name_array=array('app', $name, $app_id, $vars['database']);
|
||||
} else {
|
||||
$rrd_name_array=array('app', $name, $app_id);
|
||||
}
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], $rrd_name_array);
|
||||
|
||||
if (is_file($rrd_filename)) {
|
||||
$rrd_list = array(
|
||||
|
@@ -12,7 +12,13 @@ $printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 15;
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
|
||||
if (isset($vars['database'])) {
|
||||
$rrd_name_array=array('app', $name, $app_id, $vars['database']);
|
||||
} else {
|
||||
$rrd_name_array=array('app', $name, $app_id);
|
||||
}
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], $rrd_name_array);
|
||||
|
||||
if (is_file($rrd_filename)) {
|
||||
$rrd_list = array(
|
||||
|
@@ -2,6 +2,40 @@
|
||||
|
||||
global $config;
|
||||
|
||||
$databases=get_postgres_databases($device['device_id']);
|
||||
|
||||
$link_array = array(
|
||||
'page' => 'device',
|
||||
'device' => $device['device_id'],
|
||||
'tab' => 'apps',
|
||||
'app' => 'postgres',
|
||||
);
|
||||
|
||||
print_optionbar_start();
|
||||
|
||||
echo generate_link('Total', $link_array);
|
||||
echo '| DBs:';
|
||||
$db_int=0;
|
||||
while (isset($databases[$db_int])) {
|
||||
$db=$databases[$db_int];
|
||||
$label=$db;
|
||||
|
||||
if ($vars['database'] == $db) {
|
||||
$label='>>'.$db.'<<';
|
||||
}
|
||||
|
||||
$db_int++;
|
||||
|
||||
$append='';
|
||||
if (isset($databases[$db_int])) {
|
||||
$append=', ';
|
||||
}
|
||||
|
||||
echo generate_link($label, $link_array, array('database'=>$db)).$append;
|
||||
}
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
$graphs = array(
|
||||
'postgres_backends' => 'Backends',
|
||||
'postgres_cr' => 'Commits & Rollbacks',
|
||||
@@ -19,6 +53,11 @@ foreach ($graphs as $key => $text) {
|
||||
$graph_array['id'] = $app['app_id'];
|
||||
$graph_array['type'] = 'application_'.$key;
|
||||
|
||||
if (isset($vars['database'])) {
|
||||
$graph_array['database']=$vars['database'];
|
||||
}
|
||||
|
||||
|
||||
echo '<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.$text.'</h3>
|
||||
|
@@ -4,6 +4,8 @@ $app_id = $app['app_id'];
|
||||
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
|
||||
echo "postgres";
|
||||
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.8.112.111.115.116.103.114.101.115';
|
||||
$postgres = snmp_walk($device, $oid, $options);
|
||||
@@ -55,3 +57,77 @@ $fields = array(
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
|
||||
//process each database
|
||||
$db_lines=explode("\n", $postgres);
|
||||
$db_lines_int=17;
|
||||
$found_dbs=array();
|
||||
|
||||
while (isset($db_lines[$db_lines_int])) {
|
||||
list($backends, $commits, $rollbacks, $read, $hit, $idxscan, $idxtupread, $idxtupfetch, $idxblksread,
|
||||
$idxblkshit, $seqscan, $seqtupread, $ret, $fetch, $ins, $upd, $del, $dbname) = explode(" ", $db_lines[$db_lines_int]);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id, $dbname);
|
||||
|
||||
$found_dbs[]=$dbname;
|
||||
|
||||
$fields = array(
|
||||
'backends' => $backends,
|
||||
'commits' => $commits,
|
||||
'rollbacks' => $rollbacks,
|
||||
'read' => $read,
|
||||
'hit' => $hit,
|
||||
'idxscan' => $idxscan,
|
||||
'idxtupread' => $idxtupread,
|
||||
'idxtupfetch' => $idxtupfetch,
|
||||
'idxblksread' => $idxblksread,
|
||||
'idxblkshit' => $idxblkshit,
|
||||
'seqscan' => $seqscan,
|
||||
'seqtupread' => $seqtupread,
|
||||
'ret' => $ret,
|
||||
'fetch' => $fetch,
|
||||
'ins' => $ins,
|
||||
'upd' => $upd,
|
||||
'del' => $del
|
||||
);
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
|
||||
$db_lines_int++;
|
||||
}
|
||||
|
||||
//
|
||||
// component processing for postgres
|
||||
//
|
||||
$device_id=$device['device_id'];
|
||||
|
||||
$options=array(
|
||||
'filter' => array(
|
||||
'device_id' => array('=', $device_id),
|
||||
'type' => array('=', 'postgres'),
|
||||
),
|
||||
);
|
||||
|
||||
$component=new LibreNMS\Component();
|
||||
$pg_components=$component->getComponents($device_id, $options);
|
||||
|
||||
if (empty($found_dbs)) {
|
||||
if (isset($pg_components[$device_id])) {
|
||||
foreach ($pg_components[$device_id] as $component_id => $_unused) {
|
||||
$component->deleteComponent($component_id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isset($pg_components[$device_id])) {
|
||||
$pgc = $pg_components[$device_id];
|
||||
} else {
|
||||
$pgc = $component->createComponent($device_id, 'postgres');
|
||||
}
|
||||
|
||||
$id = $component->getFirstComponentID($pgc);
|
||||
$pgc[$id]['label'] = 'Postgres';
|
||||
$pgc[$id]['databases'] = json_encode($found_dbs);
|
||||
|
||||
$component->setComponentPrefs($device_id, $pgc);
|
||||
}
|
||||
|
Reference in New Issue
Block a user