add memcached application graphing support. move applications to <<<app-$name>>> for easier detection. add connection tracking to mysql application. move logout to /logout/ not

/?logout=yes.


git-svn-id: http://www.observium.org/svn/observer/trunk@3096 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2012-04-27 17:18:26 +00:00
parent 6feb61512b
commit 850359711c
21 changed files with 286 additions and 28 deletions

View File

@@ -20,7 +20,7 @@ if (!is_writable($config['temp_dir']))
echo("<div class='errorbox'>Temp Directory is not writable ({$config['tmp_dir']}). Graphing may fail.</div>");
}
if (isset($_GET['logout']) && $_SESSION['authenticated'])
if ($vars['page'] == "logout" && $_SESSION['authenticated'])
{
dbInsert(array('user' => $_SESSION['username'], 'address' => $_SERVER["REMOTE_ADDR"], 'result' => 'Logged Out'), 'authlog');
unset($_SESSION);
@@ -78,7 +78,6 @@ if (isset($_SESSION['username']))
setcookie("password", $_SESSION['password'], time()+60*60*24*100, "/");
}
$permissions = permissions_cache($_SESSION['user_id']);
}
elseif (isset($_SESSION['username']))
{

View File

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

View File

@@ -0,0 +1,13 @@
<?php
include("memcached.inc.php");
include("includes/graphs/common.inc.php");
$multiplier = 8;
$ds_in = "bytes_read";
$ds_out = "bytes_written";
include("includes/graphs/generic_data.inc.php");
?>

View File

@@ -0,0 +1,34 @@
<?php
include("memcached.inc.php");
include("includes/graphs/common.inc.php");
$array = array(
'cmd_set' => 'Set',
'cmd_get' => 'Get',
);
$i = 0;
if (is_file($rrd_filename))
{
foreach ($array as $ds => $vars)
{
$rrd_list[$i]['filename'] = $rrd_filename;
if (is_array($vars))
{
$rrd_list[$i]['descr'] = $vars['descr'];
} else {
$rrd_list[$i]['descr'] = $vars;
}
$rrd_list[$i]['ds'] = $ds;
$i++;
}
} else { echo("file missing: $file"); }
$colours = "mixed";
$nototal = 0;
$unit_text = "";
include("includes/graphs/generic_multi_simplex_seperated.inc.php");
?>

View File

@@ -0,0 +1,19 @@
<?php
$scale_min = "0";
include("memcached.inc.php");
include("includes/graphs/common.inc.php");
$device = device_by_id_cache($id);
$rrd_options .= " DEF:uptime=".$rrd_filename.":uptime:AVERAGE";
$rrd_options .= " CDEF:cuptime=uptime,86400,/";
$rrd_options .= " 'COMMENT:Days Current Minimum Maximum Average\\n'";
$rrd_options .= " AREA:cuptime#EEEEEE:Uptime";
$rrd_options .= " LINE1.25:cuptime#36393D:";
$rrd_options .= " GPRINT:cuptime:LAST:%6.2lf GPRINT:cuptime:AVERAGE:%6.2lf";
$rrd_options .= " GPRINT:cuptime:MAX:%6.2lf 'GPRINT:cuptime:AVERAGE:%6.2lf\\n'";
?>

View File

@@ -24,7 +24,7 @@ if($_SESSION['widescreen'] === 1)
if ($_SESSION['authenticated'])
{
echo("Logged in as <b>".$_SESSION['username']."</b> (<a href='?logout=yes'>Logout</a>)");
echo("Logged in as <b>".$_SESSION['username']."</b> (<a href='/logout/'>Logout</a>)");
} else {
echo("Not logged in!");
}

View File

@@ -29,8 +29,6 @@ if (strpos($_SERVER['PATH_INFO'], "debug"))
ini_set('error_reporting', 0);
}
include("includes/authenticate.inc.php");
foreach ($_GET as $key=>$get_var)
{
if (strstr($key, "opt"))
@@ -97,6 +95,8 @@ foreach ($_POST as $name => $value)
$vars[$name] = $value;
}
include("includes/authenticate.inc.php");
if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) { $_SESSION['widescreen'] = 1; }
if (strstr($_SERVER['REQUEST_URI'], 'widescreen=no')) { unset($_SESSION['widescreen']); }

View File

