• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Monitoring Web Services

 
Venkatesh Varadan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wanted to write a small application that would help me monitor webservices in general. The requirement being that it should monitor the server on which the service is deployed. One simple requirement would be to monitor the number of times my webservice would be called.

I am completely new to writing administration/monitoring applications and I would appreciate any help on this! Any links to tutorials to do the same would be great!

Thanking you guys for your time!
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Axis somes with two monoring applications, TCPMon (which is a GUI application running on the client) and SOAPMonitor, which is a JAX-RPC handler running inside the WS engine with a monitoring applet. Most likely, neither does precisely what you're looking for, but studying their source code might give you ideas for your own monitor.
 
Venkatesh Varadan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks will see where this leads me...

appriciate your time
 
venkat reddyk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will help you to Monitor the client calls

Compile this java file and run it from the same directory (it does not have a package assigned to it)

usage:java LEAK <-f foldername> localPort RemoteHost RemotePort

since you are running your webservice at 8080 run this on any other port (say 8088)
in which case you would run it like this
java LEAK 8088 192.168.1.33 8080

and at the client, instead of connecting-to the webservice .. connect to LEAK at port 8088.
you should be able to see the strings traveling in between the client and the server.


Here is the code for LEAK class

import java.io.*;
import java.net.*;

public class LEAK{

private ServerSocket ssocket = null;
private int port;
private String destIP;
private int destPort;
private boolean writeToFile;
private String foldername;

protected LEAK(int port,String destIP,int destPort,boolean writeToFile,String foldername) throws IOException
{
this.port = port;
this.destIP = destIP;
this.destPort = destPort;
this.writeToFile = writeToFile;
this.foldername = foldername;

try{
Socket dummySocket = new Socket(destIP,destPort);
OutputStream os = dummySocket.getOutputStream();
os.write(0);
}catch(IOException i){
System.out.println("Destination server not reachable");
System.exit(1);
}
ssocket = new ServerSocket(port);
run();
}

public void run()
{
Socket destClient;
System.out.println(" \t\tLEAK : Server socket Created at " + ssocket.getLocalPort());
int count = 0 ;
while(true){
count++;
try {
System.out.println("WAITING");
destClient = ssocket.accept();
System.out.println("\t\tLEAK : Request got from " + destClient.getInetAddress().getHostName());
System.out.println("\n\n\t\tLEAK :R E Q U E S T NO: "+count);
} catch (IOException e) {

System.out.println("\t\tLEAK : Class Server died: " + e.getMessage());
e.printStackTrace();
return;
}
try {

Socket destServer=new Socket(destIP,destPort);
PrintStream requestOut = null;
PrintStream responseOut = null;
if(writeToFile){
File f = new File(foldername);
f.mkdir();
//requestOut = new PrintStream(new FileOutputStream("LEAK_DIR/REQUEST_CYCLE_"+count));
//responseOut = new PrintStream(new FileOutputStream("LEAK_DIR/RESPONSE_CYCLE_"+count));
requestOut = new PrintStream(new FileOutputStream(f.getAbsolutePath()+"/REQUEST_CYCLE_"+count));
responseOut = new PrintStream(new FileOutputStream(f.getAbsolutePath()+"/RESPONSE_CYCLE_"+count));
}else{
requestOut = responseOut = System.out;
}
leak(destClient,destServer, requestOut,responseOut);

System.out.println(" \n\t\t\tLEAK : DONE REQUEST NO: "+count);
} catch (Exception e) {
// write out error response
}
}
}

public static void main(String[] args){
try{
int selfPort = 0;
String destinationServerIP = null;
int destinationServerPort = 0;
int argsCount = 0;
boolean writeToFile = false;
String foldername = null;

if(args.length != 3 && args.length != 5){
System.out.println("\tusage:java LEAK <-f foldername> localPort RemoteHost RemotePort");
System.exit(0);
}


if(args.length == 5){
String writeToFileString = args[argsCount++];
if(writeToFileString.equals("-f")){
foldername = args[argsCount++];
writeToFile = true;
}else{
System.out.println("\tusage:java LEAK <-f foldername> localPort RemoteHost RemotePort");
System.exit(0);
}
}

try{
selfPort = Integer.parseInt(args[argsCount++]);
if(selfPort > 65535 || selfPort < 1024){
System.out.println("Self Port not in range <1024 - 65535>");
System.exit(0);
}
}catch(NumberFormatException nfe){
System.out.println("Self Port should be a number in the range 1024 - 65535");
System.exit(0);

}
destinationServerIP = args[argsCount++];
try{
destinationServerPort = Integer.parseInt(args[argsCount++]);
if(destinationServerPort > 65535){
System.out.println("Destination Port not in range");
System.exit(0);
}
}catch(NumberFormatException nfe){
System.out.println("Destination Port should be a number in the range 1 - 65535");
System.exit(0);

}
System.out.println("\n\n\t\t************** L E A K **************");
System.out.println("\t\tLEAK : selfPort : " + selfPort);
System.out.println("\t\tLEAK : destinationServerIP : " +destinationServerIP);
System.out.println("\t\tLEAK : destinationServerPort : " +destinationServerPort);
LEAK test=new LEAK(selfPort,destinationServerIP,destinationServerPort,writeToFile,foldername);
}catch(Throwable t){t.printStackTrace();}
}




private void leak(Socket client,Socket server,PrintStream requestOut,PrintStream responseOut)
throws IOException
{
closed=false;
Thread request= new Thread(new Request(client,server,requestOut));
request.start();
System.out.println("\t\t LEAK : Request started");

Thread response= new Thread(new Response(client,server,responseOut));
//response.start(); // COMMENTED OUT TO BLOCK TILL COMLEATION
System.out.println("\t\t LEAK : Response started");
response.run();
}

boolean closed;
Object closingLockRequest = new Object();
Object closingLockResponse = new Object();

public void close(Socket destClient,Socket destServer){
if(!closed){
System.out.println("\t\tLEAK : closing");
try{

destClient.close();
destServer.close();
closed = true;
}catch(Throwable t){
System.out.println("\t\t LEAK : not able to close");
}
System.out.println("\t\tLEAK : closed");
}
}

class Request implements Runnable{
Socket client;
Socket server;
PrintStream out;

Request(Socket client,Socket server,PrintStream out){
this.client=client;
this.server=server;
this.out = out;
}
public void run(){
try{
PrintStream requestOut = new PrintStream(new FileOutputStream(new File("RequestInts")));
InputStream cis=client.getInputStream();
OutputStream sos=server.getOutputStream();
int temp=0;
int i1=0;
while(temp != -1){
i1++;


temp = cis.read();
requestOut.print(temp+" ");
//Character cc = new Character((char)temp);
//if(cc.toString().equalsIgnoreCase("?")){
if(temp >127){
out.print(temp+" ");
}
else{
out.print((char)temp);
}
sos.write(temp);
sos.flush();
}
}catch(Throwable t){
}
close(client,server);
}
}

class Response implements Runnable{
Socket client;
Socket server;
PrintStream out;
Response(Socket client,Socket server,PrintStream out){
this.client=client;
this.server=server;
this.out = out;
}
public void run(){
try{
PrintStream requestOut = new PrintStream(new FileOutputStream(new File("ResponseInts")));
InputStream sis=server.getInputStream();
OutputStream cos=client.getOutputStream();
int temp=0;
int i1 = 0;
while(temp != -1){
i1++;
temp = sis.read();
requestOut.print(temp+" ");
//Character cc = new Character((char)temp);
//if(cc.toString().equalsIgnoreCase("?")){
if(temp >127){
out.print(temp+" ");
}
else{
out.print((char)temp);
}
cos.write(temp);
cos.flush();
}
}catch(Throwable t){
}
close(client,server);
}
}
}

[ October 30, 2006: Message edited by: venkat reddyk ]
[ October 30, 2006: Message edited by: venkat reddyk ]
 
Venkatesh Varadan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your time ...
I really appreciate it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic