From: miker Date: Mon, 25 Jun 2007 20:22:34 +0000 (+0000) Subject: adding router commands to gather some stats about request counts X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2ef36222cfa304841828ab578ebb0e1c32a505ac;p=working%2FOpenSRF.git adding router commands to gather some stats about request counts git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@975 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/router/osrf_router.c b/src/router/osrf_router.c index 8308851..b7e7d60 100644 --- a/src/router/osrf_router.c +++ b/src/router/osrf_router.c @@ -6,6 +6,8 @@ #define ROUTER_REQUEST_CLASS_LIST "opensrf.router.info.class.list" +#define ROUTER_REQUEST_FULL_STATS "opensrf.router.info.stats.class.node.all" +#define ROUTER_REQUEST_CLASS_STATS "opensrf.router.info.stats.class.all" osrfRouter* osrfNewRouter( char* domain, char* name, @@ -555,6 +557,53 @@ int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* msg, osr osrfStringArrayFree(keys); + } else if(!strcmp( omsg->method_name, ROUTER_REQUEST_FULL_STATS )) { + + osrfRouterClass* class; + osrfRouterNode* node; + jresponse = jsonParseString("{}"); + + osrfHashIterator* class_itr = osrfNewHashIterator(router->classes); + while( (class = osrfHashIteratorNext(class_itr)) ) { + + jsonObject* class_res = jsonParseString("{}"); + char* classname = class_itr->current; + + osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes); + while( (node = osrfHashIteratorNext(node_itr)) ) { + jsonObjectSetKey( class_res, node->remoteId, jsonNewNumberObject( (double) node->count ) ); + } + osrfHashIteratorFree(node_itr); + + jsonObjectSetKey( jresponse, classname, class_res ); + } + + osrfHashIteratorFree(class_itr); + + } else if(!strcmp( omsg->method_name, ROUTER_REQUEST_CLASS_STATS )) { + + osrfRouterClass* class; + osrfRouterNode* node; + int count; + jresponse = jsonParseString("{}"); + + osrfHashIterator* class_itr = osrfNewHashIterator(router->classes); + while( (class = osrfHashIteratorNext(class_itr)) ) { + + count = 0; + char* classname = class_itr->current; + + osrfHashIterator* node_itr = osrfNewHashIterator(class->nodes); + while( (node = osrfHashIteratorNext(node_itr)) ) { + count += node->count; + } + osrfHashIteratorFree(node_itr); + + jsonObjectSetKey( jresponse, classname, jsonNewNumberObject( (double) count ) ); + } + + osrfHashIteratorFree(class_itr); + } else { return osrfRouterHandleMethodNFound( router, msg, omsg );