@@ -23,14 +23,30 @@ foreach (dbFetchRows("SELECT * FROM `applications` WHERE `device_id` = ?", array
} else {
#echo('<img src="images/icons/greyscale/'.$app['app_type'].'.png" class="optionicon" />');
}
echo(generate_link(ucfirst($app['app_type']),$link_array,array('app'=>$app['app_type'])));
$link_add = array('app'=>$app['app_type']);
$text = ucfirst($app['app_type']);
if(!empty($app['app_instance']))
{
$text .= "(".$app['app_instance'].")";
$link_add['instance'] = $app['app_id'];
}
echo(generate_link($text,$link_array,$link_add));
if ($vars['app'] == $app['app_type']) { echo("</span>"); }
$sep = " | ";
}
print_optionbar_end();
$app = dbFetchRow("SELECT * FROM `applications` WHERE `device_id` = ? AND `app_type` = ?", array($device['device_id'], $vars['app']));
$where_array = array($device['device_id'], $vars['app']);
if($vars['instance'])
{
$where = " AND `app_id` = ?";
$where_array[] = $vars['instance'];
}
$app = dbFetchRow("SELECT * FROM `applications` WHERE `device_id` = ? AND `app_type` = ?".$where, $where_array);
#print_r($app);
if (is_file("pages/device/apps/".mres($vars['app']).".inc.php"))
{

View File

@@ -0,0 +1,32 @@
<?php
global $config;
$graphs = array('memcached_bits' => 'Traffic',
'memcached_commands' => 'Commands',
'memcached_data' => 'Data Size',
'memcached_items' => 'Items',
'memcached_uptime' => 'Uptime',
'memcached_threads' => 'Threads',
);
foreach ($graphs as $key => $text)
{
$graph_array['height'] = "100";
$graph_array['width'] = "215";
$graph_array['to'] = $now;
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = "application_".$key;
echo('<h3>'.$text.'</h3>');
echo("<tr bgcolor='$row_colour'><td colspan=5>");
include("includes/print-graphrow.inc.php");
echo("</td></tr>");
}
?>

View File

@@ -533,8 +533,8 @@ function notify($device,$title,$message)
$emails = parse_email($email);
if ($emails)
{
$message_header = $config['page_title_prefix']."\n";
$message_footer = "E-mail sent to: ";
$message_header = $config['page_title_prefix']."\n\n";
$message_footer = "\n\nE-mail sent to: ";
$i = 0;
$count = count($emails);
foreach ($emails as $email => $email_name)

View File

@@ -2,9 +2,9 @@
## Polls Apache statistics from script via SNMP
if (!empty($agent_data['apache']))
if (!empty($agent_data['app']['apache']))
{
$apache = $agent_data['apache'];
$apache = $agent_data['app']['apache'];
} else {
$options = "-O qv";
$oid = "nsExtendOutputFull.6.97.112.97.99.104.101";

View File

@@ -1,7 +1,7 @@
<?php
$drbd_dev = $app['app_instance'];
$drbd_data = $agent_data['drbd'][$drbd_dev];
$drbd_data = $agent_data['app']['drbd'][$drbd_dev];
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-drbd-".$drbd_dev.".rrd";

View File

@@ -0,0 +1,44 @@
<?php
$data = $agent_data['app']['memcached'][$app['app_instance']];
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-memcached-".$app['app_id'].".rrd";
echo("memcached(".$app['app_instance'].") ");
if (!is_file($rrd_filename)) {
rrdtool_create ($rrd_filename, "--step 300 \
DS:uptime:DERIVE:600:0:125000000000 \
DS:threads:GAUGE:600:0:125000000000 \
DS:rusage_user_ms:DERIVE:600:0:125000000000 \
DS:rusage_system_ms:DERIVE:600:0:125000000000 \
DS:curr_items:GAUGE:600:0:125000000000 \
DS:total_items:DERIVE:600:0:125000000000 \
DS:limit_maxbytes:GAUGE:600:0:125000000000 \
DS:curr_connections:GAUGE:600:0:125000000000 \
DS:total_connections:DERIVE:600:0:125000000000 \
DS:conn_structures:GAUGE:600:0:125000000000 \
DS:bytes:GAUGE:600:0:125000000000 \
DS:cmd_get:DERIVE:600:0:125000000000 \
DS:cmd_set:DERIVE:600:0:125000000000 \
DS:get_hits:DERIVE:600:0:125000000000 \
DS:get_misses:DERIVE:600:0:125000000000 \
DS:evictions:DERIVE:600:0:125000000000 \
DS:bytes_read:DERIVE:600:0:125000000000 \
DS:bytes_written:DERIVE:600:0:125000000000 \
".$config['rrd_rra']);
}
$dslist = array('uptime', 'threads', 'rusage_user_microseconds','rusage_system_microseconds','curr_items','total_items','limit_maxbytes','curr_connections','total_connections',
'connection_structures','bytes','cmd_get','cmd_set','get_hits','get_misses','evictions','bytes_read','bytes_written');
$values = array();
foreach ($dslist as $ds)
{
$values[] = isset($data[$ds]) ? $data[$ds] : -1;
}
rrdtool_update($rrd_filename, "N:".implode(":", $values));
?>

View File

@@ -1,9 +1,9 @@
<?php
### FIXME - this is lame
if(!empty($agent_data['mysql']))
if(!empty($agent_data['app']['mysql']))
{
$mysql = $agent_data['mysql'];
$mysql = $agent_data['app']['mysql'];
} else {
#Polls MySQL statistics from script via SNMP
$mysql_cmd = $config['snmpget'] ." -m NET-SNMP-EXTEND-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
@@ -25,6 +25,8 @@ foreach ($data as $str)
#$nstring .= (float)trim($elements[1]).":";
}
### General Stats
$mapping = array(
'IDBLBSe' => 'cr',
'IBLFh' => 'ct',
@@ -115,9 +117,6 @@ foreach ($mapping as $key)
}
$string = implode(':', $values);
#$data = explode("\n", $mysql);
#$nstring = trim(implode(':',$data),':');
if (!is_file($mysql_rrd))
{
rrdtool_create ($mysql_rrd, "--step 300 \
@@ -203,6 +202,44 @@ if (!is_file($mysql_rrd))
}
rrdtool_update($mysql_rrd, "N:$string");
echo("done ");
/// Process state statistics
$mysql_status_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-mysql-".$app['app_id']."-status.rrd";
$mapping_status = array(
'State_closing_tables' => 'd2',
'State_copying_to_tmp_table' => 'd3',
'State_end' => 'd4',
'State_freeing_items' => 'd5',
'State_init' => 'd6',
'State_locked' => 'd7',
'State_login' => 'd8',
'State_preparing' => 'd9',
'State_reading_from_net' => 'da',
'State_sending_data' => 'db',
'State_sorting_result' => 'dc',
'State_statistics' => 'dd',
'State_updating' => 'de',
'State_writing_to_net' => 'df',
'State_none' => 'dg',
'State_other' => 'dh'
);
$values = array(); $rrd_create = "";
foreach ($mapping_status as $desc => $id)
{
$values[] = isset($map[$id]) ? $map[$id] : -1;
$rrd_create .= " DS:".$id.":GAUGE:600:0:125000000000";
}
$string = implode(':', $values);
if (!is_file($mysql_status_rrd))
{
rrdtool_create ($mysql_status_rrd, "--step 300 ".$rrd_create." ".$config['rrd_rra']);
}
rrdtool_update($mysql_status_rrd, "N:$string");
?>

View File

@@ -134,9 +134,12 @@ function poll_device($device, $options)
if ($options['m'])
{
if (is_file("includes/polling/".$options['m'].".inc.php"))
foreach(explode(",", $options['m']) as $module)
{
include("includes/polling/".$options['m'].".inc.php");
if (is_file("includes/polling/".$module.".inc.php"))
{
include("includes/polling/".$module.".inc.php");
}
}
} else {
foreach ($config['poller_modules'] as $module => $module_status)

View File

@@ -5,9 +5,12 @@ if($device['os_group'] == "unix")
echo("Observium UNIX Agent: ");
$port='6556';
### FIXME - this should be in config and overridable in database
$agent = fsockopen($device['hostname'], $port, $errno, $errstr, 10);
$agent_port='6556';
$agent_start = utime();
$agent = fsockopen($device['hostname'], $agent_port, $errno, $errstr, 10);
if (!$agent)
{
@@ -18,14 +21,29 @@ if($device['os_group'] == "unix")
$agent_raw .= fgets($agent, 128);
}
}
$agent_end = utime(); $agent_time = round(($agent_end - $agent_start) * 1000);
if (!empty($agent_raw))
{
echo("execution time: ".$agent_time."ms");
$agent_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/agent.rrd";
if (!is_file($agent_rrd))
{
rrdtool_create ($agent_rrd, "DS:time:GAUGE:600:0:U ".$config['rrd_rra']);
}
rrdtool_update($agent_rrd, "N:".$agent_time);
$graphs['agent'] = TRUE;
foreach (explode("<<<", $agent_raw) as $section)
{
list($section, $data) = explode(">>>", $section);
list($sa, $sb) = explode("-", $section, 2);
if($section == "apache") { $sa = "app"; $sb = "apache"; }
if($section == "mysql") { $sa = "app"; $sb = "mysql"; }
if($section == "drbd") { $sa = "app"; $sb = "drbd"; }
if(!empty($sa) && !empty($sb))
{
$agent_data[$sa][$sb] = trim($data);
@@ -34,7 +52,7 @@ if($device['os_group'] == "unix")
}
}
#print_r($agent_data);
# print_r($agent_data);
include("unix-agent/packages.inc.php");
include("unix-agent/munin-plugins.inc.php");
@@ -53,7 +71,7 @@ if($device['os_group'] == "unix")
}
### Apache
if (!empty($agent_data['apache']))
if (!empty($agent_data['app']['apache']))
{
$app_found['apache'] = TRUE;
if (dbFetchCell("SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?", array($device['device_id'], 'apache')) == "0")
@@ -63,8 +81,22 @@ if($device['os_group'] == "unix")
}
}
### memcached
if (!empty($agent_data['app']['memcached']))
{
$agent_data['app']['memcached'] = unserialize($agent_data['app']['memcached']);
foreach ($agent_data['app']['memcached'] as $memcached_host => $memcached_data)
{
if (dbFetchCell("SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ? AND `app_instance` = ?", array($device['device_id'], 'memcached', $memcached_host)) == "0")
{
echo("Found new application 'Memcached' $memcached_host\n");
dbInsert(array('device_id' => $device['device_id'], 'app_type' => 'memcached', 'app_instance' => $memcached_host), 'applications');
}
}
}
### MySQL
if (!empty($agent_data['mysql']))
if (!empty($agent_data['app']['mysql']))
{
$app_found['mysql'] = TRUE;
if (dbFetchCell("SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?", array($device['device_id'], 'mysql')) == "0")
@@ -75,7 +107,7 @@ if($device['os_group'] == "unix")
}
### DRBD
if (!empty($agent_data['drbd']))
if (!empty($agent_data['app']['drbd']))
{
$agent_data['drbd_raw'] = $agent_data['drbd'];
$agent_data['drbd'] = array();

View File

@@ -896,12 +896,16 @@ foreach ($config['os'] as $this_os => $blah)
### Graph Types
$config['graph_sections'] = array('system', 'firewall', 'netstats', 'wireless', 'storage', 'vpdn', 'load balancer');
$config['graph_sections'] = array('general', 'system', 'firewall', 'netstats', 'wireless', 'storage', 'vpdn', 'load balancer');
$config['graph_types']['device']['wifi_clients']['section'] = 'wireless';
$config['graph_types']['device']['wifi_clients']['order'] = '0';
$config['graph_types']['device']['wifi_clients']['descr'] = 'Wireless Clients';
$config['graph_types']['device']['agent']['section'] = 'system';
$config['graph_types']['device']['agent']['order'] = '0';
$config['graph_types']['device']['agent']['descr'] = 'Agent Execution Time';
$config['graph_types']['device']['cipsec_flow_bits']['section'] = 'firewall';
$config['graph_types']['device']['cipsec_flow_bits']['order'] = '0';
$config['graph_types']['device']['cipsec_flow_bits']['descr'] = 'IPSec Tunnel Traffic Volume';

View File

@@ -65,7 +65,7 @@ if (!$where)
echo(" Instances start at 0. 0-3 for -n 4\n\n");
echo("Debugging and testing options:\n");
echo("-d Enable debugging output\n");
echo("-m Specify single module to be run\n");
echo("-m Specify module(s) to be run\n");
echo("\n");
echo("No polling type specified!\n");
exit;

13
scripts/agent-local/memcached Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/php
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$stats = $m->getStats();
if(is_array($stats))
{
echo("<<<app-memcached>>>\n");
echo(serialize($m->getStats()));
echo("\n");
}
?>

View File

@@ -650,6 +650,7 @@ function ss_get_mysql_stats( $options ) {
'binary_log_space' => 'cz',
'innodb_locked_tables' => 'd0',
'innodb_lock_structs' => 'd1',
'State_closing_tables' => 'd2',
'State_copying_to_tmp_table' => 'd3',
'State_end' => 'd4',
@@ -666,6 +667,7 @@ function ss_get_mysql_stats( $options ) {
'State_writing_to_net' => 'df',
'State_none' => 'dg',
'State_other' => 'dh',
'Handler_commit' => 'di',
'Handler_delete' => 'dj',
'Handler_discover' => 'dk',
@@ -681,6 +683,7 @@ function ss_get_mysql_stats( $options ) {
'Handler_savepoint_rollback' => 'du',
'Handler_update' => 'dv',
'Handler_write' => 'dw',
# Some InnoDB stats added later...
'innodb_tables_in_use' => 'dx',
'innodb_lock_wait_secs' => 'dy',

2
sql-schema/015.sql Normal file
View File

@@ -0,0 +1,2 @@
ALTER TABLE `munin_plugins_ds` CHANGE `ds_cdef` `ds_cdef` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;
ALTER TABLE `applications` ADD `app_state` TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;