NetAdminTools.com
 
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Live Graph of Apache Processes - Part 3 - Counting and Displaying
Topic: Monitoring   Posted:2006-02-14
Printer Friendly: Print

spacerspacer
There are 3 parts to this article:
Part 1 - Part 2 - Part 3

In this article we introduced this graph and showed how it looks live, and in this article we created the scale. Finally, we will get to the part that creates the blue bars that comprise the graph. Here is the Perl script:

open (HTTPDFIG, ">> /path/to/httpd.fig");
open (COUNTHTTPD, "ps -C httpd h | wc -l |");
($sec,$min,$hour,$mday,$mon,$year,$wday,
$yday,$isdst)=localtime(time);
while (){
print HTTPDFIG " 2 1 0 5 1 7 50 -1 -1 0.000 0 0 -1 0 0 2\n";
print HTTPDFIG ($min+$hour*60)*45;
print HTTPDFIG " ";
print HTTPDFIG 22500-$_*450;
print HTTPDFIG " ";
print HTTPDFIG ($min+$hour*60)*45;
print HTTPDFIG " ";
print HTTPDFIG " 22500\n";
}
close COUNTHTTPD;
close HTTPDFIG;
system "/usr/bin/fig2dev -L png -m .2 /path/to/httpd.fig /path/to/httpd.png";
system "/usr/bin/fig2dev -L png -m .1 /path/to/httpd.fig /path/to/httpdsm.png";

First off, we open the fig file to write. We use the >> operator so that the new line is written at the end of the file. We use a pipe command and loop to read the number of httpd processes. For the blue bar/line, we use the time of the day in minutes since midnight to determine the x coordinates, and we simply multiply the number of processes ($_) times 450 to locate the end of the y coordinate on the graph. The fig2dev commands are the ones that convert the fig file to a png file. We have two so that we can display different sizes. The size is determined by the -m option. For more details on Xfig and the fig2dev command, see Xfig.org. Stick this command in your crontab to run every minute:

* * * * * /usr/bin/perl /path/to/hcount.pl > /dev/null 2>&1

One cool thing about this is that there is no extra process running all of the time to create this graph. Cron is always running (at least on our Red Hat system by default), so there really isn't much overhead here. There is a bit of a spike in usage when fig2dev renders the graphic, but it really isn't that noticeable to us.

There are 3 parts to this article:
Part 1 - Part 2 - Part 3




Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com