Browse code

counters: 2nd parameter of cnt.get rpc is now optional

If the counter name is missing cnt.get will display the whole
group (equivalent to cnt.grp_get_all).
E.g.:
$ sercmd cnt.get tcp
{
con_reset: 0
con_timeout: 0
connect_failed: 0
connect_success: 0
current_opened_connections: 0
current_write_queue_size: 0
established: 0
local_reject: 0
passive_open: 0
send_timeout: 0
sendq_full: 0
}

$ sercmd cnt.get tcp current_opened_connections
0

Andrei Pelinescu-Onciul authored on 10/08/2010 23:27:46
Showing 1 changed files
... ...
@@ -273,6 +273,10 @@ static int cnt_reset_f(struct sip_msg* msg, char* handle, char* bar)
273 273
 
274 274
 
275 275
 
276
+static void cnt_grp_get_all(rpc_t* rpc, void* c, char* group);
277
+
278
+
279
+
276 280
 static void cnt_get_rpc(rpc_t* rpc, void* c)
277 281
 {
278 282
 	char* group;
... ...
@@ -280,10 +284,11 @@ static void cnt_get_rpc(rpc_t* rpc, void* c)
280 284
 	counter_val_t v;
281 285
 	counter_handle_t h;
282 286
 	
283
-	if (rpc->scan(c, "ss", &group, &name) < 2) {
284
-		/* rpc->fault(c, 400, "group and counter name required"); */
287
+	if (rpc->scan(c, "s", &group) < 1)
285 288
 		return;
286
-	}
289
+	if (rpc->scan(c, "*s", &name) < 1)
290
+		return cnt_grp_get_all(rpc, c, group);
291
+	/* group & name read */
287 292
 	if (counter_lookup(&h, group, name) < 0) {
288 293
 		rpc->fault(c, 400, "non-existent counter %s.%s\n", group, name);
289 294
 		return;
... ...
@@ -400,16 +405,11 @@ static void cnt_var_list_rpc(rpc_t* rpc, void* c)
400 405
 
401 406
 
402 407
 
403
-static void cnt_grp_get_all_rpc(rpc_t* rpc, void* c)
408
+static void cnt_grp_get_all(rpc_t* rpc, void* c, char* group)
404 409
 {
405 410
 	void* s;
406
-	char* group;
407 411
 	struct rpc_list_params packed_params;
408 412
 	
409
-	if (rpc->scan(c, "s", &group) < 1) {
410
-		/* rpc->fault(c, 400, "group name required"); */
411
-		return;
412
-	}
413 413
 	if (rpc->add(c, "{", &s) < 0) return;
414 414
 	packed_params.rpc = rpc;
415 415
 	packed_params.ctx = s;
... ...
@@ -418,6 +418,19 @@ static void cnt_grp_get_all_rpc(rpc_t* rpc, void* c)
418 418
 
419 419
 
420 420
 
421
+static void cnt_grp_get_all_rpc(rpc_t* rpc, void* c)
422
+{
423
+	char* group;
424
+	
425
+	if (rpc->scan(c, "s", &group) < 1) {
426
+		/* rpc->fault(c, 400, "group name required"); */
427
+		return;
428
+	}
429
+	return cnt_grp_get_all(rpc, c, group);
430
+}
431
+
432
+
433
+
421 434
 static void cnt_help_rpc(rpc_t* rpc, void* ctx)
422 435
 {
423 436
 	char* group;