-D_GNU_SOURCE
LDFLAGS:=-L${stagedir}/lib
-JP_LIBS:=-lglite_jp_common -lglite_jp_trio
-TEST_LIBS:=-L${cppunit}/lib -lcppunit
-TEST_INC:=-I${cppunit}/include
-
COMPILE:=libtool --mode=compile ${CC} ${CFLAGS}
LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/lib ${LDFLAGS}
SOLINK:=libtool --mode=link ${CC} -module ${LDFLAGS} -rpath ${stagedir}/lib
expatlib := -L${expat_prefix}/lib
endif
-vomsflavour := _${nothrflavour}
-ifeq (${nothrflavour},gcc32)
- vomsflavour :=
-endif
-ifeq (${nothrflavour},gcc32dbg)
- vomsflavour :=
-endif
-
EXT_LIBS:= \
${mysqlib} -lmysqlclient -lz\
${expatlib} -lexpat \
${GRIDSITE_LIBS} \
${GLOBUS_LIBS}
+COMMON_LIB:=-lglite_lb_common_${nothrflavour}
+CLIENT_LIB:=-lglite_lb_client_${nothrflavour}
+BKSERVER_LIB:=-lglite_lb_bkserver
+JP_LIBS:=-lglite_jp_common -lglite_jp_trio
-STATISTICS_OBJS:=lb_statistics.o
+UTILS:=statistics mon mon-db
-default all: compile
+default: all
-compile: glite-lb-statistics
+compile all: ${UTILS}
-glite-lb-statistics: ${STATISTICS_OBJS}
- ${LINK} -rdynamic -o $@ ${STATISTICS_OBJS} ${JP_LIBS} ${EXT_LIBS} ${GLOBUS_LIBS}
+%.o: %.c
+ ${CC} ${CFLAGS} ${GLOBUSINC} -c $<
-check: compile
+mon: mon.o
+ ${LINK} -o $@ $< ${COMMON_LIB} ${CLIENT_LIB} ${EXT_LIBS}
+
+mon-db: mon-db.o
+ ${LINK} -o $@ $< ${COMMON_LIB} ${BKSERVER_LIB} ${EXT_LIBS}
-test_coverage:
- -mkdir coverage
- cd coverage && $(MAKE) -f ../Makefile top_srcdir=../../ COVERAGE_FLAGS="-fprofile-arcs -ftest-coverage" check
- cd coverage && for i in `echo ${INDEX_OBJS} ${BKSERVER_OBJS} | tr ' ' '\012' | sort -u`; do gcov $$i ; done
+statistics: statistics.o
+ ${LINK} -rdynamic -o $@ $< ${JP_LIBS} ${EXT_LIBS}
+
+check: compile
doc:
-mkdir -p ${PREFIX}/bin
-mkdir -p ${PREFIX}/share/doc/${package}-${version}
-mkdir -p ${PREFIX}/lib
- ${INSTALL} -m 755 glite-lb-statistics ${PREFIX}/bin
${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version}
+ for p in ${UTILS} ; do \
+ ${INSTALL} -m 755 "$$p" "${PREFIX}/bin/glite-lb-$$p"; \
+ done
+
if [ x${DOSTAGE} != xyes ]; then \
${INSTALL} -m 755 ${stagedir}/lib/glite_lb_plugin.so ${PREFIX}/lib; \
fi
Revision history:
$Log$
+ Revision 1.2 2005/10/15 00:59:34 jpospi
+ Added LB Statistics
+
Revision 1.1.1.1 2005/09/30 15:17:04 jpospi
New org.glite.lb.utils component
========================================= -->
<property name="build.package.summary" value="L&B utils" />
- <property name="build.package.description" value="L&B Statistics tool." />
+ <property name="build.package.description" value="L&B Statistics and L&B Monitoring utilities." />
</project>
--- /dev/null
+#ident "$Header$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sysexits.h>
+#include <assert.h>
+
+#include "glite/wmsutils/jobid/strmd5.h"
+#include "glite/lb/consumer.h"
+#include "glite/lb/context-int.h"
+#include "glite/lb/lbs_db.h"
+#include "glite/lb/jobstat.h"
+
+static struct option opts[] = {
+ { "mysql",1,NULL,'m' },
+ { "verbose",0,NULL,'v' },
+ { NULL, 0, NULL, 0 }
+};
+
+static void usage();
+static void do_exit(edg_wll_Context,int);
+static const char *me;
+
+int main(int argc,char **argv)
+{
+ int opt;
+ char *dbstring = getenv("LBDB");
+ int verbose = 0, rows = 0, fields = 0, jobs = 0, i;
+ edg_wll_Context ctx;
+ char *stmt = NULL, *status = NULL;
+ char *str[2];
+ edg_wll_Stmt sh;
+
+ me = strdup(argv[0]);
+
+ while ((opt = getopt_long(argc,argv,"m:v",opts,NULL)) != EOF) switch (opt) {
+ case 'm': dbstring = optarg; break;
+ case 'v': verbose++; break;
+ case '?': usage(); exit(EX_USAGE);
+ }
+
+ edg_wll_InitContext(&ctx);
+ if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
+ if (edg_wll_DBCheckVersion(ctx)) do_exit(ctx,EX_SOFTWARE);
+ if (asprintf(&stmt,"SELECT status,count(status) FROM states GROUP BY status;") < 0) do_exit(ctx,EX_OSERR);
+ if (verbose) fprintf(stderr,"mysql query: %s\n",stmt);
+ if ((rows = edg_wll_ExecStmt(ctx,stmt,&sh)) < 0) do_exit(ctx,EX_SOFTWARE);
+ if (verbose) fprintf(stderr,"number of states returned: %d\n",rows);
+ if (rows > 0) fprintf(stdout,"Number of jobs in each state: \n");
+ for (i = 0; i < rows; i++) {
+ fields = edg_wll_FetchRow(sh, str);
+ if (fields != 2) {
+ edg_wll_FreeStmt(&sh);
+ do_exit(ctx,EX_SOFTWARE);
+ }
+ status = edg_wll_StatToString((edg_wll_JobStatCode) atoi(str[0]));
+ jobs += atoi(str[1]);
+ fprintf(stdout,"%s: %s\n",status,str[1]);
+ if (str[0]) free(str[0]);
+ if (str[1]) free(str[1]);
+ if (status) free(status);
+ }
+ fprintf(stdout,"Total number of jobs: %d\n",jobs);
+
+ if (stmt) free(stmt);
+ edg_wll_FreeStmt(&sh);
+ edg_wll_FreeContext(ctx);
+
+ return 0;
+}
+
+static void do_exit(edg_wll_Context ctx,int code)
+{
+ char *et,*ed;
+
+ edg_wll_Error(ctx,&et,&ed);
+ fprintf(stderr,"%s: %s (%s)\n",me,et,ed);
+ exit(code);
+}
+
+static void usage()
+{
+ fprintf(stderr,"usage: %s <options>\n"
+ " -m,--mysql <dbstring> use non-default database connection\n"
+ " -v,--verbose be verbose\n",
+ me);
+}
--- /dev/null
+#ident "$Header$"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <getopt.h>
+#include <time.h>
+
+#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 state[3] = { EDG_WLL_JOB_CLEARED, EDG_WLL_JOB_ABORTED, EDG_WLL_JOB_CANCELLED };
+
+ int i, j, result, opt, nJobs;
+ result = opt = 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);
+ }
+ }
+ gettimeofday(&time_now,0);
+
+ if ( edg_wll_InitContext(&ctx) ) {
+ fprintf(stderr,"%s: cannot initialize edg_wll_Context\n ",myname);
+ exit(1);
+ }
+
+ for ( j = 0; j < sizeof(state)/sizeof(state[0]); j++) {
+ char *status = edg_wll_StatToString(state[j]);
+ nJobs = 0;
+
+ fprintf(stdout,"Jobs that entered state %s in the last hour: \n",status);
+
+ if ( (result = query_all(ctx, state[j], time_now, &statesOut, &jobsOut)) ) {
+ dgerr(ctx, "edg_wll_QueryJobs");
+ } else {
+
+ 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);
+ }
+
+ }
+ fprintf(stdout,"number of jobs: %d\n",nJobs);
+ fprintf(stdout,"minimum time spent in the system: %d\n",nJobs);
+ fprintf(stdout,"average time spent in the system: %d\n",nJobs);
+ fprintf(stdout,"maximum time spent in the system: %d\n",nJobs);
+ fprintf(stdout,"\n\n");
+
+ if (status) free(status);
+
+ }
+ 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);
+}