new templates and scripts

This commit is contained in:
Gerard Stańczak
2014-08-11 14:22:34 +02:00
parent d57113ae10
commit b1ea93db6e
28 changed files with 16118 additions and 13647 deletions

87
bin/apc-check.php Normal file
View File

@@ -0,0 +1,87 @@
<?php
$item = $argv[1];
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1/apc-stats.php?apc=' . $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
switch($item) {
case 'mem.used':
$results = file_get_contents_curl("sma_info");
if ($results) {
$results = unserialize($results);
echo $results["seg_size"] * $results["num_seg"] - $results["avail_mem"];
}
else
exit;
break;
case 'mem.avail':
$results = file_get_contents_curl("sma_info");
if ($results) {
$results = unserialize($results);
echo $results["avail_mem"];
}
else
exit;
break;
case 'hits':
$results = file_get_contents_curl("cache_info");
if ($results) {
$results = unserialize($results);
echo $results["num_hits"];
}
else
exit;
break;
case 'misses':
$results = file_get_contents_curl("cache_info");
if ($results) {
$results = unserialize($results);
echo $results["num_misses"];
}
else
exit;
break;
case 'hits_ratio':
$results = file_get_contents_curl("cache_info");
if ($results) {
$results = unserialize($results);
echo ($results["num_hits"] / ($results["num_hits"] - $results["num_misses"]))*100;
}
else
exit;
break;
case 'entries':
$results = file_get_contents_curl("cache_info");
if ($results) {
$results = unserialize($results);
echo $results["num_entries"];
}
else
exit;
break;
case 'user.entries':
$results = file_get_contents_curl("user_cache_info");
if ($results) {
$results = unserialize($results);
echo $results["num_entries"];
}
else
exit;
break;
default:
exit;
}
?>

17
bin/apc-stats.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1") {
switch($_GET['apc']) {
case 'cache_info':
print(serialize(apc_cache_info('',true)));
break;
case 'sma_info':
print(serialize(apc_sma_info()));
break;
case 'user_cache_info':
print(serialize(apc_cache_info('user',true)));
break;
default:
exit;
}
}
?>

146
bin/opcache.php Normal file
View File

@@ -0,0 +1,146 @@
<?php
if ($_SERVER['SERVER_ADDR'] != $_SERVER['REMOTE_ADDR']){
header('HTTP/1.1 401 Unauthorized', true, 401);
exit;
}
$configuration = opcache_get_configuration();
$status = opcache_get_status(FALSE);
switch($_GET['item']) {
// CONFIGURATION
case 'version':
print($configuration['version']['version']);
break;
case 'enable':
print($configuration['directives']['opcache.enable']);
break;
case 'enable_cli':
print($configuration['directives']['opcache.enable_cli']);
break;
case 'use_cwd':
print($configuration['directives']['opcache.use_cwd']);
break;
case 'validate_timestamps':
print($configuration['directives']['opcache.validate_timestamps']);
break;
case 'inherited_hack':
print($configuration['directives']['opcache.inherited_hack']);
break;
case 'dups_fix':
print(($configuration['directives']['opcache.dups_fix'] ? 1 : 0));
break;
case 'revalidate_path':
print(($configuration['directives']['opcache.revalidate_path'] ? 1 : 0));
break;
case 'log_verbosity_level':
print($configuration['directives']['opcache.log_verbosity_level']);
break;
case 'memory_consumption':
print($configuration['directives']['opcache.memory_consumption']);
break;
case 'interned_strings_buffer':
print($configuration['directives']['opcache.interned_strings_buffer']);
break;
case 'max_accelerated_files':
print($configuration['directives']['opcache.max_accelerated_files']);
break;
case 'max_wasted_percentage':
print($configuration['directives']['opcache.max_wasted_percentage']);
break;
case 'consistency_checks':
print($configuration['directives']['opcache.consistency_checks']);
break;
case 'force_restart_timeout':
print($configuration['directives']['opcache.force_restart_timeout']);
break;
case 'revalidate_freq':
print($configuration['directives']['opcache.revalidate_freq']);
break;
case 'max_file_size':
print($configuration['directives']['opcache.max_file_size']);
break;
case 'protect_memory':
print(($configuration['directives']['opcache.protect_memory'] ? 1 : 0));
break;
case 'save_comments':
print($configuration['directives']['opcache.save_comments']);
break;
case 'load_comments':
print($configuration['directives']['opcache.load_comments']);
break;
case 'fast_shutdown':
print($configuration['directives']['opcache.fast_shutdown']);
break;
case 'enable_file_override':
print(($configuration['directives']['opcache.enable_file_override'] ? 1 : 0));
break;
case 'optimization_level':
print($configuration['directives']['opcache.optimization_level']);
break;
// STATUS
case 'used_memory':
print($status['memory_usage']['used_memory']);
break;
case 'free_memory':
print($status['memory_usage']['free_memory']);
break;
case 'wasted_memory':
print($status['memory_usage']['wasted_memory']);
break;
case 'current_wasted_percentage':
print($status['memory_usage']['current_wasted_percentage']);
break;
case 'buffer_size':
print($status['interned_strings_usage']['buffer_size']);
break;
case 'isu.used_memory':
print($status['interned_strings_usage']['used_memory']);
break;
case 'isu.free_memory':
print($status['interned_strings_usage']['free_memory']);
break;
case 'number_of_strings':
print($status['interned_strings_usage']['number_of_strings']);
break;
case 'num_cached_scripts':
print($status['opcache_statistics']['num_cached_scripts']);
break;
case 'num_cached_keys':
print($status['opcache_statistics']['num_cached_keys']);
break;
case 'max_cached_keys':
print($status['opcache_statistics']['max_cached_keys']);
break;
case 'hits':
print($status['opcache_statistics']['hits']);
break;
case 'oom_restarts':
print($status['opcache_statistics']['oom_restarts']);
break;
case 'hash_restarts':
print($status['opcache_statistics']['hash_restarts']);
break;
case 'manual_restarts':
print($status['opcache_statistics']['manual_restarts']);
break;
case 'misses':
print($status['opcache_statistics']['misses']);
break;
case 'blacklist_misses':
print($status['opcache_statistics']['blacklist_misses']);
break;
case 'blacklist_miss_ratio':
print($status['opcache_statistics']['blacklist_miss_ratio']);
break;
case 'opcache_hit_rate':
print($status['opcache_statistics']['opcache_hit_rate']);
break;
default:
exit;
}
?>

