Missing scripts

This commit is contained in:
Kamil Porembinski 2016-05-02 09:29:00 +02:00
parent 7c43b446ea
commit 3c937983ef
12 changed files with 1643 additions and 1779 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
$item = $argv[1]; $item = $argv[1];
function file_get_contents_curl($url) { function file_get_contents_curl($url) {
$ch = curl_init(); $ch = curl_init();

16
bin/arduino.py Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
import serial
import sys
import time
ser=serial.Serial('/dev/ttyACM0', 9600, timeout=0.5)
ser.open()
try:
time.sleep(2)
ser.flush()
ser.write(sys.argv[1]+"\n")
response=ser.readline()
print response
# ser.close()
except:
print " ERROR "

68
bin/blacklist.sh Normal file
View File

@ -0,0 +1,68 @@
#!/bin/bash
# http://giantdorks.org/alain/shell-script-to-query-a-list-of-hostnames-or-ip-addresses-against-a-list-of-local-and-remote-dns-black-lists/
# Modified by Gerard Stanczak gerard@thecamels.org
# Usage: blacklist.sh DOMAIN
# IPs or hostnames to check if none provided as arguments to the script
hosts='
'
# Locally maintained list of DNSBLs to check
LocalList='
b.barracudacentral.org
'
# pipe delimited exclude list for remote lists
Exclude='spamtrap.drbl.drand.net|dnsbl.proxybl.org|^dnsbl.mailer.mobi$|^foo.bar$|^bar.baz$|^.*webiron.*$'
# Remotely maintained list of DNSBLs to check
WPurl="https://en.wikipedia.org/wiki/Comparison_of_DNS_blacklists"
WPlst=$(curl -s $WPurl | egrep "<td>([a-z]+\.){1,7}[a-z]+</td>" | sed -r "s|</?td>||g;/$Exclude/d")
# ---------------------------------------------------------------------
HostToIP()
{
if ( echo "$host" | egrep -q "[a-zA-Z]" ); then
IP=$(host "$host" | awk '/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ {print$NF}')
else
IP="$host"
fi
}
Reverse()
{
echo $1 | awk -F. '{print$4"."$3"."$2"."$1}'
}
Check()
{
result=$(dig +short $rIP.$BL)
if [ -n "$result" ]; then
echo -e "$host LISTED $BL (answer = $result)"
else
echo -e "$host OK $BL"
fi
}
if [ -n "$1" ]; then
hosts=$@
fi
if [ -z "$hosts" ]; then
hosts=$(netstat -tn | awk '$4 ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ && $4 !~ /127.0.0/ {gsub(/:[0-9]+/,"",$4);} END{print$4}')
fi
for host in $hosts; do
HostToIP
rIP=$(Reverse $IP)
# Checking $IP against BLs from $WPurl"
for BL in $WPlst; do
Check
done
# Checking $IP against BLs from a local list"
for BL in $LocalList; do
Check
done
done

7
bin/check-update.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
day=$(date +%e)
if ((day <= 7)) ; then
result=`/usr/bin/yum -q check-update | grep -v "^$"`
echo -n "$result" > /tmp/yum-update-pending
chown zabbix.zabbix /tmp/yum-update-pending
fi

View File

@ -1,10 +1,4 @@
#!/bin/bash #!/bin/bash
# Script for HDD discovery
#
# Created by:
# Michał Macioszek, Taras Baran, Michal Gębora, Marcin Wilk, Maks Bednarek, Anna Fałek, Mikołaj Szczuraszek
disks=`ls -l /dev/sd* | awk '{print $NF}' | sed 's/[0-9]//g' | uniq` disks=`ls -l /dev/sd* | awk '{print $NF}' | sed 's/[0-9]//g' | uniq`
echo -n "{\"data\":[" echo -n "{\"data\":["

View File

@ -0,0 +1,19 @@
#!bin/bash
comma=1
echo -n "{\"data\":["
for i in $(sudo /bin/find /var/lib/mysql -type f -printf %p+%s= | tr "=" "\n" | grep -v "\/mysql\/mysql\/" | grep "\.ibd" | cut -d "+" -f 1 | sed 's/@002d/\-/g' | cut -d "/" -f 5- | sed 's/.ibd//g' ); do
dbname=$(echo $i | cut -d '/' -f 1)
tblname=$(echo $i | cut -d '/' -f 2)
if [ $comma -eq 0 ]; then
echo -n ","
fi
comma=0
echo -n "{\"{#DBNAME}\":\"$dbname\",\"{#TABLENAME}\":\"$tblname\"}"
done
echo -n "]}"

View File

@ -0,0 +1,29 @@
#!/bin/bash
cachefile='/tmp/mysqldbsize.log'
random=$RANDOM
if [ ! -e $cachefile ]; then
touch -d "2 hours ago" $cachefile
fi
if [ $# -ne 2 ]; then
echo "Usage: $0 dbname tablename"
exit 1
fi
cachefileage=$(($(date +%s) - $(stat -c %Y $cachefile)))
process_running=$(ps aux | grep 'find /var/lib/mysql' | grep -v "grep" | wc -l)
if [ "$cachefileage" -gt 60 ] && [ "$process_running" -eq 0 ]; then
sudo /bin/find /var/lib/mysql -type f -printf %p+%s= | tr "=" "\n" | grep -v "\/mysql\/mysql\/" | grep "\.ibd" | sed 's/@002d/\-/g' > $cachefile.$random
if [ $? -eq 0 ]; then
mv $cachefile.$random $cachefile
chown zabbix.zabbix $cachefile
fi
fi
grep "/$1/" $cachefile | grep "/$2\.ibd" | cut -d "+" -f 2

12
bin/pgsql_find_db.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# If you want to monitor "foo" and "bar" databases, you set the GETDB as
# GETDB="select datname from pg_database where datname in ('foo','bar');"
# CREATE USER zabbix WITH PASSWORD 'asfrtgrg432f';
# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO zabbix;
GETDB="select datname from pg_database where datistemplate = 'f';"
for dbname in $(psql -U zabbix -d postgres -t -c "${GETDB}"); do
dblist="$dblist,"'{"{#DBNAME}":"'$dbname'"}'
done
echo '{"data":['${dblist#,}' ]}'

View File

@ -1,24 +1,11 @@
<?php <?php
# ============================================================================ # ============================================================================
# This is a script to retrieve information from a MySQL server for input to a # This program is part of Percona Monitoring Plugins
# Cacti graphing process. It is hosted at # License: GPL License (see COPYING)
# http://code.google.com/p/mysql-cacti-templates/. # Copyright 2008-2015 Baron Schwartz, 2012-2015 Percona
# # Authors:
# This program is copyright (c) 2007 Baron Schwartz. Feedback and improvements # Baron Schwartz, Roman Vynar
# are welcome.
#
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
# ============================================================================ # ============================================================================
# ============================================================================ # ============================================================================
@ -41,19 +28,27 @@ if ( !array_key_exists('SCRIPT_FILENAME', $_SERVER)
# .cnf extension. # .cnf extension.
# ============================================================================ # ============================================================================
$mysql_user = 'zabbix'; $mysql_user = 'zabbix';
$mysql_pass = 'ha7jqnlacwefrs'; $mysql_pass = 'wJ44mR6a59r3duDr';
$mysql_port = 3306; $mysql_port = 3306;
$mysql_ssl = FALSE; # Whether to use SSL to connect to MySQL. $mysql_ssl = FALSE; # Whether to use SSL to connect to MySQL.
$mysql_ssl_key = '/etc/pki/tls/certs/mysql/client-key.pem';
$mysql_ssl_cert = '/etc/pki/tls/certs/mysql/client-cert.pem';
$mysql_ssl_ca = '/etc/pki/tls/certs/mysql/ca-cert.pem';
$heartbeat = FALSE; # Whether to use pt-heartbeat table for repl. delay calculation.
$heartbeat_utc = FALSE; # Whether pt-heartbeat is run with --utc option.
$heartbeat_server_id = 0; # Server id to associate with a heartbeat. Leave 0 if no preference.
$heartbeat_table = 'percona.heartbeat'; # db.tbl.
$heartbeat = ''; # db.tbl in case you use mk-heartbeat from Maatkit.
$cache_dir = '/tmp'; # If set, this uses caching to avoid multiple calls. $cache_dir = '/tmp'; # If set, this uses caching to avoid multiple calls.
$poll_time = 300; # Adjust to match your polling interval. $poll_time = 300; # Adjust to match your polling interval.
$timezone = null; # If not set, uses the system default. Example: "UTC"
$chk_options = array ( $chk_options = array (
'innodb' => true, # Do you want to check InnoDB statistics? 'innodb' => true, # Do you want to check InnoDB statistics?
'master' => true, # Do you want to check binary logging? 'master' => true, # Do you want to check binary logging?
'slave' => true, # Do you want to check slave status? 'slave' => true, # Do you want to check slave status?
'procs' => true, # Do you want to check SHOW PROCESSLIST? 'procs' => true, # Do you want to check SHOW PROCESSLIST?
'get_qrt' => true, # Get query response times from Percona Server? 'get_qrt' => true, # Get query response times from Percona Server or MariaDB?
); );
$use_ss = FALSE; # Whether to use the script server or not $use_ss = FALSE; # Whether to use the script server or not
@ -63,13 +58,18 @@ $debug_log = FALSE; # If $debug_log is a filename, it'll be used.
# ============================================================================ # ============================================================================
# You should not need to change anything below this line. # You should not need to change anything below this line.
# ============================================================================ # ============================================================================
$version = "1.1.8"; $version = '1.1.5';
# ============================================================================ # ============================================================================
# Include settings from an external config file (issue 39). # Include settings from an external config file.
# ============================================================================ # ============================================================================
if ( file_exists(__FILE__ . '.cnf' ) ) { if ( file_exists('/etc/cacti/' . basename(__FILE__) . '.cnf' ) ) {
require('/etc/cacti/' . basename(__FILE__) . '.cnf');
debug('Found configuration file /etc/cacti/' . basename(__FILE__) . '.cnf');
}
elseif ( file_exists(__FILE__ . '.cnf' ) ) {
require(__FILE__ . '.cnf'); require(__FILE__ . '.cnf');
debug('Found configuration file ' . __FILE__ . '.cnf');
} }
# Make this a happy little script even when there are errors. # Make this a happy little script even when there are errors.
@ -104,6 +104,18 @@ if ( $use_ss ) {
} }
} }
# ============================================================================
# Set the default timezone either to the configured, system timezone, or the
# default set above in the script.
# ============================================================================
if ( function_exists("date_default_timezone_set")
&& function_exists("date_default_timezone_get") ) {
$tz = ($timezone ? $timezone : @date_default_timezone_get());
if ( $tz ) {
@date_default_timezone_set($tz);
}
}
# ============================================================================ # ============================================================================
# Make sure we can also be called as a script. # Make sure we can also be called as a script.
# ============================================================================ # ============================================================================
@ -156,8 +168,12 @@ if ( !function_exists('array_change_key_case') ) {
# Validate that the command-line options are here and correct # Validate that the command-line options are here and correct
# ============================================================================ # ============================================================================
function validate_options($options) { function validate_options($options) {
debug($options); $opts = array('host', 'items', 'user', 'pass', 'nocache', 'port', 'server-id');
$opts = array('host', 'items', 'user', 'pass', 'heartbeat', 'nocache', 'port'); # Show help
if ( array_key_exists('help', $options) ) {
usage('');
}
# Required command-line options # Required command-line options
foreach ( array('host', 'items') as $option ) { foreach ( array('host', 'items') as $option ) {
if ( !isset($options[$option]) || !$options[$option] ) { if ( !isset($options[$option]) || !$options[$option] ) {
@ -175,21 +191,20 @@ function validate_options($options) {
# Print out a brief usage summary # Print out a brief usage summary
# ============================================================================ # ============================================================================
function usage($message) { function usage($message) {
global $mysql_user, $mysql_pass, $mysql_port, $heartbeat; global $mysql_user, $mysql_pass, $mysql_port;
$usage = <<<EOF $usage = <<<EOF
$message $message
Usage: php ss_get_mysql_stats.php --host <host> --items <item,...> [OPTION] Usage: php ss_get_mysql_stats.php --host <host> --items <item,...> [OPTION]
--host Hostname to connect to; use host:port syntax to specify a port --host MySQL host
Use :/path/to/socket if you want to connect via a UNIX socket
--items Comma-separated list of the items whose data you want --items Comma-separated list of the items whose data you want
--user MySQL username; defaults to $mysql_user if not given --user MySQL username
--pass MySQL password; defaults to $mysql_pass if not given --pass MySQL password
--heartbeat MySQL heartbeat table; defaults to '$heartbeat' (see mk-heartbeat) --port MySQL port
--server-id Server id to associate with a heartbeat if heartbeat usage is enabled
--nocache Do not cache results in a file --nocache Do not cache results in a file
--port MySQL port; defaults to $mysql_port if not given --help Show usage
--mysql_ssl Add the MYSQL_CLIENT_SSL flag to mysql_connect() call
EOF; EOF;
die($usage); die($usage);
@ -200,39 +215,23 @@ EOF;
# return them as an array ( arg => value ) # return them as an array ( arg => value )
# ============================================================================ # ============================================================================
function parse_cmdline( $args ) { function parse_cmdline( $args ) {
$result = array(); $options = array();
$cur_arg = ''; while (list($tmp, $p) = each($args)) {
foreach ($args as $val) { if (strpos($p, '--') === 0) {
if ( strpos($val, '--') === 0 ) { $param = substr($p, 2);
if ( strpos($val, '--no') === 0 ) { $value = null;
# It's an option without an argument, but it's a --nosomething so $nextparam = current($args);
# it's OK. if ($nextparam !== false && strpos($nextparam, '--') !==0) {
$result[substr($val, 2)] = 1; list($tmp, $value) = each($args);
$cur_arg = '';
} }
elseif ( $cur_arg ) { # Maybe the last --arg was an option with no arg $options[$param] = $value;
if ( $cur_arg == '--user' || $cur_arg == '--pass' || $cur_arg == '--port' ) {
# Special case because Cacti will pass these without an arg
$cur_arg = '';
}
else {
die("No arg: $cur_arg\n");
}
}
else {
$cur_arg = $val;
}
}
else {
$result[substr($cur_arg, 2)] = $val;
$cur_arg = '';
} }
} }
if ( $cur_arg && ($cur_arg != '--user' && $cur_arg != '--pass' && $cur_arg != '--port') ) { if ( array_key_exists('host', $options) ) {
die("No arg: $cur_arg\n"); $options['host'] = substr($options['host'], 0, 4) == 'tcp:' ? substr($options['host'], 4) : $options['host'];
} }
debug($result); debug($options);
return $result; return $options;
} }
# ============================================================================ # ============================================================================
@ -240,43 +239,24 @@ function parse_cmdline( $args ) {
# top of this file. # top of this file.
# ============================================================================ # ============================================================================
function ss_get_mysql_stats( $options ) { function ss_get_mysql_stats( $options ) {
# Process connection options and connect to MySQL. # Process connection options.
global $debug, $mysql_user, $mysql_pass, $heartbeat, $cache_dir, $poll_time, global $debug, $mysql_user, $mysql_pass, $cache_dir, $poll_time, $chk_options,
$chk_options, $mysql_port, $mysql_ssl; $mysql_port, $mysql_ssl, $mysql_ssl_key, $mysql_ssl_cert, $mysql_ssl_ca,
$heartbeat, $heartbeat_table, $heartbeat_server_id, $heartbeat_utc;
# Connect to MySQL.
$user = isset($options['user']) ? $options['user'] : $mysql_user; $user = isset($options['user']) ? $options['user'] : $mysql_user;
$pass = isset($options['pass']) ? $options['pass'] : $mysql_pass; $pass = isset($options['pass']) ? $options['pass'] : $mysql_pass;
$host = $options['host'];
$port = isset($options['port']) ? $options['port'] : $mysql_port; $port = isset($options['port']) ? $options['port'] : $mysql_port;
$heartbeat = isset($options['heartbeat']) ? $options['heartbeat'] : $heartbeat; $heartbeat_server_id = isset($options['server-id']) ? $options['server-id'] : $heartbeat_server_id;
# If there is a port, or if it's a non-standard port, we add ":$port" to the
# hostname.
$host_str = $options['host']
. (isset($options['port']) || $port != 3306 ? ":$port" : '');
debug(array('connecting to', $host_str, $user, $pass));
if ( !extension_loaded('mysql') ) {
debug("The MySQL extension is not loaded");
die("The MySQL extension is not loaded");
}
if ( $mysql_ssl || (isset($options['mysql_ssl']) && $options['mysql_ssl']) ) {
$conn = mysql_connect($host_str, $user, $pass, true, MYSQL_CLIENT_SSL);
}
else {
$conn = mysql_connect($host_str, $user, $pass);
}
if ( !$conn ) {
die("MySQL: " . mysql_error());
}
$sanitized_host $sanitized_host = str_replace(array(":", "/"), array("", "_"), $host);
= str_replace(array(":", "/"), array("", "_"), $options['host']); $cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt" . ($port != 3306 ? ":$port" : '');
$cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt"
. (isset($options['port']) || $port != 3306 ? ":$port" : '');
debug("Cache file is $cache_file"); debug("Cache file is $cache_file");
# First, check the cache. # First, check the cache.
$fp = null; $fp = null;
if ( !isset($options['nocache']) ) { if ( $cache_dir && !array_key_exists('nocache', $options) ) {
if ( $fp = fopen($cache_file, 'a+') ) { if ( $fp = fopen($cache_file, 'a+') ) {
$locked = flock($fp, 1); # LOCK_SH $locked = flock($fp, 1); # LOCK_SH
if ( $locked ) { if ( $locked ) {
@ -308,14 +288,36 @@ function ss_get_mysql_stats( $options ) {
} }
} }
else { else {
debug("Couldn't lock the cache file, ignoring it.");
$fp = null; $fp = null;
debug("Couldn't lock the cache file, ignoring it");
} }
} }
else {
$fp = null;
debug("Couldn't open the cache file");
}
} }
else { else {
$fp = null; debug("Caching is disabled.");
debug("Couldn't open the cache file"); }
# Connect to MySQL.
debug(array('Connecting to', $host, $port, $user, $pass));
if ( !extension_loaded('mysqli') ) {
debug("PHP MySQLi extension is not loaded");
die("PHP MySQLi extension is not loaded");
}
if ( $mysql_ssl ) {
$conn = mysqli_init();
mysqli_ssl_set($conn, $mysql_ssl_key, $mysql_ssl_cert, $mysql_ssl_ca, NULL, NULL);
mysqli_real_connect($conn, $host, $user, $pass, NULL, $port);
}
else {
$conn = mysqli_connect($host, $user, $pass, NULL, $port);
}
if ( mysqli_connect_errno() ) {
debug("MySQL connection failed: " . mysqli_connect_error());
die("ERROR: " . mysqli_connect_error());
} }
# Set up variables. # Set up variables.
@ -334,22 +336,22 @@ function ss_get_mysql_stats( $options ) {
'innodb_sem_wait_time_ms' => 0, 'innodb_sem_wait_time_ms' => 0,
# Values for the 'state' column from SHOW PROCESSLIST (converted to # Values for the 'state' column from SHOW PROCESSLIST (converted to
# lowercase, with spaces replaced by underscores) # lowercase, with spaces replaced by underscores)
'State_closing_tables' => null, 'State_closing_tables' => 0,
'State_copying_to_tmp_table' => null, 'State_copying_to_tmp_table' => 0,
'State_end' => null, 'State_end' => 0,
'State_freeing_items' => null, 'State_freeing_items' => 0,
'State_init' => null, 'State_init' => 0,
'State_locked' => null, 'State_locked' => 0,
'State_login' => null, 'State_login' => 0,
'State_preparing' => null, 'State_preparing' => 0,
'State_reading_from_net' => null, 'State_reading_from_net' => 0,
'State_sending_data' => null, 'State_sending_data' => 0,
'State_sorting_result' => null, 'State_sorting_result' => 0,
'State_statistics' => null, 'State_statistics' => 0,
'State_updating' => null, 'State_updating' => 0,
'State_writing_to_net' => null, 'State_writing_to_net' => 0,
'State_none' => null, 'State_none' => 0,
'State_other' => null, # Everything not listed above 'State_other' => 0, # Everything not listed above
); );
# Get SHOW STATUS and convert the name-value array into a simple # Get SHOW STATUS and convert the name-value array into a simple
@ -367,7 +369,14 @@ function ss_get_mysql_stats( $options ) {
# Get SHOW SLAVE STATUS, and add it to the $status array. # Get SHOW SLAVE STATUS, and add it to the $status array.
if ( $chk_options['slave'] ) { if ( $chk_options['slave'] ) {
$result = run_query("SHOW SLAVE STATUS", $conn); # Leverage lock-free SHOW SLAVE STATUS if available
$result = run_query("SHOW SLAVE STATUS NONBLOCKING", $conn);
if ( !$result ) {
$result = run_query("SHOW SLAVE STATUS NOLOCK", $conn);
if ( !$result ) {
$result = run_query("SHOW SLAVE STATUS", $conn);
}
}
$slave_status_rows_gotten = 0; $slave_status_rows_gotten = 0;
foreach ( $result as $row ) { foreach ( $result as $row ) {
$slave_status_rows_gotten++; $slave_status_rows_gotten++;
@ -379,9 +388,16 @@ function ss_get_mysql_stats( $options ) {
# Check replication heartbeat, if present. # Check replication heartbeat, if present.
if ( $heartbeat ) { if ( $heartbeat ) {
if ( $heartbeat_utc ) {
$now_func = 'UNIX_TIMESTAMP(UTC_TIMESTAMP)';
}
else {
$now_func = 'UNIX_TIMESTAMP()';
}
$result2 = run_query( $result2 = run_query(
"SELECT GREATEST(0, UNIX_TIMESTAMP() - UNIX_TIMESTAMP(ts) - 1)" "SELECT MAX($now_func - ROUND(UNIX_TIMESTAMP(ts)))"
. " AS delay FROM $heartbeat WHERE id = 1", $conn); . " AS delay FROM $heartbeat_table"
. " WHERE $heartbeat_server_id = 0 OR server_id = $heartbeat_server_id", $conn);
$slave_delay_rows_gotten = 0; $slave_delay_rows_gotten = 0;
foreach ( $result2 as $row2 ) { foreach ( $result2 as $row2 ) {
$slave_delay_rows_gotten++; $slave_delay_rows_gotten++;
@ -391,7 +407,7 @@ function ss_get_mysql_stats( $options ) {
$status['slave_lag'] = $row2['delay']; $status['slave_lag'] = $row2['delay'];
} }
else { else {
debug("Couldn't get slave lag from $heartbeat"); debug("Couldn't get slave lag from $heartbeat_table");
} }
} }
if ( $slave_delay_rows_gotten == 0 ) { if ( $slave_delay_rows_gotten == 0 ) {
@ -443,6 +459,10 @@ function ss_get_mysql_stats( $options ) {
if ( $state == '' ) { if ( $state == '' ) {
$state = 'none'; $state = 'none';
} }
# MySQL 5.5 replaces the 'Locked' state with a variety of "Waiting for
# X lock" types of statuses. Wrap these all back into "Locked" because
# we don't really care about the type of locking it is.
$state = preg_replace('/^(Table lock|Waiting for .*lock)$/', 'Locked', $state);
$state = str_replace(' ', '_', strtolower($state)); $state = str_replace(' ', '_', strtolower($state));
if ( array_key_exists("State_$state", $status) ) { if ( array_key_exists("State_$state", $status) ) {
increment($status, "State_$state", 1); increment($status, "State_$state", 1);
@ -453,35 +473,59 @@ function ss_get_mysql_stats( $options ) {
} }
} }
# Get SHOW ENGINES to be able to determine whether InnoDB is present.
$engines = array();
$result = run_query("SHOW ENGINES", $conn);
foreach ( $result as $row ) {
$engines[$row[0]] = $row[1];
}
# Get SHOW INNODB STATUS and extract the desired metrics from it, then add # Get SHOW INNODB STATUS and extract the desired metrics from it, then add
# those to the array too. # those to the array too.
if ( $chk_options['innodb'] if ( $chk_options['innodb']
&& array_key_exists('have_innodb', $status) && array_key_exists('InnoDB', $engines)
&& $status['have_innodb'] == 'YES' && $engines['InnoDB'] == 'YES'
|| $engines['InnoDB'] == 'DEFAULT'
) { ) {
$result = run_query("SHOW /*!50000 ENGINE*/ INNODB STATUS", $conn); $result = run_query("SHOW /*!50000 ENGINE*/ INNODB STATUS", $conn);
$istatus_text = $result[0]['Status']; $istatus_text = $result[0]['Status'];
$istatus_vals = get_innodb_array($istatus_text); $istatus_vals = get_innodb_array($istatus_text);
# Get response time histogram from Percona Server if enabled. # Get response time histogram from Percona Server or MariaDB if enabled.
if ( $chk_options['get_qrt'] if ( $chk_options['get_qrt']
&& isset($status['have_response_time_distribution']) && (( isset($status['have_response_time_distribution'])
&& ($status['have_response_time_distribution'] == 'YES')) && $status['have_response_time_distribution'] == 'YES')
|| (isset($status['query_response_time_stats'])
&& $status['query_response_time_stats'] == 'ON')) )
{ {
debug('Getting query time histogram'); debug('Getting query time histogram');
$i = 0; $i = 0;
$result = run_query( $result = run_query(
"SELECT `count`, total * 1000000 AS total " "SELECT `count`, ROUND(total * 1000000) AS total "
. "FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME " . "FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME "
. "WHERE `time` <> 'TOO LONG'", . "WHERE `time` <> 'TOO LONG'",
$conn); $conn);
foreach ( $result as $row ) { foreach ( $result as $row ) {
if ( $i > 13 ) {
# It's possible that the number of rows returned isn't 14.
# Don't add extra status counters.
break;
}
$count_key = sprintf("Query_time_count_%02d", $i); $count_key = sprintf("Query_time_count_%02d", $i);
$total_key = sprintf("Query_time_total_%02d", $i); $total_key = sprintf("Query_time_total_%02d", $i);
$status[$count_key] = $row['count']; $status[$count_key] = $row['count'];
$status[$total_key] = $row['total']; $status[$total_key] = $row['total'];
$i++; $i++;
} }
# It's also possible that the number of rows returned is too few.
# Don't leave any status counters unassigned; it will break graphs.
while ( $i <= 13 ) {
$count_key = sprintf("Query_time_count_%02d", $i);
$total_key = sprintf("Query_time_total_%02d", $i);
$status[$count_key] = 0;
$status[$total_key] = 0;
$i++;
}
} }
else { else {
debug('Not getting time histogram because it is not enabled'); debug('Not getting time histogram because it is not enabled');
@ -506,6 +550,8 @@ function ss_get_mysql_stats( $options ) {
'Innodb_rows_inserted' => 'rows_inserted', 'Innodb_rows_inserted' => 'rows_inserted',
'Innodb_rows_read' => 'rows_read', 'Innodb_rows_read' => 'rows_read',
'Innodb_rows_updated' => 'rows_updated', 'Innodb_rows_updated' => 'rows_updated',
'Innodb_buffer_pool_reads' => 'pool_reads',
'Innodb_buffer_pool_read_requests' => 'pool_read_requests',
); );
# If the SHOW STATUS value exists, override... # If the SHOW STATUS value exists, override...
@ -548,204 +594,221 @@ function ss_get_mysql_stats( $options ) {
} }
# Define the variables to output. I use shortened variable names so maybe # Define the variables to output. I use shortened variable names so maybe
# it'll all fit in 1024 bytes for Cactid and Spine's benefit. This list must # it'll all fit in 1024 bytes for Cactid and Spine's benefit. Strings must
# come right after the word MAGIC_VARS_DEFINITIONS. The Perl script parses # have some non-hex characters (non a-f0-9) to avoid a Cacti bug. This list
# it and uses it as a Perl variable. # must come right after the word MAGIC_VARS_DEFINITIONS. The Perl script
# parses it and uses it as a Perl variable.
$keys = array( $keys = array(
'Key_read_requests' => 'a0', 'Key_read_requests' => 'gg',
'Key_reads' => 'a1', 'Key_reads' => 'gh',
'Key_write_requests' => 'a2', 'Key_write_requests' => 'gi',
'Key_writes' => 'a3', 'Key_writes' => 'gj',
'history_list' => 'a4', 'history_list' => 'gk',
'innodb_transactions' => 'a5', 'innodb_transactions' => 'gl',
'read_views' => 'a6', 'read_views' => 'gm',
'current_transactions' => 'a7', 'current_transactions' => 'gn',
'locked_transactions' => 'a8', 'locked_transactions' => 'go',
'active_transactions' => 'a9', 'active_transactions' => 'gp',
'pool_size' => 'aa', 'pool_size' => 'gq',
'free_pages' => 'ab', 'free_pages' => 'gr',
'database_pages' => 'ac', 'database_pages' => 'gs',
'modified_pages' => 'ad', 'modified_pages' => 'gt',
'pages_read' => 'ae', 'pages_read' => 'gu',
'pages_created' => 'af', 'pages_created' => 'gv',
'pages_written' => 'ag', 'pages_written' => 'gw',
'file_fsyncs' => 'ah', 'file_fsyncs' => 'gx',
'file_reads' => 'ai', 'file_reads' => 'gy',
'file_writes' => 'aj', 'file_writes' => 'gz',
'log_writes' => 'ak', 'log_writes' => 'hg',
'pending_aio_log_ios' => 'al', 'pending_aio_log_ios' => 'hh',
'pending_aio_sync_ios' => 'am', 'pending_aio_sync_ios' => 'hi',
'pending_buf_pool_flushes' => 'an', 'pending_buf_pool_flushes' => 'hj',
'pending_chkp_writes' => 'ao', 'pending_chkp_writes' => 'hk',
'pending_ibuf_aio_reads' => 'ap', 'pending_ibuf_aio_reads' => 'hl',
'pending_log_flushes' => 'aq', 'pending_log_flushes' => 'hm',
'pending_log_writes' => 'ar', 'pending_log_writes' => 'hn',
'pending_normal_aio_reads' => 'as', 'pending_normal_aio_reads' => 'ho',
'pending_normal_aio_writes' => 'at', 'pending_normal_aio_writes' => 'hp',
'ibuf_inserts' => 'au', 'ibuf_inserts' => 'hq',
'ibuf_merged' => 'av', 'ibuf_merged' => 'hr',
'ibuf_merges' => 'aw', 'ibuf_merges' => 'hs',
'spin_waits' => 'ax', 'spin_waits' => 'ht',
'spin_rounds' => 'ay', 'spin_rounds' => 'hu',
'os_waits' => 'az', 'os_waits' => 'hv',
'rows_inserted' => 'b0', 'rows_inserted' => 'hw',
'rows_updated' => 'b1', 'rows_updated' => 'hx',
'rows_deleted' => 'b2', 'rows_deleted' => 'hy',
'rows_read' => 'b3', 'rows_read' => 'hz',
'Table_locks_waited' => 'b4', 'Table_locks_waited' => 'ig',
'Table_locks_immediate' => 'b5', 'Table_locks_immediate' => 'ih',
'Slow_queries' => 'b6', 'Slow_queries' => 'ii',
'Open_files' => 'b7', 'Open_files' => 'ij',
'Open_tables' => 'b8', 'Open_tables' => 'ik',
'Opened_tables' => 'b9', 'Opened_tables' => 'il',
'innodb_open_files' => 'ba', 'innodb_open_files' => 'im',
'open_files_limit' => 'bb', 'open_files_limit' => 'in',
'table_cache' => 'bc', 'table_cache' => 'io',
'Aborted_clients' => 'bd', 'Aborted_clients' => 'ip',
'Aborted_connects' => 'be', 'Aborted_connects' => 'iq',
'Max_used_connections' => 'bf', 'Max_used_connections' => 'ir',
'Slow_launch_threads' => 'bg', 'Slow_launch_threads' => 'is',
'Threads_cached' => 'bh', 'Threads_cached' => 'it',
'Threads_connected' => 'bi', 'Threads_connected' => 'iu',
'Threads_created' => 'bj', 'Threads_created' => 'iv',
'Threads_running' => 'bk', 'Threads_running' => 'iw',
'max_connections' => 'bl', 'max_connections' => 'ix',
'thread_cache_size' => 'bm', 'thread_cache_size' => 'iy',
'Connections' => 'bn', 'Connections' => 'iz',
'slave_running' => 'bo', 'slave_running' => 'jg',
'slave_stopped' => 'bp', 'slave_stopped' => 'jh',
'Slave_retried_transactions' => 'bq', 'Slave_retried_transactions' => 'ji',
'slave_lag' => 'br', 'slave_lag' => 'jj',
'Slave_open_temp_tables' => 'bs', 'Slave_open_temp_tables' => 'jk',
'Qcache_free_blocks' => 'bt', 'Qcache_free_blocks' => 'jl',
'Qcache_free_memory' => 'bu', 'Qcache_free_memory' => 'jm',
'Qcache_hits' => 'bv', 'Qcache_hits' => 'jn',
'Qcache_inserts' => 'bw', 'Qcache_inserts' => 'jo',
'Qcache_lowmem_prunes' => 'bx', 'Qcache_lowmem_prunes' => 'jp',
'Qcache_not_cached' => 'by', 'Qcache_not_cached' => 'jq',
'Qcache_queries_in_cache' => 'bz', 'Qcache_queries_in_cache' => 'jr',
'Qcache_total_blocks' => 'c0', 'Qcache_total_blocks' => 'js',
'query_cache_size' => 'c1', 'query_cache_size' => 'jt',
'Questions' => 'c2', 'Questions' => 'ju',
'Com_update' => 'c3', 'Com_update' => 'jv',
'Com_insert' => 'c4', 'Com_insert' => 'jw',
'Com_select' => 'c5', 'Com_select' => 'jx',
'Com_delete' => 'c6', 'Com_delete' => 'jy',
'Com_replace' => 'c7', 'Com_replace' => 'jz',
'Com_load' => 'c8', 'Com_load' => 'kg',
'Com_update_multi' => 'c9', 'Com_update_multi' => 'kh',
'Com_insert_select' => 'ca', 'Com_insert_select' => 'ki',
'Com_delete_multi' => 'cb', 'Com_delete_multi' => 'kj',
'Com_replace_select' => 'cc', 'Com_replace_select' => 'kk',
'Select_full_join' => 'cd', 'Select_full_join' => 'kl',
'Select_full_range_join' => 'ce', 'Select_full_range_join' => 'km',
'Select_range' => 'cf', 'Select_range' => 'kn',
'Select_range_check' => 'cg', 'Select_range_check' => 'ko',
'Select_scan' => 'ch', 'Select_scan' => 'kp',
'Sort_merge_passes' => 'ci', 'Sort_merge_passes' => 'kq',
'Sort_range' => 'cj', 'Sort_range' => 'kr',
'Sort_rows' => 'ck', 'Sort_rows' => 'ks',
'Sort_scan' => 'cl', 'Sort_scan' => 'kt',
'Created_tmp_tables' => 'cm', 'Created_tmp_tables' => 'ku',
'Created_tmp_disk_tables' => 'cn', 'Created_tmp_disk_tables' => 'kv',
'Created_tmp_files' => 'co', 'Created_tmp_files' => 'kw',
'Bytes_sent' => 'cp', 'Bytes_sent' => 'kx',
'Bytes_received' => 'cq', 'Bytes_received' => 'ky',
'innodb_log_buffer_size' => 'cr', 'innodb_log_buffer_size' => 'kz',
'unflushed_log' => 'cs', 'unflushed_log' => 'lg',
'log_bytes_flushed' => 'ct', 'log_bytes_flushed' => 'lh',
'log_bytes_written' => 'cu', 'log_bytes_written' => 'li',
'relay_log_space' => 'cv', 'relay_log_space' => 'lj',
'binlog_cache_size' => 'cw', 'binlog_cache_size' => 'lk',
'Binlog_cache_disk_use' => 'cx', 'Binlog_cache_disk_use' => 'll',
'Binlog_cache_use' => 'cy', 'Binlog_cache_use' => 'lm',
'binary_log_space' => 'cz', 'binary_log_space' => 'ln',
'innodb_locked_tables' => 'd0', 'innodb_locked_tables' => 'lo',
'innodb_lock_structs' => 'd1', 'innodb_lock_structs' => 'lp',
'State_closing_tables' => 'd2', 'State_closing_tables' => 'lq',
'State_copying_to_tmp_table' => 'd3', 'State_copying_to_tmp_table' => 'lr',
'State_end' => 'd4', 'State_end' => 'ls',
'State_freeing_items' => 'd5', 'State_freeing_items' => 'lt',
'State_init' => 'd6', 'State_init' => 'lu',
'State_locked' => 'd7', 'State_locked' => 'lv',
'State_login' => 'd8', 'State_login' => 'lw',
'State_preparing' => 'd9', 'State_preparing' => 'lx',
'State_reading_from_net' => 'da', 'State_reading_from_net' => 'ly',
'State_sending_data' => 'db', 'State_sending_data' => 'lz',
'State_sorting_result' => 'dc', 'State_sorting_result' => 'mg',
'State_statistics' => 'dd', 'State_statistics' => 'mh',
'State_updating' => 'de', 'State_updating' => 'mi',
'State_writing_to_net' => 'df', 'State_writing_to_net' => 'mj',
'State_none' => 'dg', 'State_none' => 'mk',
'State_other' => 'dh', 'State_other' => 'ml',
'Handler_commit' => 'di', 'Handler_commit' => 'mm',
'Handler_delete' => 'dj', 'Handler_delete' => 'mn',
'Handler_discover' => 'dk', 'Handler_discover' => 'mo',
'Handler_prepare' => 'dl', 'Handler_prepare' => 'mp',
'Handler_read_first' => 'dm', 'Handler_read_first' => 'mq',
'Handler_read_key' => 'dn', 'Handler_read_key' => 'mr',
'Handler_read_next' => 'do', 'Handler_read_next' => 'ms',
'Handler_read_prev' => 'dp', 'Handler_read_prev' => 'mt',
'Handler_read_rnd' => 'dq', 'Handler_read_rnd' => 'mu',
'Handler_read_rnd_next' => 'dr', 'Handler_read_rnd_next' => 'mv',
'Handler_rollback' => 'ds', 'Handler_rollback' => 'mw',
'Handler_savepoint' => 'dt', 'Handler_savepoint' => 'mx',
'Handler_savepoint_rollback' => 'du', 'Handler_savepoint_rollback' => 'my',
'Handler_update' => 'dv', 'Handler_update' => 'mz',
'Handler_write' => 'dw', 'Handler_write' => 'ng',
# Some InnoDB stats added later... 'innodb_tables_in_use' => 'nh',
'innodb_tables_in_use' => 'dx', 'innodb_lock_wait_secs' => 'ni',
'innodb_lock_wait_secs' => 'dy', 'hash_index_cells_total' => 'nj',
'hash_index_cells_total' => 'dz', 'hash_index_cells_used' => 'nk',
'hash_index_cells_used' => 'e0', 'total_mem_alloc' => 'nl',
'total_mem_alloc' => 'e1', 'additional_pool_alloc' => 'nm',
'additional_pool_alloc' => 'e2', 'uncheckpointed_bytes' => 'nn',
'uncheckpointed_bytes' => 'e3', 'ibuf_used_cells' => 'no',
'ibuf_used_cells' => 'e4', 'ibuf_free_cells' => 'np',
'ibuf_free_cells' => 'e5', 'ibuf_cell_count' => 'nq',
'ibuf_cell_count' => 'e6', 'adaptive_hash_memory' => 'nr',
'adaptive_hash_memory' => 'e7', 'page_hash_memory' => 'ns',
'page_hash_memory' => 'e8', 'dictionary_cache_memory' => 'nt',
'dictionary_cache_memory' => 'e9', 'file_system_memory' => 'nu',
'file_system_memory' => 'ea', 'lock_system_memory' => 'nv',
'lock_system_memory' => 'eb', 'recovery_system_memory' => 'nw',
'recovery_system_memory' => 'ec', 'thread_hash_memory' => 'nx',
'thread_hash_memory' => 'ed', 'innodb_sem_waits' => 'ny',
'innodb_sem_waits' => 'ee', 'innodb_sem_wait_time_ms' => 'nz',
'innodb_sem_wait_time_ms' => 'ef', 'Key_buf_bytes_unflushed' => 'og',
'Key_buf_bytes_unflushed' => 'eg', 'Key_buf_bytes_used' => 'oh',
'Key_buf_bytes_used' => 'eh', 'key_buffer_size' => 'oi',
'key_buffer_size' => 'ei', 'Innodb_row_lock_time' => 'oj',
'Innodb_row_lock_time' => 'ej', 'Innodb_row_lock_waits' => 'ok',
'Innodb_row_lock_waits' => 'ek', 'Query_time_count_00' => 'ol',
'Query_time_count_00' => 'el', 'Query_time_count_01' => 'om',
'Query_time_count_01' => 'em', 'Query_time_count_02' => 'on',
'Query_time_count_02' => 'en', 'Query_time_count_03' => 'oo',
'Query_time_count_03' => 'eo', 'Query_time_count_04' => 'op',
'Query_time_count_04' => 'ep', 'Query_time_count_05' => 'oq',
'Query_time_count_05' => 'eq', 'Query_time_count_06' => 'or',
'Query_time_count_06' => 'er', 'Query_time_count_07' => 'os',
'Query_time_count_07' => 'es', 'Query_time_count_08' => 'ot',
'Query_time_count_08' => 'et', 'Query_time_count_09' => 'ou',
'Query_time_count_09' => 'eu', 'Query_time_count_10' => 'ov',
'Query_time_count_10' => 'ev', 'Query_time_count_11' => 'ow',
'Query_time_count_11' => 'ew', 'Query_time_count_12' => 'ox',
'Query_time_count_12' => 'ex', 'Query_time_count_13' => 'oy',
'Query_time_count_13' => 'ey', 'Query_time_total_00' => 'oz',
'Query_time_total_00' => 'ez', 'Query_time_total_01' => 'pg',
'Query_time_total_01' => 'fa', 'Query_time_total_02' => 'ph',
'Query_time_total_02' => 'fb', 'Query_time_total_03' => 'pi',
'Query_time_total_03' => 'fc', 'Query_time_total_04' => 'pj',
'Query_time_total_04' => 'fd', 'Query_time_total_05' => 'pk',
'Query_time_total_05' => 'fe', 'Query_time_total_06' => 'pl',
'Query_time_total_06' => 'ff', 'Query_time_total_07' => 'pm',
'Query_time_total_07' => 'fg', 'Query_time_total_08' => 'pn',
'Query_time_total_08' => 'fh', 'Query_time_total_09' => 'po',
'Query_time_total_09' => 'fi', 'Query_time_total_10' => 'pp',
'Query_time_total_10' => 'fj', 'Query_time_total_11' => 'pq',
'Query_time_total_11' => 'fk', 'Query_time_total_12' => 'pr',
'Query_time_total_12' => 'fl', 'Query_time_total_13' => 'ps',
'Query_time_total_13' => 'fm', 'wsrep_replicated_bytes' => 'pt',
'wsrep_received_bytes' => 'pu',
'wsrep_replicated' => 'pv',
'wsrep_received' => 'pw',
'wsrep_local_cert_failures' => 'px',
'wsrep_local_bf_aborts' => 'py',
'wsrep_local_send_queue' => 'pz',
'wsrep_local_recv_queue' => 'qg',
'wsrep_cluster_size' => 'qh',
'wsrep_cert_deps_distance' => 'qi',
'wsrep_apply_window' => 'qj',
'wsrep_commit_window' => 'qk',
'wsrep_flow_control_paused' => 'ql',
'wsrep_flow_control_sent' => 'qm',
'wsrep_flow_control_recv' => 'qn',
'pool_reads' => 'qo',
'pool_read_requests' => 'qp',
); );
# Return the output. # Return the output.
@ -846,13 +909,26 @@ function get_innodb_array($text) {
$results['spin_rounds'][] = to_int($row[5]); $results['spin_rounds'][] = to_int($row[5]);
$results['os_waits'][] = to_int($row[8]); $results['os_waits'][] = to_int($row[8]);
} }
elseif (strpos($line, 'RW-shared spins') === 0 ) { elseif (strpos($line, 'RW-shared spins') === 0
&& strpos($line, ';') > 0 ) {
# RW-shared spins 3859028, OS waits 2100750; RW-excl spins 4641946, OS waits 1530310 # RW-shared spins 3859028, OS waits 2100750; RW-excl spins 4641946, OS waits 1530310
$results['spin_waits'][] = to_int($row[2]); $results['spin_waits'][] = to_int($row[2]);
$results['spin_waits'][] = to_int($row[8]); $results['spin_waits'][] = to_int($row[8]);
$results['os_waits'][] = to_int($row[5]); $results['os_waits'][] = to_int($row[5]);
$results['os_waits'][] = to_int($row[11]); $results['os_waits'][] = to_int($row[11]);
} }
elseif (strpos($line, 'RW-shared spins') === 0 && strpos($line, '; RW-excl spins') === FALSE) {
# Post 5.5.17 SHOW ENGINE INNODB STATUS syntax
# RW-shared spins 604733, rounds 8107431, OS waits 241268
$results['spin_waits'][] = to_int($row[2]);
$results['os_waits'][] = to_int($row[7]);
}
elseif (strpos($line, 'RW-excl spins') === 0) {
# Post 5.5.17 SHOW ENGINE INNODB STATUS syntax
# RW-excl spins 604733, rounds 8107431, OS waits 241268
$results['spin_waits'][] = to_int($row[2]);
$results['os_waits'][] = to_int($row[7]);
}
elseif (strpos($line, 'seconds the semaphore:') > 0) { elseif (strpos($line, 'seconds the semaphore:') > 0) {
# --Thread 907205 has waited at handler/ha_innodb.cc line 7156 for 1.00 seconds the semaphore: # --Thread 907205 has waited at handler/ha_innodb.cc line 7156 for 1.00 seconds the semaphore:
increment($results, 'innodb_sem_waits', 1); increment($results, 'innodb_sem_waits', 1);
@ -866,7 +942,8 @@ function get_innodb_array($text) {
# transactions # transactions
# Trx id counter 0 1170664159 # Trx id counter 0 1170664159
# Trx id counter 861B144C # Trx id counter 861B144C
$results['innodb_transactions'] = make_bigint($row[3], $row[4]); $results['innodb_transactions'] = make_bigint(
$row[3], (isset($row[4]) ? $row[4] : null));
$txn_seen = TRUE; $txn_seen = TRUE;
} }
elseif ( strpos($line, 'Purge done for trx') === 0 ) { elseif ( strpos($line, 'Purge done for trx') === 0 ) {
@ -952,6 +1029,16 @@ function get_innodb_array($text) {
$results['ibuf_used_cells'] = to_int($row[2]); $results['ibuf_used_cells'] = to_int($row[2]);
$results['ibuf_free_cells'] = to_int($row[6]); $results['ibuf_free_cells'] = to_int($row[6]);
$results['ibuf_cell_count'] = to_int($row[9]); $results['ibuf_cell_count'] = to_int($row[9]);
if (strpos($line, 'merges')) {
$results['ibuf_merges'] = to_int($row[10]);
}
}
elseif (strpos($line, ', delete mark ') > 0 && strpos($prev_line, 'merged operations:') === 0 ) {
# Output of show engine innodb status has changed in 5.5
# merged operations:
# insert 593983, delete mark 387006, delete 73092
$results['ibuf_inserts'] = to_int($row[1]);
$results['ibuf_merged'] = to_int($row[1]) + to_int($row[4]) + to_int($row[6]);
} }
elseif (strpos($line, ' merged recs, ') > 0 ) { elseif (strpos($line, ' merged recs, ') > 0 ) {
# 19817685 inserts, 19817684 merged recs, 3552620 merges # 19817685 inserts, 19817684 merged recs, 3552620 merges
@ -1007,8 +1094,9 @@ function get_innodb_array($text) {
} }
# BUFFER POOL AND MEMORY # BUFFER POOL AND MEMORY
elseif (strpos($line, "Total memory allocated") === 0 ) { elseif (strpos($line, "Total memory allocated") === 0 && strpos($line, "in additional pool allocated") > 0 ) {
# Total memory allocated 29642194944; in additional pool allocated 0 # Total memory allocated 29642194944; in additional pool allocated 0
# Total memory allocated by read views 96
$results['total_mem_alloc'] = to_int($row[3]); $results['total_mem_alloc'] = to_int($row[3]);
$results['additional_pool_alloc'] = to_int($row[8]); $results['additional_pool_alloc'] = to_int($row[8]);
} }
@ -1088,6 +1176,7 @@ function get_innodb_array($text) {
$results['queries_inside'] = to_int($row[0]); $results['queries_inside'] = to_int($row[0]);
$results['queries_queued'] = to_int($row[4]); $results['queries_queued'] = to_int($row[4]);
} }
$prev_line = $line;
} }
foreach ( array('spin_waits', 'spin_rounds', 'os_waits') as $key ) { foreach ( array('spin_waits', 'spin_rounds', 'os_waits') as $key ) {
@ -1144,23 +1233,29 @@ function to_int ( $str ) {
} }
# ============================================================================ # ============================================================================
# Wrap mysql_query in error-handling, and instead of returning the result, # Wrap mysqli_query in error-handling, and instead of returning the result,
# return an array of arrays in the result. # return an array of arrays in the result.
# ============================================================================ # ============================================================================
function run_query($sql, $conn) { function run_query($sql, $conn) {
global $debug; global $debug;
debug($sql); debug($sql);
$result = @mysql_query($sql, $conn); $result = @mysqli_query($conn, $sql);
if ( $debug ) { if ( $debug && strpos($sql, 'SHOW SLAVE STATUS ') === false ) {
$error = @mysql_error($conn); $error = @mysqli_error($conn);
if ( $error ) { if ( $error ) {
debug(array($sql, $error)); debug(array($sql, $error));
die("SQLERR $error in $sql"); die("SQLERR $error in $sql");
} }
} }
$array = array(); $array = array();
while ( $row = @mysql_fetch_array($result) ) { $count = @mysqli_num_rows($result);
$array[] = $row; if ( $count > 10000 ) {
debug('Abnormal number of rows returned: ' . $count);
}
else {
while ( $row = @mysqli_fetch_array($result) ) {
$array[] = $row;
}
} }
debug(array($sql, $array)); debug(array($sql, $array));
return $array; return $array;
@ -1268,7 +1363,7 @@ function debug($val) {
if ( !count($calls) ) { if ( !count($calls) ) {
$calls[] = "at $file:$line"; $calls[] = "at $file:$line";
} }
fwrite($fp, date('Y-m-d h:i:s') . ' ' . implode(' <- ', $calls)); fwrite($fp, date('Y-m-d H:i:s') . ' ' . implode(' <- ', $calls));
fwrite($fp, "\n" . var_export($val, TRUE) . "\n"); fwrite($fp, "\n" . var_export($val, TRUE) . "\n");
fclose($fp); fclose($fp);
} }
@ -1278,4 +1373,3 @@ function debug($val) {
} }
} }
?>

7
bin/swap_enabled.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
swap=$(free -m | grep -i swap | awk '{ print $2 }')
if [ "$swap" != "0" ]; then
echo '{"data":[{"{#TOTAL}":"total", "{#FREE}":"free", "{#PFREE}":"pfree", "{#PUSED}":"pused" } ]}'
fi

View File

@ -9,4 +9,10 @@ zabbix ALL=(ALL) NOPASSWD: /opt/dell/srvadmin/bin/omreport
zabbix ALL=(ALL) NOPASSWD: /usr/bin/bcu zabbix ALL=(ALL) NOPASSWD: /usr/bin/bcu
zabbix ALL=(ALL) NOPASSWD: /sbin/powermt zabbix ALL=(ALL) NOPASSWD: /sbin/powermt
zabbix ALL=(ALL) NOPASSWD: /bin/find /var/spool/postfix/ -type f zabbix ALL=(ALL) NOPASSWD: /bin/find /var/spool/postfix/ -type f
zabbix ALL=(ALL) NOPASSWD: /usr/sbin/httpd -v
zabbix ALL=(ALL) NOPASSWD: /usr/sbin/dmidecode
zabbix ALL=(ALL) NOPASSWD: /usr/bin/stat
zabbix ALL=(ALL) NOPASSWD: /usr/bin/md5sum
zabbix ALL=(ALL) NOPASSWD: /bin/find /var/lib/mysql/ -type f -printf %p+%s=
zabbix ALL=(ALL) NOPASSWD: /etc/zabbix/bin/haproxy.sh
Defaults:zabbix !requiretty Defaults:zabbix !requiretty

File diff suppressed because it is too large Load Diff