Difference between revisions of "Ministat"

From James Dooley's Wiki
Jump to: navigation, search
(Usage)
(Usage)
Line 79: Line 79:
 
Direct download and execution of script (auto mode) from ent.int server:
 
Direct download and execution of script (auto mode) from ent.int server:
  
<code>[bash,n]wget http://scripts.ent.liquidweb.com/ministat -O ministat; watch -n 10 sh ministat; rm -f ministat</code>
+
<code>[bash,n]wget http://scripts.ent.liquidweb.com/ministat -O ministat; watch sh ministat; rm -f ministat</code>
  
 
Direct download and execution of script (auto mode) from this server:
 
Direct download and execution of script (auto mode) from this server:
  
<code>[bash,n]wget http://wiki.jamesdooley.us/scripts/ministat -O ministat; watch -n 10 sh ministat; rm -f ministat</code>
+
<code>[bash,n]wget http://wiki.jamesdooley.us/scripts/ministat -O ministat; watch sh ministat; rm -f ministat</code>
  
 
==What to change==
 
==What to change==

Revision as of 14:12, 13 January 2012

Overview

Down and dirty mini status viewer. Makes it easy to monitor several different sections of a server at the same time.

Useful for monitoring a server that is having problems.

The main concept is to minify the output of several sections in to a small terminal window, useful for monitoring a server when it is having problems or could at some point.

Auto adjusts output based on size of the terminal.

Script

[bash,n]

  1. !/bin/bash

function checkmysql { cmdmysql=`mysql --batch -e 'show processlist;' | grep -v "Id" | cut -f6,5,4,8 | sed -e 's/\t/ /g' | sort -nr --key=3 | sed -e 's/ /\|/' -e 's/ /\|/' -e 's/ /\|/' | awk 'BEGIN {FS="|"}; { printf "%-4s%-18s%-8s%-30s",$3,$1,$2,$4; print "" }'` if $cmdmysql != "" then wcmysql=`echo "$cmdmysql" | wc -l` else wcmysql=0 fi return } function checkapache { if [ -d "/var/cpanel" ] then cmdapache=`httpd status 2>&1 | sed -n '/requests\/sec/,/Scoreboard/p' | sed 'N;$!P;$!D;$d' | grep "requests/sec" -A 999` else cmdapache=`lynx --dump http://localhost/server-status 2>&1 | sed -n '/requests\/sec/,/Scoreboard/p' | sed 'N;$!P;$!D;$d' | grep "requests/sec" -A 999` fi if $cmdapache != "" then wcapache=`echo "$cmdapache" | wc -l` else wcapache=0 fi return } function calclines { nline=`tput lines | awk '{print int(($1 - 14) / 3)}'` aline=`echo $nline 3 | awk '{print $1 + $2}'` if [ $nline -gt $wcmysql ] then nline=`echo $nline $wcmysql | awk '{print $1 * 2 - $2}'` fi return } function addseperator { printf "%$(tput cols)s\n"|tr ' ' '=' return }

cat /proc/loadavg addseperator

checkmysql checkapache calclines

top -c -b -n 1 | grep -v "grep" | grep "PID" -A $nline addseperator

free | grep -v "cache:"

if [ $wcmysql -gt 0 ] then addseperator echo "$cmdmysql" | head -$nline fi if [ $wcapache -gt 0 ] then addseperator echo "$cmdapache" | head -$aline fi

Usage

Direct download and execution of script (auto mode) from ent.int server:

[bash,n]wget http://scripts.ent.liquidweb.com/ministat -O ministat; watch sh ministat; rm -f ministat

Direct download and execution of script (auto mode) from this server:

[bash,n]wget http://wiki.jamesdooley.us/scripts/ministat -O ministat; watch sh ministat; rm -f ministat

What to change