static struct mi_root *mi_get_stats(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_node *rpl; struct mi_node *arg; module_stats *mods; stat_var *stat; str val; int i; if (cmd->node.kids==NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; for( arg=cmd->node.kids ; arg ; arg=arg->next) { if (arg->value.len==0) continue; val = arg->value; if ( val.len==3 && memcmp(val.s,"all",3)==0) { /* add all statistic variables */ for( i=0 ; i<collector->mod_no ;i++ ) { if (mi_add_module_stats( rpl, &collector->amodules[i] )!=0) goto error; } } else if ( val.len>1 && val.s[val.len-1]==':') { /* add module statistics */ val.len--; mods = get_stat_module( &val ); if (mods==0) continue; if (mi_add_module_stats( rpl, mods )!=0) goto error; } else { /* add only one statistic */ stat = get_stat( &val ); if (stat==0) continue; if (mi_add_stat(rpl,stat)!=0) goto error; } } if (rpl->kids==0) { free_mi_tree(rpl_tree); return init_mi_tree( 404, "Statistics Not Found", 20); } return rpl_tree; error: free_mi_tree(rpl_tree); return 0; }
static struct mi_root *mi_get_stats(struct mi_root *cmd, void *param) { struct mi_root *rpl_tree; struct mi_node *rpl; struct mi_node *arg; stat_var *stat; str val; if(stats_support()==0) return init_mi_tree( 404, "Statistics Not Found", 20); if (cmd->node.kids==NULL) return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); if (rpl_tree==0) return 0; rpl = &rpl_tree->node; for( arg=cmd->node.kids ; arg ; arg=arg->next) { if (arg->value.len==0) continue; val = arg->value; if ( val.len==3 && memcmp(val.s,"all",3)==0) { /* add all statistic variables */ /* use direct counters access for that */ counter_iterate_grp_names(mi_add_all_grps_cbk, rpl); } else if ( val.len>1 && val.s[val.len-1]==':') { /* add module statistics */ val.len--; val.s[val.len]=0; /* zero term. */ /* use direct counters access for that */ counter_iterate_grp_vars(val.s, mi_add_grp_vars_cbk, rpl); val.s[val.len]=':' /* restore */; } else { /* add only one statistic */ stat = get_stat( &val ); if (stat==0) continue; if (mi_add_stat(rpl,stat)!=0) goto error; } } if (rpl->kids==0) { free_mi_tree(rpl_tree); return init_mi_tree( 404, "Statistics Not Found", 20); } return rpl_tree; error: free_mi_tree(rpl_tree); return 0; }