static int cnt_int_fixup(void** param, int param_no) { char* name; char* grp; char* p; counter_handle_t h; if (param_no == 1) { name = (char*)*param; grp = cnt_script_grp; /* default group */ if ((p = strchr(name, '.')) != 0) { /* found group */ grp = name; name = p+1; *p = 0; } if (counter_lookup(&h, grp, name) < 0) { ERR("counter %s.%s does not exist (forgot to define it?)\n", grp, name); return -1; } *param = (void*)(long)h.id; } else return fixup_var_int_2(param, param_no); return 0; }
int counter_read(uint64_t ref_id, uint64_t *pval) { counter_t *cntr = counter_lookup(ref_id); if (cntr == 0) return -NOT_FOUND; *pval = cntr->value; return 0; }
int counter_increment(uint64_t ref_id, uint64_t incr) { counter_t *cntr = counter_lookup(ref_id); if (cntr == 0) return -NOT_FOUND; cntr->value += incr; cntr->value &= cntr->mask; return 0; }
int counter_remove(uint64_t ref_id) { counter_t *cntr = counter_lookup(ref_id); if (cntr == 0) return -NOT_FOUND; memmove(cntr, cntr +1, (void *)(all_counters +nr_counters -1) -(void *)cntr); nr_counters--; return 0; }
static void cnt_reset_rpc(rpc_t* rpc, void* c) { char* group; char* name; counter_handle_t h; if (rpc->scan(c, "ss", &group, &name) < 2) { /* rpc->fault(c, 400, "group and counter name required"); */ return; } if (counter_lookup(&h, group, name) < 0) { rpc->fault(c, 400, "non-existent counter %s.%s\n", group, name); return; } counter_reset(h); return; }
static void cnt_get_raw_rpc(rpc_t* rpc, void* c) { char* group; char* name; counter_val_t v; counter_handle_t h; if (rpc->scan(c, "ss", &group, &name) < 2) { /* rpc->fault(c, 400, "group and counter name required"); */ return; } if (counter_lookup(&h, group, name) < 0) { rpc->fault(c, 400, "non-existent counter %s.%s\n", group, name); return; } v = counter_get_raw_val(h); rpc->add(c, "d", (int)v); return; }
static void cnt_get_rpc(rpc_t* rpc, void* c) { char* group; char* name; counter_val_t v; counter_handle_t h; if (rpc->scan(c, "s", &group) < 1) return; if (rpc->scan(c, "*s", &name) < 1) return cnt_grp_get_all(rpc, c, group); /* group & name read */ if (counter_lookup(&h, group, name) < 0) { rpc->fault(c, 400, "non-existent counter %s.%s\n", group, name); return; } v = counter_get_val(h); rpc->add(c, "d", (int)v); return; }
static void cnt_help_rpc(rpc_t* rpc, void* ctx) { char* group; char* name; char* desc; counter_handle_t h; if (rpc->scan(ctx, "ss", &group, &name) < 2) { /* rpc->fault(c, 400, "group and counter name required"); */ return; } if (counter_lookup(&h, group, name) < 0) { rpc->fault(ctx, 400, "non-existent counter %s.%s\n", group, name); return; } desc = counter_get_doc(h); if (desc) rpc->add(ctx, "s", desc); else rpc->fault(ctx, 400, "no description for counter %s.%s\n", group, name); return; }