SUPERMON

EXAMPLE CLIENTS

This page contains basic clients to illustrate how simple it is to read and process Supermon data in a variety of languages.

Common LISP

;;
;; Matt's Trivial CLISP supermon client
;;
;; Text based clisp client to read a single variable from a single mon
;; and print a 'bargraph' of the difference between samples. Currently
;; monitors cpuinfo user time, and if you turn your monitor it looks like
;; a gross, text only version of xload. It's only intended to demonstrate
;; how easy LISP is for prototyping supermon clients.
;;
;; It actually has more lines of comments than REAL CODE! Now how cool
;; is that!
;;
;; tweak the MONHOST line below to point at the host running MON
;; same with the MONPORT -- point it at the port MON is listening on.
;;
;; matt@lanl.gov
;;
;; mon host to monitor
(SETQ MONHOST '"127.0.0.1")
(SETQ MONPORT '2709)
;;
;; function to scan a mon S sample and return the expression containing
;; the sample data for a single category. This applies to a single node
;; sample.
;;
(defun getnodedata (category sample)
(if (equal NIL sample)
'unknown
(if (equal category (cadar sample)) (car (last (car sample)))
(getnodedata category (cdr sample)) )))
;; socket
(SETQ SOCK (SOCKET:SOCKET-CONNECT MONPORT MONHOST))
(PRINT "S\n" SOCK)
(SETf samp (READ SOCK))
(setf cur_cpuinfo (funcall #'getnodedata 'cpuinfo samp))
;; loop
(DO
((keepgoing 'T))
((equal keepgoing 'F) (return))
;; loop body
(PRINT "S\n" SOCK)
(SETf samp (READ SOCK))
(setf prev_cpuinfo cur_cpuinfo)
(setf cur_cpuinfo (funcall #'getnodedata 'cpuinfo samp))
(print (make-array (- (cadar cur_cpuinfo) (cadar prev_cpuinfo))
:element-type 'string-char :initial-element '#\*))
(sleep 0.5)
)

Ruby

require "Sexp"

C

#include <stdio.h>
#include "supermon_data.h"
int main(int argc, char **argv) {
smon_connection_t *conn = NULL;
smon_sample_t *samp = NULL;
double *ddata = NULL;
int i,j;
long *ldata = NULL;
conn = init_socket_sampler("localhost",2709); condition_sampler(conn);
get_smon_sample(conn);
samp = get_sample_data(conn,"sensor-w83627hf","temps");
if (samp == NULL) {
fprintf(stderr,"Crap.\n");
return 0;
}
fprintf(stderr,"Data sample:\n");
fprintf(stderr," NODES: %d\n",samp->numnodes);
fprintf(stderr," TYPE: %d\n",samp->datatype);
if (samp->datatype == SUPERMON_DOUBLE)
fprintf(stderr," (double)\n");
if (samp->datatype == SUPERMON_LONG)
fprintf(stderr," (long)\n");
for (i=0;i<samp->numnodes;i++) {
if (samp->datatype == SUPERMON_DOUBLE) ddata = (double *)samp->data[i];
if (samp->datatype == SUPERMON_LONG) ldata = (long *)samp->data[i];
fprintf(stderr," NODE %d (ID=%s) data: ",i,samp->nodeID[i]);
for (j=0;j<samp->arity[i];j++) {
if (samp->datatype == SUPERMON_DOUBLE)
fprintf(stderr,"%f ",ddata[j]);
if (samp->datatype == SUPERMON_LONG)
fprintf(stderr,"%d ",ldata[j]);
}
fprintf(stderr,"\n");
}
close_sampler(conn);
destroy_sampler(conn);
return 0;
}

 

Updated 08-13-2008