157
bin/rabbit.php Normal file
View File

@@ -0,0 +1,157 @@
<?php
define('RABBITMQCTL_BIN', '/usr/sbin/rabbitmqctl 2>/dev/null');
$results = array();
$cleanStats = array();
$matches = array();
$stats = array();
$stats['queues'] = shell_exec(RABBITMQCTL_BIN . ' list_queues name durable auto_delete messages_ready messages_unacknowledged messages consumers memory');
$stats['exchanges'] = shell_exec(RABBITMQCTL_BIN . ' list_exchanges type durable auto_delete');
$stats['bindings'] = shell_exec(RABBITMQCTL_BIN . ' list_bindings source_kind destination_kind');
$stats['connections'] = shell_exec(RABBITMQCTL_BIN . ' list_connections state channels protocol recv_oct send_oct');
$stats['channels'] = shell_exec(RABBITMQCTL_BIN . ' list_channels transactional confirm consumer_count messages_unacknowledged messages_uncommitted acks_uncommitted messages_unconfirmed');
foreach ($stats as $name => $statusString) {
$statusString = str_replace("\t", " ", $statusString);
$statusString = trim(str_replace("\r", " ", $statusString));
$stats[$name] = preg_replace('/ +/', ' ', $statusString);
$stats[$name] = explode("\n", $statusString);
foreach ($stats[$name] as $index => $value) {
if (strpos($value, '...') === false && !empty($value)) {
$cleanStats[$name][$index] = $value;
}
}
}
// QUEUES
if (isset($cleanStats['queues'])) {
foreach ($cleanStats['queues'] as $line) {
$columns = explode(' ', $line);
if (count($columns) == 8) {
$row = array(
'queues_count' => 1,
'queues_durable_count' => $columns[1] == 'true' ? 1 : 0,
'queues_auto_delete_count' => $columns[2] == 'true' ? 1 : 0,
'messages_ready_count' => $columns[3],
'messages_unacknowledged_count' => $columns[4],
'messages_count' => $columns[5],
'queue_consumers_count' => $columns[6],
'queues_memory_allocated' => $columns[7],
);
$results[] = $row;
}
}
}
$results[] = array(
'queues_count' => 0,
'queues_durable_count' => 0,
'queues_auto_delete_count' => 0,
'messages_ready_count' => 0,
'messages_unacknowledged_count' => 0,
'messages_count' => 0,
'queue_consumers_count' => 0,
'queues_memory_allocated' => 0,
);
// EXCHANGES
if (isset($cleanStats['exchanges'])) {
foreach ($cleanStats['exchanges'] as $line) {
$columns = explode(' ', $line);
if (count($columns) == 3) {
$row = array(
'exchanges_count' => 1,
'exchanges_durable_count' => $columns[1] == 'true' ? 1 : 0,
'exchanges_auto_delete_count' => $columns[2] == 'true' ? 1 : 0,
'exchanges_direct_count' => $columns[0] == 'direct' ? 1 : 0,
'exchanges_topic_count' => $columns[0] == 'topic' ? 1 : 0,
'exchanges_fanout_count' => $columns[0] == 'fanout' ? 1 : 0,
'exchanges_headers_count' => $columns[0] == 'headers' ? 1 : 0,
);
$results[] = $row;
}
}
}
$results[] = array(
'exchanges_count' => 0,
'exchanges_durable_count' => 0,
'exchanges_auto_delete_count' => 0,
'exchanges_direct_count' => 0,
'exchanges_topic_count' => 0,
'exchanges_fanout_count' => 0,
'exchanges_headers_count' => 0,
);
// CONNECTIONS
if (isset($cleanStats['connections'])) {
foreach ($cleanStats['connections'] as $line) {
$columns = explode(' ', $line);
if (count($columns) == 5) {
$row = array(
'connections_count' => 1,
'connections_starting' => $columns[0] == 'starting' ? 1 : 0,
'connections_tuning' => $columns[0] == 'tuning' ? 1 : 0,
'connections_opening' => $columns[0] == 'opening' ? 1 : 0,
'connections_running' => $columns[0] == 'running' ? 1 : 0,
'connections_blocking' => $columns[0] == 'blocking' ? 1 : 0,
'connections_blocked' => $columns[0] == 'blocked' ? 1 : 0,
'connections_closing' => $columns[0] == 'closing' ? 1 : 0,
'connections_closed' => $columns[0] == 'closed' ? 1 : 0,
);
$results[] = $row;
}
}
}
$results[] = array(
'connections_count' => 0,
'connections_starting' => 0,
'connections_tuning' => 0,
'connections_opening' => 0,
'connections_running' => 0,
'connections_blocking' => 0,
'connections_blocked' => 0,
'connections_closing' => 0,
'connections_closed' => 0,
);
// CHANNELS
if (isset($cleanStats['channels'])) {
foreach ($cleanStats['channels'] as $line) {
$columns = explode(' ', $line);
if (count($columns) == 2) {
$row = array(
'channels_count' => 1,
'channels_transactional_count' => $columns[0] == 'true' ? 1 : 0,
'channels_confirm_count' => $columns[1] == 'true' ? 1 : 0,
);
$results[] = $row;
}
}
}
$results[] = array(
'channels_count' => 0,
'channels_transactional_count' => 0,
'channels_confirm_count' => 0,
);
// BINDINGS
$results[] = array('bindings_count' => count($cleanStats['exchanges']));
//SUMMARU
$summary = array();
foreach ($results as $index => $values) {
foreach ($values as $name => $value) {
if (!isset($summary[$name])) {
$summary[$name] = 0;
}
$summary[$name] += $value;
}
}
// PRINT
foreach ($summary as $name => $value) {
echo $name . ':' . $value . "\n";
}

