From 25a762a07890b05d7bf7f35a85b6ab4f2001cb90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Posp=C3=AD=C5=A1il?= Date: Mon, 20 Feb 2006 10:37:17 +0000 Subject: [PATCH] First attempt to lb monitoring --- org.glite.lb.client/Makefile | 4 +- org.glite.lb.client/examples/lbmon.c | 137 +++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 org.glite.lb.client/examples/lbmon.c diff --git a/org.glite.lb.client/Makefile b/org.glite.lb.client/Makefile index 76ba6b2..12f1219 100644 --- a/org.glite.lb.client/Makefile +++ b/org.glite.lb.client/Makefile @@ -140,7 +140,7 @@ PLUSLIB:=libglite_lb_clientpp_${nothrflavour}.la THRPLUSLIB:=libglite_lb_clientpp_${thrflavour}.la TOOLS:=dump load purge lb_dump_exporter -EXAMPLES:=log_usertag_proxy job_log job_reg feed_shark notify query_ext query_seq_code stats abort_job change_acl +EXAMPLES:=log_usertag_proxy job_log job_reg feed_shark notify query_ext query_seq_code stats abort_job change_acl lbmon EXAMPLES_CL=user_jobs job_status FAKE_EXAMPLES:=job_log_fake @@ -241,7 +241,7 @@ ${MAN_GZ}: ${MAN} default: all -compile all: check_version ${LIB} ${THRLIB} ${TOOLS} logevent ${PLUSLIB} ${THRPLUSLIB} examples ${MAN_GZ} +compile all: ${LIB} ${THRLIB} ${TOOLS} logevent ${PLUSLIB} ${THRPLUSLIB} examples ${MAN_GZ} examples: ${EXAMPLES} ${EXAMPLES_CL} ${sh_PROGS} diff --git a/org.glite.lb.client/examples/lbmon.c b/org.glite.lb.client/examples/lbmon.c new file mode 100644 index 0000000..2d466b9 --- /dev/null +++ b/org.glite.lb.client/examples/lbmon.c @@ -0,0 +1,137 @@ +#ident "$Header$" + +#include +#include +#include +#include +#include +#include + +#include "glite/lb/consumer.h" + +static void usage(char *); +static int query_all(edg_wll_Context, int, struct timeval, edg_wll_JobStat **, edg_wlc_JobId **); +static void dgerr(edg_wll_Context,char *); + +static char *myname = NULL; +static int debug = 0, verbose = 0, lbproxy =0; +static const char rcsid[] = "@(#)$Id$"; + +static struct option const long_options[] = { + { "help", no_argument, 0, 'h' }, + { "version", no_argument, 0, 'V' }, + { "verbose", no_argument, 0, 'v' }, + { "debug", no_argument, 0, 'd' }, + { "lbproxy", required_argument, 0, 'x' }, + { NULL, 0, NULL, 0} +}; + +int main(int argc,char *argv[]) { + edg_wll_Context ctx; + edg_wll_JobStat *statesOut = NULL; + edg_wlc_JobId *jobsOut = NULL; + struct timeval time_now; + + int i, result, opt, nJobs; + i = result = opt = 0; + gettimeofday(&time_now,0); + + myname = argv[0]; + fprintf(stdout,"\n"); + /* get arguments */ + while ((opt = getopt_long(argc,argv, + "h" /* help */ + "V" /* version */ + "v" /* verbose */ + "d" /* debug */ + "x", /* lbproxy */ + long_options, (int *) 0)) != EOF) { + + switch (opt) { + case 'V': fprintf(stdout,"%s:\t%s\n",argv[0],rcsid); exit(0); + case 'v': verbose = 1; break; + case 'd': debug = 1; break; + case 'x': lbproxy = 1; break; + case 'h': + default: + usage(argv[0]); exit(0); + } + } + if ( edg_wll_InitContext(&ctx) ) { + fprintf(stderr,"%s: cannot initialize edg_wll_Context\n ",myname); + exit(1); + } + + if ( (result = query_all(ctx, EDG_WLL_JOB_CLEARED, time_now, &statesOut, &jobsOut)) ) { + dgerr(ctx, "edg_wll_QueryJobs"); + } else { + fprintf(stdout,"Number of jobs... "); + } + + nJobs = 0; + if ( jobsOut ) { + for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); { + nJobs++; + free(jobsOut); + } + } + if ( statesOut ) { + for (i=0; statesOut[i].state; i++) edg_wll_FreeStatus(&statesOut[i]); + free(statesOut); + } + edg_wll_FreeContext(ctx); + + + return result; +} + +static void +usage(char *name) { + fprintf(stderr,"Usage: %s [-x]\n", name); +} + +static int +query_all(edg_wll_Context ctx, int query_status, struct timeval query_time, edg_wll_JobStat **statesOut, edg_wlc_JobId **jobsOut) { + edg_wll_QueryRec jc[3]; + int ret; + + memset(jc, 0, sizeof jc); + + /* jobs in the state 'query_status' within last hour */ + jc[0].attr = EDG_WLL_QUERY_ATTR_STATUS; + jc[0].op = EDG_WLL_QUERY_OP_EQUAL; + jc[0].value.i = query_status; + jc[1].attr = EDG_WLL_QUERY_ATTR_TIME; + jc[1].attr_id.state = query_status; + jc[1].op = EDG_WLL_QUERY_OP_WITHIN; + jc[1].value.t.tv_sec = query_time.tv_sec - 3600; + jc[1].value.t.tv_usec = query_time.tv_usec; + jc[1].value2.t.tv_sec = query_time.tv_sec; + jc[1].value2.t.tv_usec = query_time.tv_usec; + jc[2].attr = EDG_WLL_QUERY_ATTR_UNDEF; + + if ( (ret = edg_wll_QueryJobs(ctx, jc, 0, jobsOut, statesOut)) ) { + if ( ret == E2BIG ) { + int r; + if ( edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, &r) ) return ret; + if ( r != EDG_WLL_QUERYRES_LIMITED ) return ret; + + fprintf(stderr," edg_wll_QueryJobs() Warning: only limited result returned!\n"); + return 0; + } else return ret; + } + + return ret; +} + +static void +dgerr(edg_wll_Context ctx,char *where) { + char *etxt,*edsc; + + edg_wll_Error(ctx,&etxt,&edsc); + fprintf(stderr,"%s: %s: %s",myname,where,etxt); + if (edsc) fprintf(stderr," (%s)",edsc); + putc('\n',stderr); + if(etxt) free(etxt); + if(edsc) free(edsc); +} -- 1.8.2.3