Server monitoring tools

This commit is contained in:
Serghey Rodin 2015-09-09 16:45:09 +03:00
commit 841c97982f
10 changed files with 586 additions and 9 deletions

42
bin/v-list-sys-cpu-status Executable file
View file

@ -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

83
bin/v-list-sys-db-status Executable file
View file

@ -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

40
bin/v-list-sys-disk-status Executable file
View file

@ -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

75
bin/v-list-sys-dns-status Executable file
View file

@ -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

46
bin/v-list-sys-mail-status Executable file
View file

@ -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

40
bin/v-list-sys-memory-status Executable file
View file

@ -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

40
bin/v-list-sys-network-status Executable file
View file

@ -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

49
bin/v-list-sys-web-status Executable file
View file

@ -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 "<h2>$PROXY_SYSTEM STATUS</h2>"| tr '[:lower:]' '[:upper:]'
wget -qO- http://localhost:8084/
echo "<br><br><br>"
fi
# Displaying web server status
echo "<h2>$WEB_SYSTEM STATUS</h2>"| 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

View file

@ -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 " </pre>\n</body>\n</html>\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 " </pre>\n</body>\n</html>\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 " </pre>\n</body>\n</html>\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 " </pre>\n</body>\n</html>\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 " </pre>\n</body>\n</html>\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 " </pre>\n</body>\n</html>\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 " </pre>\n</body>\n</html>\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 " </pre>\n</body>\n</html>\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'];

View file

@ -0,0 +1,44 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
<title>Vesta - <?=__($TAB)?> </title>
<link rel="stylesheet" href="/css/styles.min.css">
<link type="text/css" href="/css/jquery-custom-dialogs.css" rel="stylesheet" />
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="/js/events.js"></script>
</head>
<body>
<a href="#" class="to-top">
<i class="l-icon-to-top"></i>
</a>
<div class="l-header">
<div class="l-center">
<a href="/" class="l-logo"></a>
<!-- /.l-logo -->
<div class="l-menu clearfix">
<div class="l-menu__item <?php if(isset($_GET['cpu'])) echo 'l-menu__item--active' ?>"><a href="/list/server/?cpu"><?=__('CPU')?></a></div>
<div class="l-menu__item <?php if(isset($_GET['mem'])) echo 'l-menu__item--active' ?>"><a href="/list/server/?mem"><?=__('MEMORY')?></a></div>
<div class="l-menu__item <?php if(isset($_GET['disk'])) echo 'l-menu__item--active' ?>"><a href="/list/server/?disk"><?=__('DISK')?></a></div>
<div class="l-menu__item <?php if(isset($_GET['net'])) echo 'l-menu__item--active' ?>"><a href="/list/server/?net"><?=__('NETWORK')?></a></div>
<div class="l-menu__item <?php if(isset($_GET['web'])) echo 'l-menu__item--active' ?>"><a href="/list/server/?web"><?=__('WEB')?></a></div>
<div class="l-menu__item <?php if(isset($_GET['dns'])) echo 'l-menu__item--active' ?>"><a href="/list/server/?dns"><?=__('DNS')?></a></div>
<div class="l-menu__item <?php if(isset($_GET['mail'])) echo 'l-menu__item--active' ?>"><a href="/list/server/?mail"><?=__('MAIL')?></a></div>
<div class="l-menu__item <?php if(isset($_GET['db'])) echo 'l-menu__item--active' ?>"><a href="/list/server/?db"><?=__('DB')?></a></div>
</div>
<!-- /.l-menu -->
<div class="l-profile">
<a class="l-profile__username" href="/edit/user/?user=<?php echo $user; ?>"><?=$user?></a>
<a class="l-profile__logout" href="/logout/"> <?=__('Log out')?> </a>
</div>
<!-- /.l-profile -->
</div>
</div>
<!-- /.l-header -->
<div style="color: #ff6701; padding: 10px 0 20px 20px; background: #fff; ">.</div><div class="l-center">
<pre style="color: #555">