27
bin/rabbitmq.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
# =======================
cachefile='/tmp/rabbitmq.log'
command='sudo /usr/bin/php /etc/zabbix/bin/rabbit.php'
# =======================
random=$RANDOM
if [ ! -e $cachefile ]; then
touch -d "2 hours ago" $cachefile
fi
cachefileage=$(($(date +%s) - $(stat -c %Y $cachefile)))
process_running=$(ps aux | grep rabbit.php | grep -v "grep" | wc -l)
if [ "$cachefileage" -gt 60 ] && [ "$process_running" -eq 0 ]; then
output=$($command 2>&1)
if [ $? -eq 0 ]; then
echo "$output" > $cachefile.$random
mv $cachefile.$random $cachefile
chown zabbix.zabbix $cachefile
fi
fi
cat $cachefile

27
bin/rabbitmqctl.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
# =======================
cachefile='/tmp/rabbitmqctl.log'
command='sudo /usr/sbin/rabbitmqctl status'
# =======================
random=$RANDOM
if [ ! -e $cachefile ]; then
touch -d "2 hours ago" $cachefile
fi
cachefileage=$(($(date +%s) - $(stat -c %Y $cachefile)))
process_running=$(ps aux | grep "rabbitmqctl status" | grep -v "grep" | wc -l)
if [ "$cachefileage" -gt 60 ] && [ "$process_running" -eq 0 ]; then
output=$($command 2>&1)
if [ $? -eq 0 ]; then
echo "$output" > $cachefile.$random
mv $cachefile.$random $cachefile
chown zabbix.zabbix $cachefile
fi
fi
cat $cachefile