From 841c97982fe1f53efcad527914283976348e0e6c Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 9 Sep 2015 16:45:09 +0300 Subject: [PATCH] Server monitoring tools --- bin/v-list-sys-cpu-status | 42 +++++++ bin/v-list-sys-db-status | 83 +++++++++++++ bin/v-list-sys-disk-status | 40 +++++++ bin/v-list-sys-dns-status | 75 ++++++++++++ bin/v-list-sys-mail-status | 46 ++++++++ bin/v-list-sys-memory-status | 40 +++++++ bin/v-list-sys-network-status | 40 +++++++ bin/v-list-sys-web-status | 49 ++++++++ web/list/server/index.php | 136 ++++++++++++++++++++-- web/templates/admin/list_server_info.html | 44 +++++++ 10 files changed, 586 insertions(+), 9 deletions(-) create mode 100755 bin/v-list-sys-cpu-status create mode 100755 bin/v-list-sys-db-status create mode 100755 bin/v-list-sys-disk-status create mode 100755 bin/v-list-sys-dns-status create mode 100755 bin/v-list-sys-mail-status create mode 100755 bin/v-list-sys-memory-status create mode 100755 bin/v-list-sys-network-status create mode 100755 bin/v-list-sys-web-status create mode 100644 web/templates/admin/list_server_info.html diff --git a/bin/v-list-sys-cpu-status b/bin/v-list-sys-cpu-status new file mode 100755 index 00000000..fa925f8b --- /dev/null +++ b/bin/v-list-sys-cpu-status @@ -0,0 +1,42 @@ +#!/bin/bash +# info: list system cpu info +# options: [FORMAT] +# +# The function lists cpu information + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +#format=${1-shell} + +# Includes +#source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Displaying top 30 +top -b -n1 | head -n 37 +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying process tree +pstree -s +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying CPU information +grep 'model name' /proc/cpuinfo|cut -f 2 -d : | sed "s/ //" +echo +lscpu 2>/dev/null + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-list-sys-db-status b/bin/v-list-sys-db-status new file mode 100755 index 00000000..755ff5c4 --- /dev/null +++ b/bin/v-list-sys-db-status @@ -0,0 +1,83 @@ +#!/bin/bash +# info: list db status +# options: [FORMAT] +# +# The function lists db server status + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +#format=${1-shell} + +# Includes +#source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Checking db system +if [ -z "$DB_SYSTEM" ]; then + exit +fi + +# Checking supported database systems +for db in $(echo $DB_SYSTEM| tr ',' '\n'); do + OLD_IFS="$IFS" + IFS=$'\n' + + # Checking database config + if [ -e "$VESTA/conf/$db.conf" ]; then + + # Checking server status + for host_str in $(cat $VESTA/conf/$db.conf); do + eval $host_str + + # Checking MySQL + if [ "$db" = 'mysql' ]; then + mycnf="$VESTA/conf/.mysql.$HOST" + if [ ! -e "$mycnf" ]; then + echo "[client]">$mycnf + echo "host='$HOST'" >> $mycnf + echo "user='$USER'" >> $mycnf + echo "password='$PASSWORD'" >> $mycnf + chmod 600 $mycnf + else + mypw=$(grep password $mycnf|cut -f 2 -d \') + if [ "$mypw" != "$PASSWORD" ]; then + echo "[client]">$mycnf + echo "host='$HOST'" >> $mycnf + echo "user='$USER'" >> $mycnf + echo "password='$PASSWORD'" >> $mycnf + chmod 660 $mycnf + fi + fi + echo "MySQL $HOST status" + mysqladmin --defaults-file=$mycnf status |sed -e "s/ /\n/g" + echo + mysqladmin --defaults-file=$mycnf processlist + echo -en "\n-------------------------------------" + echo -en "-------------------------------------\n\n" + fi + + # Checking PostgreSQL + if [ "$db" = 'pgsql' ]; then + echo "PostgreSQL $HOST status" + export PGPASSWORD="$PASSWORD" + psql -h $HOST -U $USER -c "SELECT * FROM pg_stat_activity" + fi + done + fi + IFS="$OLD_IFS" +done + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-list-sys-disk-status b/bin/v-list-sys-disk-status new file mode 100755 index 00000000..c8b50f85 --- /dev/null +++ b/bin/v-list-sys-disk-status @@ -0,0 +1,40 @@ +#!/bin/bash +# info: list disk information +# options: [FORMAT] +# +# The function lists disk information + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +#format=${1-shell} + +# Includes +#source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Displaying disk usage +df -h +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying I/O usage +iostat -m +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying disk information +fdisk -l + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-list-sys-dns-status b/bin/v-list-sys-dns-status new file mode 100755 index 00000000..d39cd40a --- /dev/null +++ b/bin/v-list-sys-dns-status @@ -0,0 +1,75 @@ +#!/bin/bash +# info: list dns status +# options: [FORMAT] +# +# The function lists dns server status + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +#format=${1-shell} + +# Includes +#source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Checking dns system +if [ -z "$DNS_SYSTEM" ]; then + exit +fi + +# Checking statistics-file on RHEL/CentOS +if [ -e "/etc/named/named.conf" ]; then + conf="/etc/named/named.conf" + dump_file='/var/named/data/named_stats.txt' + dump_option=" dump-file \"$dump_file\";" + opt_check=$(grep $dump_file $conf |grep -v //) + if [ -z "$opt_check" ]; then + sed -i "s|options {|options {\n$dump_option|" $conf + service named restart >/dev/null 2>&1 + fi +fi +if [ -e "/etc/named.conf" ]; then + conf="/etc/named.conf" + dump_file='/var/named/data/named_stats.txt' + dump_option=" dump-file \"$dump_file\";" + opt_check=$(grep $dump_file $conf |grep -v //) + if [ -z "$opt_check" ]; then + sed -i "s|options {|options {\n$dump_option|" $conf + service named restart >/dev/null 2>&1 + fi +fi + +# Checking statistics-file on Debian/Ubuntu +if [ -e "/etc/bind/named.conf" ]; then + conf="/etc/bind/named.conf.options" + dump_file='/var/cache/bind/named.stats' + #dump_option=" dump-file \"$dump_file\";" + #opt_check=$(grep $dump_file $conf |grep -v //) + #if [ -z "$opt_check" ]; then + # sed -i "s|options {|options {\n$dump_option|" $conf + # service named restart >/dev/null 2>&1 + #fi +fi + +# Generating dns stats +rm -f $dump_file 2>/dev/null +/usr/sbin/rndc stats 2>/dev/null + +# Displaying dns status +if [ -e "$dump_file" ]; then + cat $dump_file +fi + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-list-sys-mail-status b/bin/v-list-sys-mail-status new file mode 100755 index 00000000..802f24be --- /dev/null +++ b/bin/v-list-sys-mail-status @@ -0,0 +1,46 @@ +#!/bin/bash +# info: list mail status +# options: [FORMAT] +# +# The function lists mail server status + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +#format=${1-shell} + +# Includes +#source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Checking mail system +if [ -z "$MAIL_SYSTEM" ]; then + exit +fi + +# Displaying exim queue status +echo "Exim queue status" +exim -bp +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying exim stats +if [ -e "/var/log/exim4/mainlog" ]; then + eximstats /var/log/exim4/mainlog 2>/dev/null +else + eximstats /var/log/exim/main.log 2>/dev/null +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-list-sys-memory-status b/bin/v-list-sys-memory-status new file mode 100755 index 00000000..f6a8e077 --- /dev/null +++ b/bin/v-list-sys-memory-status @@ -0,0 +1,40 @@ +#!/bin/bash +# info: list virtual memory info +# options: [FORMAT] +# +# The function lists virtual memory information + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +#format=${1-shell} + +# Includes +#source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Displaying memory and swap usage +free -t -m +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying memory stats +vmstat -S m -s +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying ram information +dmidecode -t 17 2>/dev/null + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-list-sys-network-status b/bin/v-list-sys-network-status new file mode 100755 index 00000000..2050da57 --- /dev/null +++ b/bin/v-list-sys-network-status @@ -0,0 +1,40 @@ +#!/bin/bash +# info: list system network status +# options: [FORMAT] +# +# The function lists network status + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +#format=${1-shell} + +# Includes +#source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Displaying network stats +ss -s +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying network usage +lsof -itcp -n -P +echo -en "\n-------------------------------------" +echo -en "-------------------------------------\n\n" + +# Displaying network interfaces +ifconfig + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-list-sys-web-status b/bin/v-list-sys-web-status new file mode 100755 index 00000000..b243437a --- /dev/null +++ b/bin/v-list-sys-web-status @@ -0,0 +1,49 @@ +#!/bin/bash +# info: list web status +# options: [FORMAT] +# +# The function lists web server status + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +#format=${1-shell} + +# Includes +#source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Checking web system +if [ -z "$WEB_SYSTEM" ]; then + exit +fi + +# Displaying proxy status +if [ "$PROXY_SYSTEM" = 'nginx' ]; then + echo "

