Rrdcached application monitoring

Can collect data from the agent or by connecting directly
This commit is contained in:
Tony Murray
2016-06-08 20:40:51 -05:00
parent a68687de5e
commit 60624c1ac0
8 changed files with 207 additions and 10 deletions

View File

@@ -0,0 +1,5 @@
<?php
$rrd = $config['rrd_dir'].'/'.$device['hostname'].'/app-rrdcached-'.$app['app_id'].'.rrd';
if (is_file($rrd)) {
$rrd_filename = $rrd;
}

View File

@@ -0,0 +1,31 @@
<?php
include 'rrdcached.inc.php';
$nototal = 1;
$colours = 'mixed';
$rrd_list = array(
array (
'ds' => 'updates_written',
'filename' => $rrd_filename,
'descr' => 'Updates Written',
),
array (
'ds' => 'data_sets_written',
'filename' => $rrd_filename,
'descr' => 'Data Sets Written',
),
array(
'ds' => 'updates_received',
'filename' => $rrd_filename,
'descr' => 'Updates Recieved',
),
array (
'ds' => 'flushes_received',
'filename' => $rrd_filename,
'descr' => 'Flushes Recieved',
),
);
require 'includes/graphs/generic_multi_line.inc.php';

View File

@@ -0,0 +1,20 @@
<?php
include 'rrdcached.inc.php';
$colours = 'pinks';
$rrd_list = array(
array(
'ds' => 'journal_rotate',
'filename' => $rrd_filename,
'descr' => 'Rotated',
),
array(
'ds' => 'journal_bytes',
'filename' => $rrd_filename,
'descr' => 'Bytes Written',
)
);
require 'includes/graphs/generic_multi.inc.php';

View File

@@ -0,0 +1,14 @@
<?php
require 'rrdcached.inc.php';
require 'includes/graphs/common.inc.php';
$ds = 'queue_length';
$colour_area = 'F37900';
$colour_line = 'FFA700';
$colour_area_max = 'F78800';
$unit_text = 'Count';
require 'includes/graphs/generic_simplex.inc.php';

View File

@@ -0,0 +1,20 @@
<?php
include 'rrdcached.inc.php';
$colours = 'blues';
$rrd_list = array(
array(
'ds' => 'tree_depth',
'filename' => $rrd_filename,
'descr' => 'Depth',
),
array(
'ds' => 'tree_nodes_number',
'filename' => $rrd_filename,
'descr' => 'Nodes',
)
);
require 'includes/graphs/generic_multi.inc.php';

View File

@@ -0,0 +1,29 @@
<?php
global $config;
$graphs = array(
'rrdcached_queue_length' => 'Queue Length',
'rrdcached_events' => 'Events',
'rrdcached_tree' => 'Tree',
'rrdcached_journal' => 'Journal',
);
foreach ($graphs as $key => $text) {
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = 'application_'.$key;
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/print-graphrow.inc.php';
echo '</div>';
echo '</div>';
echo '</div>';
}

View File

@@ -0,0 +1,77 @@
<?php
echo " rrdcached";
$data = "";
if($agent_data['app']['rrdcached']) {
$data = $agent_data['app']['rrdcached'];
} else {
d_echo("\nNo Agent Data. Attempting to connect directly to the rrdcached server ".$device['hostname'].":42217\n");
$sock = fsockopen($device['hostname'], 42217, $errno, $errstr, 5);
if(!$sock && $device['hostname'] == 'localhost') {
if (file_exists('/var/run/rrdcached.sock')) {
$sock = fsockopen('unix:///var/run/rrdcached.sock');
} elseif (file_exists('/run/rrdcached.sock')) {
$sock = fsockopen('unix:///run/rrdcached.sock');
} elseif (file_exists('/tmp/rrdcached.sock')) {
$sock = fsockopen('unix:///tmp/rrdcached.sock');
}
}
if($sock) {
fwrite($sock, "STATS\n");
$max = -1;
$count = 0;
while ($max == -1 || $count < $max) {
$data .= fgets($sock, 128);
if ($max == -1) {
$max = explode(' ', $data)[0] + 1;
}
$count++;
}
fclose($sock);
} else {
d_echo("ERROR: $errno - $errstr\n");
}
}
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-rrdcached-'.$app['app_id'].'.rrd';
if (!is_file($rrd_filename)) {
rrdtool_create(
$rrd_filename,
'--step 300
DS:queue_length:GAUGE:600:0:U
DS:updates_received:COUNTER:600:0:U
DS:flushes_received:COUNTER:600:0:U
DS:updates_written:COUNTER:600:0:U
DS:data_sets_written:COUNTER:600:0:U
DS:tree_nodes_number:GAUGE:600:0:U
DS:tree_depth:GAUGE:600:0:U
DS:journal_bytes:COUNTER:600:0:U
DS:journal_rotate:COUNTER:600:0:U
'.$config['rrd_rra']
);
}
$fields = array();
foreach (explode("\n", $data) as $line) {
$split = explode(': ', $line);
if (count($split) == 2) {
$name = strtolower(preg_replace('/[A-Z]/', '_$0', lcfirst($split[0])));
$fields[$name] = $split[1];
}
}
rrdtool_update($rrd_filename, $fields);
$tags = array('name' => 'rrdcached', 'app_id' => $app['app_id']);
influx_update($device,'app',$tags,$fields);
unset($data);
unset($rrd_filename);
unset($fields);
unset($tags);

View File

@@ -52,20 +52,21 @@ if ($device['os_group'] == 'unix') {
$graphs['agent'] = true;
foreach (explode('<<<', $agent_raw) as $section) {
list($section, $data) = explode('>>>', $section);
list($sa, $sb) = explode('-', $section, 2);
$agentapps = array(
"apache",
"bind",
"ceph",
"mysql",
"nginx",
"bind",
"powerdns",
"proxmox",
"rrdcached",
"tinydns");
foreach (explode('<<<', $agent_raw) as $section) {
list($section, $data) = explode('>>>', $section);
list($sa, $sb) = explode('-', $section, 2);
if (in_array($section, $agentapps)) {
$agent_data['app'][$section] = trim($data);
}