[Opensrf-commits] r975 - trunk/src/router

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Jun 25 16:25:04 EDT 2007


Author: miker
Date: 2007-06-25 16:22:34 -0400 (Mon, 25 Jun 2007)
New Revision: 975

Modified:
   trunk/src/router/osrf_router.c
Log:
adding router commands to gather some stats about request counts

Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c	2007-06-25 03:06:56 UTC (rev 974)
+++ trunk/src/router/osrf_router.c	2007-06-25 20:22:34 UTC (rev 975)
@@ -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 @@
 		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 );



More information about the opensrf-commits mailing list