$PROXY_SYSTEM STATUS

"| tr '[:lower:]' '[:upper:]' + wget -qO- http://localhost:8084/ + echo "


" +fi + +# Displaying web server status +echo "

$WEB_SYSTEM STATUS

"| tr '[:lower:]' '[:upper:]' +if [ "$WEB_SYSTEM" != 'nginx' ]; then + wget -qO- http://localhost:8081/server-status/ |\ + egrep -v "html|DOCTYPE|h1>|title|head" +else + wget -qO- http://localhost:8084/ +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/web/list/server/index.php b/web/list/server/index.php index 57e0c5f5..c34a8b0e 100644 --- a/web/list/server/index.php +++ b/web/list/server/index.php @@ -5,6 +5,126 @@ $TAB = 'SERVER'; // Main include include($_SERVER['DOCUMENT_ROOT']."/inc/main.php"); +// Check user +if ($_SESSION['user'] != 'admin') { + header("Location: /list/user"); + exit; +} + +// CPU info +if (isset($_GET['cpu'])) { + $TAB = 'CPU'; + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_server_info.html'); + exec (VESTA_CMD.'v-list-sys-cpu-status', $output, $return_var); + if ($return_var == 0 ) { + foreach($output as $file) { + echo $file . "\n"; + } + } + echo " \n\n\n"; + exit(); +} + +// Memory info +if (isset($_GET['mem'])) { + $TAB = 'MEMORY'; + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_server_info.html'); + exec (VESTA_CMD.'v-list-sys-memory-status', $output, $return_var); + if ($return_var == 0 ) { + foreach($output as $file) { + echo $file . "\n"; + } + } + echo " \n\n\n"; + exit(); +} + +// Disk info +if (isset($_GET['disk'])) { + $TAB = 'MEMORY'; + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_server_info.html'); + exec (VESTA_CMD.'v-list-sys-disk-status', $output, $return_var); + if ($return_var == 0 ) { + foreach($output as $file) { + echo $file . "\n"; + } + } + echo " \n\n\n"; + exit(); +} + +// Network info +if (isset($_GET['net'])) { + $TAB = 'MEMORY'; + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_server_info.html'); + exec (VESTA_CMD.'v-list-sys-network-status', $output, $return_var); + if ($return_var == 0 ) { + foreach($output as $file) { + echo $file . "\n"; + } + } + echo " \n\n\n"; + exit(); +} + +// Web info +if (isset($_GET['web'])) { + $TAB = 'WEB'; + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_server_info.html'); + exec (VESTA_CMD.'v-list-sys-web-status', $output, $return_var); + if ($return_var == 0 ) { + foreach($output as $file) { + echo $file . "\n"; + } + } + echo " \n\n\n"; + exit(); +} + + +// DNS info +if (isset($_GET['dns'])) { + $TAB = 'DNS'; + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_server_info.html'); + exec (VESTA_CMD.'v-list-sys-dns-status', $output, $return_var); + if ($return_var == 0 ) { + foreach($output as $file) { + echo $file . "\n"; + } + } + echo " \n\n\n"; + exit(); +} + +// Mail info +if (isset($_GET['mail'])) { + $TAB = 'MAIL'; + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_server_info.html'); + exec (VESTA_CMD.'v-list-sys-mail-status', $output, $return_var); + if ($return_var == 0 ) { + foreach($output as $file) { + echo $file . "\n"; + } + } + echo " \n\n\n"; + exit(); +} + +// DB info +if (isset($_GET['db'])) { + $TAB = 'DB'; + include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_server_info.html'); + exec (VESTA_CMD.'v-list-sys-db-status', $output, $return_var); + if ($return_var == 0 ) { + foreach($output as $file) { + echo $file . "\n"; + } + } + echo " \n\n\n"; + exit(); +} + + // Header include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); @@ -12,15 +132,13 @@ include($_SERVER['DOCUMENT_ROOT'].'/templates/header.html'); top_panel($user,$TAB); // Data -if ($_SESSION['user'] == 'admin') { - exec (VESTA_CMD."v-list-sys-info json", $output, $return_var); - $sys = json_decode(implode('', $output), true); - unset($output); - exec (VESTA_CMD."v-list-sys-services json", $output, $return_var); - $data = json_decode(implode('', $output), true); - unset($output); - include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_services.html'); -} +exec (VESTA_CMD."v-list-sys-info json", $output, $return_var); +$sys = json_decode(implode('', $output), true); +unset($output); +exec (VESTA_CMD."v-list-sys-services json", $output, $return_var); +$data = json_decode(implode('', $output), true); +unset($output); +include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/list_services.html'); // Back uri $_SESSION['back'] = $_SERVER['REQUEST_URI']; diff --git a/web/templates/admin/list_server_info.html b/web/templates/admin/list_server_info.html new file mode 100644 index 00000000..94d5e833 --- /dev/null +++ b/web/templates/admin/list_server_info.html @@ -0,0 +1,44 @@ + + + + + + Vesta - <?=__($TAB)?> + + + + + + + + + + + + + + + +
.
+
\ No newline at end of file