Processing mod_status Visualization

Code and more after the break!

The Video shows the Output from a Apache Webserver with mod_status enabled.

Raw it llooks like that:

So the Processing script converts the "Scoreboard" into a nice stream of pictures {#emotions_dlg.smile}

The Code:

/**
 * Server - Status.
 * 
 * Draws a rectangle matrix with the data from a Apache Webserver.
 * It shows whats happening on the server in a way the human can understand it. 
 * And saves a series of pictures. Use VirtualDub for Assembly of the Video!
 *
 */

String sWebServer = "http://apache.org/server-status?auto";

int iSBlenght = 1250;   //how many Workers should be shown? (x10!)
int iSize = 10;         //how many Pixels should a worker be?

/*
 DO NO EDIT BELOW HERE!
*/

import processing.video.*;

//MovieMaker mm;  // Declare MovieMaker object


int iCorner = 0;
char sCurrW;
char[] aSBcontent = new char[100000];

boolean debug = false;

void FetchArray() {
  String lines[] = loadStrings(sWebServer);
  if(debug==true){
    println("there are " + lines.length + " lines");
    for (int i=0; i < lines.length; i++) {
      println(lines[i]);
    }
  }
  //Line 10 is the interesting one:
  if(lines != null){
    if(lines.length == 10){
      String Scoreboard = lines[9];
      Scoreboard = Scoreboard.substring(11,Scoreboard.length());  
      if(debug==true){
      println(Scoreboard);
      println(Scoreboard.length());
      }
      int iSizeFetch;
      if (Scoreboard.length() > iSBlenght){
        iSizeFetch = iSBlenght;
      }
      else {
        iSizeFetch = Scoreboard.length();
      } 
      if(iSizeFetch > 1){
        for (int i=0;i < iSizeFetch; i++){
          aSBcontent[i] = Scoreboard.charAt(i);
          if(debug==true){
          print(aSBcontent[i]);
          }
        }
      }
    }
  }
  //End!
}

void setup() {
  
  //define the size:
  iCorner = ceil(sqrt(iSBlenght))*iSize; 
  size(iCorner+2, iCorner+2,P3D);
  background(102);
  stroke(125, 125, 125);
  fill(0, 102);
  
  FetchArray(); //now in aSBcontent is the array inside! 
  
} void draw() {      FetchArray();   //now run X/Y:   for(int Y = 1; Y < iCorner; Y+=iSize){     for(int X = 1; X < iCorner; X+=iSize){      //a little switch case for the colours:      sCurrW = aSBcontent[(X/iSize+1)+Y/iSize*(iCorner/iSize)];      switch(sCurrW){        case '.': //open slot          fill(color(0, 0, 0));          rect(X,Y,iSize,iSize);          break;        case 'W': //sending reply          fill(color(255, 255, 255));          rect(X,Y,iSize,iSize);          break;        case 'S': //starting up          fill(color(0, 0, 0));          rect(X,Y,iSize,iSize);          break;        case 'R': //reading request          fill(color(255, 0, 0));          rect(X,Y,iSize,iSize);          break;        case 'K': //keepalive          fill(color(255, 255, 0));          rect(X,Y,iSize,iSize);          break;        case '_': //waiting          fill(color(0, 255, 0));          rect(X,Y,iSize,iSize);          break;        case 'D': //DNS Lookup          fill(color(255, 0, 0));          rect(X,Y,iSize,iSize);          break;        case 'C': //closing connection          fill(color(0, 0, 255));          rect(X,Y,iSize,iSize);          break;        case 'L': //Logging          fill(color(255, 0, 0));          rect(X,Y,iSize,iSize);          break;        case 'I': //Idle cleanup          fill(color(255, 0, 255));          rect(X,Y,iSize,iSize);          break;        case 'G': //Gracefull finish          fill(color(0, 255, 255));          rect(X,Y,iSize,iSize);          break;        default:          fill(color(0, 0, 0));          rect(X,Y,iSize,iSize);          break;      }     }   }       //And overlay the current time:      PFont font; font = loadFont("Arial-Black-28.vlw"); textFont(font); fill(255, 255, 255);   int h = hour(); // Values from 1 - 31   int m = minute(); // Values from 1 - 12   int se = second(); // 2003, 2004, 2005, etc.   String s = String.valueOf(h);   if (s.length() == 1){     s = '0' + s;   }   text(s, 20, iCorner-20);   s = String.valueOf(m);   if (s.length() == 1){     s = '0' + s;   }   text(s, 70, iCorner-20);   s = String.valueOf(se);   if (s.length() == 1){     s = '0' + s;   }   text(s, 120, iCorner-20); saveFrame("/backup/line-####.png");     delay(2000);   } void keyPressed() {     exit(); }

Comments powered by CComment