Miscellaneous Code
  Home arrow Miscellaneous Code arrow RRD monitor page
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

RRD monitor page
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2003-03-06

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Already use MRTG's? Store data with RRD?
    Try these php pages to set threshold monitoring on usage statistics.

    By : bigphish

    devmon.php ->

    <?php

    /*
    * Program Name: Device List Creater
    * Date: March 6, 2003
    * Modified: March 6, 2003
    * Author: Jason Chambers
    * File Name: devmon.php
    * email: jason.chambers@phishie.net
    *
    * Description: This page will create the list of devices to monitor by
    * going through the directories where the rrd files are
    * stored.
    *
    */

    /* Set path to base directory (where subdirectories contain the rrd files) */
    $rrd_dir = "/var/www/html/mon/";

    /* Look inside $rrd_dir for the subdirectories */
    if (is_dir($rrd_dir)){
    $fd = @opendir($rrd_dir);
    if($fd) {
    while (($part = @readdir($fd)) == true) {
    if ($part != "." && $part != "..") {
    if (is_dir($part)){
    $my_dir[] = $part;
    }
    }
    }
    }
    }

    sort($my_dir); /* Sort the array of subdirectories */
    reset($my_dir); /* Reset the pointer to the beginning of the array */

    $content = ""; /* Initialize $content */
    $content .= "<html>\n<head>\n<title>Monitor device list</title>\n</head>\n\n<body>\n\n";
    $content .= "<form name=\"mylist\" action=\"new_mon_list.php\" method=\"POST\">\n";

    for($i=0;$i<count($my_dir);$i++){
    $node_dir = $rrd_dir . $my_dir[$i];
    $content .= "<h5> in directory $my_dir[$i] </h5>\n";
    $content .= "<table>\n";
    if ($handle = opendir("$node_dir")) {
    while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
    $content .= "\t<tr>\n\t\t<td><input type=\"checkbox\" name=\"mon_me[]\" value=\"$file\"><font size=\"-1\" color=\"cornflowerblue\">$file</font></td>\n\t</tr>\n";
    }
    }
    }
    $content .= "</table>\n";
    }

    $content .= "<table>\n";
    $content .= "<tr><td><input type=\"SUBMIT\"></td></tr>\n";
    $content .= "</table>\n";
    $content .= "</form>\n";
    $content .= "</body>\n";
    $content .= "</html>\n\n";

    print "$content";


    ?>

    !-----------------------
    new_mon_list.php ->

    <?php

    /*
    * This file takes the posted data from devmon.php
    * and writes to monlist.txt
    *
    * Your webserver needs to have write access
    * to this directory
    *
    */


    $to_file = "";

    foreach($_POST as $key => $nested)
    {

    for($i=0;$i<count($nested);$i++)
    {
    $to_file .= "$nested[$i]\n";
    }
    }

    $myFile = fopen("monlist.txt","w");
    fputs($myFile,"$to_file");
    fclose($myFile);

    header("Refresh: 5; URL=../index.php");
    print "<h4><i>The file \"monlist.txt\" has been created in this directory.</i></h4>";

    ?>

    !----------------------------------
    index.php ->

    <?

    /*
    * Program Name: RRD monitor script
    * Date: March 3, 2003
    * Modified: March 5, 2003
    * Author: Jason Chambers
    * File name: index.php
    * email:jason.chambers@phishie.net
    *
    */

    header("Refresh: 600"); /* Tell the browser to refresh every 10 minutes */

    $send_alert = ''; /* Send alerts when threshold is surpassed 'on'/'off' */
    $notify_who = ''; /* Set the email address of the person to notify */
    $mail_msg = 'Hello, '; /* Initialize $mail_msg */

    /* poll list file */
    $poll_list = '/home/rrdtool/poll/list';

    /* path to rrdtool */
    $path_rrdtool = '/usr/local/bin/';

    /* path to base directory (directory that contains the subdirectories/working directories) for your rrd files */
    $path_rrdbase_dir = '/var/www/html/mon/';

    $time_now = time(); /* Epoch Timestamp for "now" */
    $time_back = $time_now - 600; /* Timestamp for 10 minutes back from "now" */

    $th_high = 4; /* if interface traffic increase by this amount */
    $th_low = 3; /* if interface traffic decreases by this amount */
    $num_trouble = 0; /* initialize num_trouble variable to 0 (no troubles) */

    echo "<h3>" . date("l, F dS, Y h:i A") . "</h3>";

    print "<table border=1 align=\"center\">\n";
    print "\t<tr>\n";
    print "\t\t<th>device</th>\n";
    print "\t\t<th>interface</th>\n";
    print "\t\t<th>ALERT? IN</th>\n";
    print "\t\t<th>ALERT? OUT</th>\n";

    $handle = fopen($poll_list,"r");
    while (!feof($handle)) {
    $from_file = fgets($handle,256);
    $from_file = chop($from_file);
    if (!$from_file == ""){


    $node = preg_split('/_/',$from_file); /* $node[] is an array on the split line, '_' from the poll file */
    $path_rrdfiles = $path_rrdbase_dir . "$node[0]"; /* path to rrd files */

    /* rrdtool fetch for now and 15 minutes ago */
    $run_now = $path_rrdtool . "rrdtool fetch $path_rrdfiles/$from_file AVERAGE -r 900 -s $time_now -e $time_now";

    $my_data_now = shell_exec($run_now); /* Array with the results of the rrdtool fetch command */
    $data0_array = preg_split('/\n/',$my_data_now); /* Split the array on new line char */
    $now_data = preg_split('/ /',$data0_array[2]);; /* Split the new array on spaces */

    /* Get old data */
    $run_old = $path_rrdtool . "rrdtool fetch $path_rrdfiles/$from_file AVERAGE -r 900 -s $time_back -e $time_back";

    $my_data_old = shell_exec($run_old); /* Array with the results of the rrdtool fetch command */
    $data1_array = preg_split('/\n/',$my_data_old); /* Split the array on new line char */
    $old_data = preg_split('/ /',$data1_array[2]); /* split the new array on spaces */

    /* Setup traffic in/out info */
    $now_traf_in = $now_data[1] * 1;
    $now_traf_out = $now_data[2] * 1;
    $now_traf_in = number_format($now_traf_in,2,'.', '');
    $now_traf_out = number_format($now_traf_out,2,'.', '');

    $old_traf_in = $old_data[1] * 1;
    $old_traf_out = $old_data[2] * 1;
    $old_traf_in = number_format($old_traf_in,2,'.', '');
    $old_traf_out = number_format($old_traf_out,2,'.', '');

    /* Setup up alert levels */
    $alert_up_in = $old_traf_in * $th_high; /* if in traffic has doubled in the last 15 minutes */
    $alert_down_in = $old_traf_in / $th_low; /* if in traffic has decreased by half */
    $alert_up_out = $old_traf_out * $th_high; /* if out traffic has doubled in the last 15 minutes */
    $alert_down_out = $old_traf_out / $th_low; /* if out traffic has decreased by half */

    /* Check for an alert */

    if ($now_traf_in>$alert_up_in||$now_traf_in<$alert_down_in||$now_traf_in==0)
    {
    $in_bg_color = "red";
    $in_trouble = "yes";
    $num_trouble = $num_trouble + 1;
    $mail_msg .= "alert detected on $node[0] port $node[1] going IN. Please check traffic on $node[0] for issues.\n";
    }
    else
    {
    $in_bg_color = "green";
    $in_trouble = "no";
    }

    if ($now_traf_out>$alert_up_out||$now_traf_out<$alert_down_out||$now_traf_out==0)
    {
    $out_bg_color = "red";
    $out_trouble = "yes";
    $num_trouble = $num_trouble + 1;
    $mail_msg .= "alert detected on $node[0] port $node[1] going OUT. Please check traffic on $node[0] for issues.\n";
    }
    else
    {
    $out_bg_color = "green";
    $out_trouble = "no";
    }

    if ($in_trouble == "yes" || $out_trouble == "yes") {
    print "\t<tr>\n";
    print "\t\t<td>$node[0]</td>\n";
    print "\t\t<td>$node[1]</td>\n";
    print "\t\t<td bgcolor=\"$in_bg_color\" align=\"center\"><font color=\"white\"><strong>:: IN ::</strong></font></td>\n";
    print "\t\t<td bgcolor=\"$out_bg_color\" align=\"center\"><font color=\"white\"><strong>:: OUT ::</strong></font></td>\n";
    print "\t</tr>\n";
    }

    }

    }

    fclose($handle);

    /* No trouble? Cool, display no trouble message. */
    if ($num_trouble == 0){

    print "\t<tr>\n";
    print "\t\t<td colspan=4 align=\"center\"> <i>no current trouble</i></td>\n";
    print "\t</tr>\n";

    }

    /* Should we send the alert by email? */
    if ($num_trouble > 0 && $send_alert == "on") {
    mail("$notify_who","Alert detected while comparing interface usage.","$mail_msg\n Thanks.");
    }


    print "</table>\n";

    /* Credits */
    print "<table align=\"center\">\n\t<tr>\n\t\t<td><font size=\"-2\"><i>Created by <a href=\"mailto:jason.chambers@phishie.net\">Jason Chambers</a></i></font></td>\n\t</tr>\n</table>\n\n";

    ?>




    Click to Download File



    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! IBM Enterprise Modernization Sandbox for System z: Architecture

    Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server.
    FREE! Go There Now!


    NEW! IBM Rational AppScan Standard Edition V7.7

    Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 2: Automate builds for a real-world Tomcat project

    Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available.
    FREE! Go There Now!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started.
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Webcast: Calling All Testers! Find Application Vulnerabilities Early in the Development Process Where they are Easier to Fix and Less Risky to your Business

    In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek