Exemple #1
0
inline static int mi_reset_and_add_stat(struct mi_node *rpl, stat_var *stat)
{
	struct mi_node *node;
	long old_val, new_val;

	if (stats_support()==0) return -1;

	old_val=get_stat_val(stat);
	reset_stat(stat);
	new_val=get_stat_val(stat);

	if (old_val==new_val)
	{
		node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s = %lu",
				ZSW(get_stat_module(stat)),
				ZSW(get_stat_name(stat)),
				new_val);
	} else {
		node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s = %lu (%lu)",
				ZSW(get_stat_module(stat)),
				ZSW(get_stat_name(stat)),
				new_val, old_val );
	}

	if (node==0)
		return -1;
	return 0;
}
Exemple #2
0
/**
 * Satistic reset/clear-er RPC callback..
 */
static void rpc_reset_or_clear_grp_vars_cbk(void* p, str* g, str* n, counter_handle_t h)
{
	struct rpc_list_params *packed_params;
	rpc_t* rpc;
	void* ctx;
	int clear;
	stat_var *s_stat;
	long old_val, new_val;

	packed_params = p;
	rpc = packed_params->rpc;
	ctx = packed_params->ctx;
	clear = packed_params->clear;
	s_stat = get_stat(n);
	if (s_stat) {
		if (clear) {
			old_val=get_stat_val(s_stat);
			reset_stat(s_stat);
			new_val=get_stat_val(s_stat);
			if (old_val==new_val) {
				rpc->rpl_printf(ctx, "%s:%s = %lu",
					ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)),
					new_val);
			}
			else {
				rpc->rpl_printf(ctx, "%s:%s = %lu (%lu)",
					ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)),
					new_val, old_val);
			}
		}
		else {
			reset_stat(s_stat);
		}
	}
}
Exemple #3
0
/**
 * All statistics reset/clear-er RPC callback.
 */
static void stats_reset_or_clear_all(rpc_t* rpc, void* ctx, char* stat, int clear)
{
	int len = strlen(stat);
	struct rpc_list_params packed_params;
	str s_statistic;
	stat_var *s_stat;
	long old_val, new_val;

	if (len==3 && strcmp("all", stat)==0) {
		packed_params.rpc   = rpc;
		packed_params.ctx   = ctx;
		packed_params.clear = clear;
		counter_iterate_grp_names(rpc_reset_or_clear_all_grps_cbk, &packed_params);
	}
	else if (stat[len-1]==':') {
		packed_params.rpc   = rpc;
		packed_params.ctx   = ctx;
		packed_params.clear = clear;
		stat[len-1] = '\0';
		counter_iterate_grp_vars(stat, rpc_reset_or_clear_grp_vars_cbk, &packed_params);
		stat[len-1] = ':';
	}
	else {
		s_statistic.s = stat;
		s_statistic.len = strlen(stat);
		s_stat = get_stat(&s_statistic);
		if (s_stat) {
			if (clear) {
				old_val=get_stat_val(s_stat);
				reset_stat(s_stat);
				new_val=get_stat_val(s_stat);
				if (old_val==new_val) {
					rpc->rpl_printf(ctx, "%s:%s = %lu",
						ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)),
						new_val);
				}
				else {
					rpc->rpl_printf(ctx, "%s:%s = %lu (%lu)",
						ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)),
						new_val, old_val);
				}
			}
			else {
				reset_stat(s_stat);
			}
		}
	}
}
Exemple #4
0
local void print_player_data(int key, DBT *val)
{
    if (key == KEY_STATS)
    {
        struct
        {
            unsigned short stat;
            int val;
        } *v = val->data;
        int c = val->size / sizeof(*v);

        printf("\tstats data:\n");
        for (; c--; v++)
            printf("\t\t%s: %d\n", get_stat_name(v->stat), v->val);
    }
    else if (key == KEY_CHAT)
    {
        struct
        {
            unsigned short mask;
            time_t expires;
            int msgs;
            ticks_t lastcheck;
        } *v = val->data;

        printf("\tchat data: mask=%hu expires=%ld msgs=%d lastcheck=%d\n",
               v->mask, (long)v->expires, v->msgs, v->lastcheck);
    }
    else
    {
        printf("\tunknown key type %d\n", key);
    }
}
Exemple #5
0
/**
 * All statistic getter RPC callback.
 */
