Re: api to query gkrellmd
| Newsgroups | gmane.comp.gnome.apps.gkrellm |
|---|---|
| Message-ID | <[email protected]> |
Hi, Many thanks, for your answer, i wrote a silly java program to interact with gkrellm daemon. Unfortunately, the answer sent by the server is not well xml defined. I show an output, of my java program: ------------------------------------------------------- Connected! Sending request... <gkrellmd_setup> <version> gkrellmd 2.2.10 <decimal_point> . <sensors_setup> <cpu_setup> n_cpus 1 <net_setup> net_use_routed <mail_setup> <hostname> reboot <sysname> Linux 2.6.11.4-20a-default <time> 57 12 18 13 10 106 1 316 0 <monitors> sensors cpu proc disk net inet mem fs mail battery uptime <io_timeout> 0 <reconnect_timeout> 0 </gkrellmd_setup> <initial_update> <cpu> 0 4336858 12335 385991 50061509 <proc> 127 3 9093 1.00 5 <disk> hda 2953901056 1182765056 hda1 hda 229376 0 hda2 hda 20188160 0 hda3 hda 6144 0 hda5 hda 19075072 188370944 hda6 hda 2909204480 688680960 hdc 0 0 hdd 0 0 md0 virtual 0 0 fd0 2048 0 <net> eth0 3461332694 244606681 lo 44258626 44258626 sit0 0 0 <net_routed> eth0 1 lo 1 <inet> +0 4056 207.46.109.30:747 +0 34a4 72.14.253.91:50 <mem> 1060528128 746110976 25604096 0 49442816 239370240 <swap> 1077469184 184082432 4603 45989 <fs_mounts> .clear / rootfs rootfs 2632558 604605 604605 4096 /lib/klibc/dev initramfsdevs tmpfs 12945 12266 12266 4096 / /dev/hda6 reiserfs 2632558 604605 604605 4096 /dev/shm tmpfs tmpfs 129459 129459 129459 4096 /windows/C /dev/hda2 ntfs 16623258 888834 888834 4096 /media/floppy /dev/fd0 subfs 0 0 0 0 <fs_fstab> .clear / /dev/hda6 reiserfs /windows/C /dev/hda2 ntfs /media/cdrecorder /dev/cdrecorder subfs /media/dvd /dev/dvd subfs /media/floppy /dev/fd0 subfs <uptime> 9141 <time> 57 12 18 13 10 106 1 316 0 </initial_update> ------------------------------------------------------------------ as you can see, many tags are opened but not closed (ie. uptime, time, cpu, and so on.) according to xml standards, besides, will be very useful provide the DTD file in order to gather information according to the structure defined in that file. However, i intend write a simple object that allows to connect a gkrellmd gather a machine status snapshot and keep it in an object, then the user can invoke the proper methods to get the information desired such as: cpu, mem, disk, and so on. regards. > > On Nov 13, 2006, at 11:28 AM, [email protected] wrote: > >> thanks for your answer, but can you more specific, i mean what exactly >> file to look, a little sample. >> > > I don't have a sample around, my code is Windows and I'm on a Mac > now. But here's a snippet from the code I have. Keep in mind this is > based on my memory and the last version of GKrellM I worked with a > few years ago. > > Create a socket on port 19150 (the default) > Send "gkrellm 1.1.1" (or whatever version of the client you want) to > the server > Then loop while running and check the socket for read data (you won't > ever need to write data again) > Parse up the data you receive according to the type of xml node > The data is only sent when a change occurs, so you won't receive full > data for every monitor on every tick. > Also Bill's xmlish format lacks the closing xml tag to lower bytes > transmitted. > > Here's some Windows specific code (which wasn't at 1.0 yet) that I > used to read & parse the data: > http://redbog.com/temp/gkrellmserver.txt > > To see how to parse the data, take a look at monitor.c in the server > folder from the latest gkrellm source. (for example the function > gkrellmd_serve_data which sets up the xml tag and then calls > functions like serve_cpu_data). > > Also you might want to start the server with the -V verbose option to > see what is being sent to the client. Helps with debugging. > > Thanks > Bill > > _______________________________________________ > Gkrellm mailing list > [email protected] > http://lists.jutley.org/cgi-bin/mailman/listinfo/gkrellm > (`'`'`'`'`) | | | | | | -----.. (()---- | | || (_ | | || | | | || | | | || /\ ..-- '--------'' /\ ||-'' \ / \ \ \// ,, \---. .---------. \./ |~| /__\ \ | ___|_________|__|""-.___ / || | | | | .-----' || | | | |CC.-----. | | | | '-----' | |-ABG | | _______________________________________________ Gkrellm mailing list [email protected] http://lists.jutley.org/cgi-bin/mailman/listinfo/gkrellm
D.java
(text/x-java, 1.2 KB)
import java.net.Socket;
//import java.io.ObjectOutputStream;
import java.io.PrintStream;
//import java.io.ObjectInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class D {
public static void main(String[] argv) throws Exception {
Socket s = new Socket("localhost",19150);
System.out.println("Connected!");
//ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
PrintStream ps = new PrintStream(s.getOutputStream(),true);
//oos.writeObject("gkrellm 2.2.2");
ps.println("gkrellm 2.2.10");
System.out.println("Sending request...");
//ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
//DataInputStream dis = new DataInputStream(s.getInputStream());
BufferedReader d = new BufferedReader(
new InputStreamReader(s.getInputStream()));
while (true) {
//System.out.println("Waiting for data...");
System.out.println(d.readLine());
}
}
}