static void stats_get_all(rpc_t* rpc, void* ctx, char* stat)
{
	int len = strlen(stat);
	struct rpc_list_params packed_params;
	str s_statistic;
	stat_var *s_stat;

	if (len==3 && strcmp("all", stat)==0) {
		packed_params.rpc = rpc;
		packed_params.ctx = ctx;
		counter_iterate_grp_names(rpc_get_all_grps_cbk, &packed_params);
	}
	else if (stat[len-1]==':') {
		packed_params.rpc = rpc;
		packed_params.ctx = ctx;
		stat[len-1] = '\0';
		counter_iterate_grp_vars(stat, rpc_get_grp_vars_cbk, &packed_params);
		stat[len-1] = ':';
	}
	else {
		s_statistic.s = stat;
		s_statistic.len = strlen(stat);
		s_stat = get_stat(&s_statistic);
		if (s_stat) {
			rpc->rpl_printf(ctx, "%s:%s = %lu",
				ZSW(get_stat_module(s_stat)), ZSW(get_stat_name(s_stat)),
				get_stat_val(s_stat));
		}
	}
}
Exemple #6
0
local int cmd_stats(int argc, char *argv[])
{
    int i, c;
    time_t tm = time(NULL), ended;

    stats_args.arena = argv[1];
    if (!stats_args.arena)
    {
        puts("you must specify an arena name");
        return 1;
    }

    if (args.serial == LATEST_SERIAL)
        if (!get_latest_serial(&args.serial, stats_args.arena, args.iv))
            return 2;

    args.serial += args.serialoffset;

    /* print some meta-information */
    printf("### asss db tool: stats\n");
    printf("### generated at %s", ctime(&tm));
    printf("### arena: %s\n", stats_args.arena);
    printf("### interval: %s\n", get_interval_name(args.iv));
    printf("### serial: %d\n", args.serial);
    if (get_ending_time(&ended, stats_args.arena, args.iv, args.serial))
        printf("### last modified time: %s\n", ctime(&ended));
    else
        printf("### last modified time unknown\n");

    /* note: it's possible to see stats during the print_stats that we
     * didn't see during the get_statmap because of concurrent access! */
    /* also note we're taking advantage of the fact that stats are
     * always stored in sorted order to speed thing up a bit. */

    walk_db(stats_get_statmap, FALSE);

    /* figure out column positions */
    for (i = c = 0; i < MAX_STAT; i++)
        if (stats_args.statmap[i])
            stats_args.statmap[i] = c++;

    /* print header line */
    stats_args.statmap[MAX_STAT] = c;
    printf("player name");
    for (i = 0; i < MAX_STAT; i++)
        if (stats_args.statmap[i])
        {
            if (args.numheader)
                printf(",%d", i);
            else
                printf(",%s", get_stat_name(i));
        }
    putchar('\n');

    /* does the real work */
    walk_db(stats_print_stats, FALSE);

    return 0;
}
Exemple #7
0
inline static int mi_add_stat(struct mi_node *rpl, stat_var *stat)
{
	struct mi_node *node;

	if (stats_support()==0) return -1;

	node = addf_mi_node_child(rpl, 0, 0, 0, "%s:%s = %lu",
		ZSW(get_stat_module(stat)),
		ZSW(get_stat_name(stat)),
		get_stat_val(stat) );

	if (node==0)
		return -1;
	return 0;
}
Exemple #8
0
int pv_set_stat(struct sip_msg* msg, pv_param_t *param, int op,
													pv_value_t *val)
{
	stat_var *stat;

	if (get_stat_name( msg, &(param->pvn), 1, &stat)!=0) {
		LM_ERR("failed to generate/get statistic name\n");
		return -1;
	}

	if (val != 0)
		LM_WARN("non-zero value - setting value to 0\n");

	reset_stat( stat );

	return 0;
}
Exemple #9
0
int pv_get_stat(struct sip_msg *msg,  pv_param_t *param, pv_value_t *res)
{
	stat_var *stat;

	if(msg==NULL || res==NULL)
		return -1;

	if (get_stat_name( msg, &(param->pvn), 0, &stat)!=0) {
		LM_ERR("failed to generate/get statistic name\n");
		return -1;
	}

	if (stat==NULL)
		return pv_get_null(msg, param, res);

	res->ri = (int)get_stat_val( stat );
	res->rs.s = sint2str(res->ri, &res->rs.len);
	res->flags = PV_VAL_INT|PV_VAL_STR|PV_TYPE_INT;

	return 0;
}