Example #1
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);
		}
	}
}
Example #2
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;
}
Example #3
0
unsigned long get_avg_mar_response_time() {

	long rpls_received = get_stat_val(mar_replies_received);
	if (!rpls_received)
		return 0;

	return get_stat_val(mar_replies_response_time)/rpls_received;
}
/*
 * (Mostly auto-generated function) 
 *
 * The *_create_row routine is called by the table handler to create a new row
 * for a given index. This is the first stage of the row creation process.  The
 * *_set_reserve_* functions can be used to prevent the row from being inserted
 * into the table even if the row passes any preliminary checks set here. 
 *
 * Returns a newly allocated kamailioSIPRegUserLookupTable_context structure (a
 * row in the table) if the indexes are legal.  NULL will be returned otherwise.
 *
 * The function has been modified from its original form, in that it will store
 * the number of messages 'in' to the system, and the number of messages 'out'
 * of the system, that had a status code matching this rows status code, at the
 * time this row was created.  
 *
 * This value will be used in the future to calculate the delta between now and
 * the time this row has been read.  
 * */
kamailioSIPStatusCodesTable_context *
kamailioSIPStatusCodesTable_create_row( netsnmp_index* hdr)
{
	stat_var *in_status_code;
	stat_var *out_status_code;

	kamailioSIPStatusCodesTable_context * ctx =
		SNMP_MALLOC_TYPEDEF(kamailioSIPStatusCodesTable_context);
	if(!ctx)
		return NULL;
		
	/* The *_extract_index funtion already validates the indices, so we
	 * don't need to do any further evaluations here.  */
	if(kamailioSIPStatusCodesTable_extract_index( ctx, hdr )) {
		if (NULL != ctx->index.oids)
			free(ctx->index.oids);
		free(ctx);
		return NULL;
	}


	/* The indices were already set up in the extract_index function
	 * above. */
	ctx->kamailioSIPStatusCodeIns       = 0;
	ctx->kamailioSIPStatusCodeOuts      = 0;
	ctx->kamailioSIPStatusCodeRowStatus = 0;

	/* Retrieve the index for the status code, and then assign the starting
	 * values.  The starting values will be used to calculate deltas during
	 * the next snmpget/snmpwalk/snmptable/etc. */
	int codeIndex = ctx->kamailioSIPStatusCodeValue;

	ctx->startingInStatusCodeValue  = 0;
	ctx->startingOutStatusCodeValue = 0;

	in_status_code  = get_stat_var_from_num_code(codeIndex, 0);
	out_status_code = get_stat_var_from_num_code(codeIndex, 1);

	if (in_status_code != NULL) 
	{
		ctx->startingInStatusCodeValue  = get_stat_val(in_status_code);
	}

	if (out_status_code != NULL) 
	{
		ctx->startingOutStatusCodeValue = get_stat_val(out_status_code);
	}

	return ctx;
}
Example #5
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);
			}
		}
	}
}
Example #6
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));
		}
	}
}
Example #7
0
static unsigned long cc_flow_get_load( void *flow_p)
{
	struct cc_flow *flow = (struct cc_flow*)flow_p;

	return (flow->logged_agents==0) ? 0 :
	(100*(get_stat_val(flow->st_onhold_calls)+flow->logged_agents-cc_flow_free_agents(flow))/flow->logged_agents);
}
Example #8
0
static unsigned long cc_flow_get_etw( void *flow_p)
{
	struct cc_flow *flow = (struct cc_flow*)flow_p;

	return flow->logged_agents? (unsigned long)(( flow->avg_call_duration * get_stat_val(flow->st_queued_calls) ) /
		(float)flow->logged_agents):0;
}
Example #9
0
int pv_get_stat(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
{
	stat_var *stat;

	stat = get_stat(&param->pvn.u.isname.name.s);
	if (stat == NULL) {
		LM_WARN("No stat variable ``%.*s''\n",
			param->pvn.u.isname.name.s.len, param->pvn.u.isname.name.s.s);
		return pv_get_null(msg, param, res);
	}
	return pv_get_uintval(msg, param, res,
			(unsigned int)get_stat_val(stat));
}
Example #10
0
int statsc_svalue(str *name, int64_t *res)
{
	stat_var       *stat;

	stat = get_stat(name);
	if(stat==NULL) {
		LM_ERR("statistic %.*s not found\n", name->len, name->s);
		return -1;
	}

	*res = (int64_t)get_stat_val(stat);

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

	node = addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
		collector->amodules[stat->mod_idx].name.len,
		collector->amodules[stat->mod_idx].name.s,
		stat->name.len, stat->name.s,
		get_stat_val(stat) );

	if (node==0)
		return -1;
	return 0;
}
Example #12
0
int pv_get_stat(struct sip_msg *msg,  pv_param_t *param, pv_value_t *res)
{

	stat_var *stat = get_stat_p(param);

	if (stat == NULL)
		return -1;

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

	return 0;
}
Example #13
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;
}
Example #14
0
inline static int mi_add_module_stats(struct mi_node *rpl,
													module_stats *mods)
{
	struct mi_node *node;
	stat_var *stat;

	for( stat=mods->head ; stat ; stat=stat->lnext) {
		node = addf_mi_node_child(rpl, 0, 0, 0, "%.*s:%.*s = %lu",
			mods->name.len, mods->name.s,
			stat->name.len, stat->name.s,
			get_stat_val(stat) );
		if (node==0)
			return -1;
	}
	return 0;
}
Example #15
0
/*!
 * \brief Loops through all domains summing up the number of users
 * \return the number of users, could be zero
 */
unsigned long get_number_of_users(void)
{
	long numberOfUsers = 0;

	dlist_t* current_dlist;
	
	current_dlist = root;

	while (current_dlist)
	{
		numberOfUsers += get_stat_val(current_dlist->d->users); 
		current_dlist  = current_dlist->next;
	}

	return numberOfUsers;
}
Example #16
0
unsigned long get_number_of_impu(void)
{
        long numberOfExpired = 0;

        dlist_t* current_dlist;

        current_dlist = root;

        while (current_dlist)
        {
                numberOfExpired += get_stat_val(current_dlist->d->expired);
                current_dlist  = current_dlist->next;
        }

        return numberOfExpired;
}
Example #17
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;
}
Example #18
0
static int pv_get_dlg_count(struct sip_msg *msg, pv_param_t *param,
		pv_value_t *res)
{
	int n;
	int l;
	char *ch;

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

	n = active_dlgs ? get_stat_val(active_dlgs) : 0;
	l = 0;
	ch = int2str( n, &l);

	res->rs.s = ch;
	res->rs.len = l;

	res->ri = n;
	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;

	return 0;
}
Example #19
0
unsigned long stg_load(unsigned short foo)
{
	unsigned int free_ag;
	unsigned int load;
	struct cc_agent *agent;

	lock_get( data->lock );

	if (data->logedin_agents==0) {
		lock_release( data->lock );
		return 0;
	}

	free_ag = 0;
	for (agent = data->agents[CC_AG_ONLINE] ; agent ; agent=agent->next) {
		if (agent->state==CC_AGENT_FREE) free_ag++;
	}

	load = 100*( get_stat_val(stg_onhold_calls) + data->logedin_agents - free_ag ) / data->logedin_agents;

	lock_release( data->lock );

	return load;
}
Example #20
0
int wsconn_add(struct receive_info rcv, unsigned int sub_protocol)
{
	int cur_cons, max_cons;
	int id = rcv.proto_reserved1;
	int id_hash = tcp_id_hash(id);
	ws_connection_t *wsc;

	LM_DBG("wsconn_add id [%d]\n", id);

	/* Allocate and fill in new WebSocket connection */
	wsc = shm_malloc(sizeof(ws_connection_t) + BUF_SIZE);
	if (wsc == NULL)
	{
		LM_ERR("allocating shared memory\n");
		return -1;
	}
	memset(wsc, 0, sizeof(ws_connection_t) + BUF_SIZE);
	wsc->id = id;
	wsc->id_hash = id_hash;
	wsc->state = WS_S_OPEN;
	wsc->rcv = rcv;
	wsc->sub_protocol = sub_protocol;
	wsc->run_event = 0;
	wsc->frag_buf.s = ((char*)wsc) + sizeof(ws_connection_t);
	atomic_set(&wsc->refcnt, 0);

	LM_DBG("wsconn_add new wsc => [%p], ref => [%d]\n", wsc, atomic_get(&wsc->refcnt));

	WSCONN_LOCK;
	/* Add to WebSocket connection table */
	wsconn_listadd(wsconn_id_hash[wsc->id_hash], wsc, id_next, id_prev);

	/* Add to the end of the WebSocket used list */
	wsc->last_used = (int)time(NULL);
	if (wsconn_used_list->head == NULL)
		wsconn_used_list->head = wsconn_used_list->tail = wsc;
	else
	{
		wsc->used_prev = wsconn_used_list->tail;
		wsconn_used_list->tail->used_next = wsc;
		wsconn_used_list->tail = wsc;
	}
	wsconn_ref(wsc);

	WSCONN_UNLOCK;

	LM_DBG("wsconn_add added to conn_table wsc => [%p], ref => [%d]\n", wsc, atomic_get(&wsc->refcnt));

	/* Update connection statistics */
	lock_get(wsstat_lock);

	update_stat(ws_current_connections, 1);
	cur_cons = get_stat_val(ws_current_connections);
	max_cons = get_stat_val(ws_max_concurrent_connections);
	if (max_cons < cur_cons)
		update_stat(ws_max_concurrent_connections, cur_cons - max_cons);

	if (wsc->sub_protocol == SUB_PROTOCOL_SIP)
	{
		update_stat(ws_sip_current_connections, 1);
		cur_cons = get_stat_val(ws_sip_current_connections);
		max_cons = get_stat_val(ws_sip_max_concurrent_connections);
		if (max_cons < cur_cons)
			update_stat(ws_sip_max_concurrent_connections,
					cur_cons - max_cons);
	}
	else if (wsc->sub_protocol == SUB_PROTOCOL_MSRP)
	{
		update_stat(ws_msrp_current_connections, 1);
		cur_cons = get_stat_val(ws_msrp_current_connections);
		max_cons = get_stat_val(ws_msrp_max_concurrent_connections);
		if (max_cons < cur_cons)
			update_stat(ws_msrp_max_concurrent_connections,
					cur_cons - max_cons);
	}

	lock_release(wsstat_lock);

	return 0;
}
Example #21
0
/*
 * Note: as opposed to hp_shm_malloc_unsafe(),
 *       hp_shm_malloc() assumes that the core statistics are initialized
 */
void *hp_shm_malloc(struct hp_block *hpb, unsigned long size)
{
	struct hp_frag *frag;
	unsigned int init_hash, hash, sec_hash;
	int i;

	/* size must be a multiple of ROUNDTO */
	size = ROUNDUP(size);

	/*search for a suitable free frag*/

	for (hash = GET_HASH(size), init_hash = hash; hash < HP_HASH_SIZE; hash++) {
		if (!hpb->free_hash[hash].is_optimized) {
			SHM_LOCK(hash);
			frag = hpb->free_hash[hash].first;

			for (; frag; frag = frag->u.nxt_free)
				if (frag->size >= size)
					goto found;

			SHM_UNLOCK(hash);
		} else {
			/* optimized size. search through its own hash! */
			for (i = 0, sec_hash = HP_HASH_SIZE +
			                       hash * shm_secondary_hash_size +
				                   optimized_get_indexes[hash];
				 i < shm_secondary_hash_size;
				 i++, sec_hash = (sec_hash + 1) % shm_secondary_hash_size) {

				SHM_LOCK(sec_hash);
				frag = hpb->free_hash[sec_hash].first;
				for (; frag; frag = frag->u.nxt_free)
					if (frag->size >= size) {
						/* free fragments are detached in a simple round-robin manner */
						optimized_get_indexes[hash] =
						    (optimized_get_indexes[hash] + i + 1)
						     % shm_secondary_hash_size;
						hash = sec_hash;
						goto found;
					}

				SHM_UNLOCK(sec_hash);
			}
		}

		/* try in a bigger bucket */
	}

	/* out of memory... we have to shut down */
	LM_CRIT("not enough shared memory, please increase the \"-m\" parameter!\n");
	abort();

found:
	hp_frag_detach(hpb, frag);

	/* split the fragment if possible */
	shm_frag_split(hpb, frag, size, hash);

	SHM_UNLOCK(hash);

	update_stats_shm_frag_detach(frag);

#ifndef HP_MALLOC_FAST_STATS
	unsigned long real_used;

	real_used = get_stat_val(shm_rused);
	if (real_used > hpb->max_real_used)
		hpb->max_real_used = real_used;
#endif

	/* ignore concurrency issues, simply obtaining an estimate is enough */
	mem_hash_usage[init_hash]++;

	return (char *)frag + sizeof *frag;
}
Example #22
0
static int w_handle_call(struct sip_msg *msg, char *flow_var)
{
	struct cc_flow *flow;
	struct cc_call *call;
	str leg = {NULL,0};
	str *dn;
	str val;
	int dec;
	int ret = -1;

	call = NULL;
	dec = 0;

	/* get the flow name */
	if (fixup_get_svalue(msg, (gparam_p)flow_var, &val)!=0) {
		LM_ERR("failed to avaluate the flow name variable\n");
		return -1;
	}

	/* parse FROM URI */
	if (parse_from_uri(msg)==NULL) {
		LM_ERR("failed to parse from hdr\n");
		return -2;
	}

	lock_get( data->lock );

	/* get the flow ID */
	flow = get_flow_by_name(data, &val);
	if (flow==NULL) {
		LM_ERR("flow <%.*s> does not exists\n", val.len, val.s);
		ret = -3;
		goto error;
	}
	LM_DBG("using call flow %p\n", flow);

	if (flow->logged_agents==0 /* no logged agents */ ) {
		LM_NOTICE("flow <%.*s> closed\n",flow->id.len,flow->id.s);
		ret = -4;
		goto error;
	}

	update_stat(stg_incalls, 1);
	update_stat(flow->st_incalls, 1);

	if (flow->cid.len) {
		dn = build_displayname(&flow->cid, get_from(msg));
	} else if (get_from(msg)->display.len) {
		dn = &get_from(msg)->display;
	} else {
		dn = &get_from(msg)->parsed_uri.user;
	}
	LM_DBG("cid=<%.*s>\n",dn->len,dn->s);

	call = new_cc_call(data, flow, dn, &get_from(msg)->parsed_uri.user);
	if (call==NULL) {
		LM_ERR("failed to create new call\n");
		ret = -5;
		goto error;
	}
	call->fst_flags |= FSTAT_INCALL;

	/* get estimated wait time */
	call->eta = (unsigned int) (( flow->avg_call_duration *
		(float)get_stat_val(flow->st_queued_calls) ) /
		(float)flow->logged_agents);
	
	LM_DBG("avg_call_duration=%.2f queued_calls=%lu logedin_agents=%u\n",
		flow->avg_call_duration, get_stat_val(flow->st_queued_calls),
		flow->logged_agents);

	LM_DBG("ETA for new call(%p) is %d\n", call, call->eta);

	/* one more call to process */
	flow->ongoing_calls++;

	/* there is no need to lock the call here as it is not 
	 * yet sharead at all - just we have a ref to it */
	
	/* get the first state */
	if (cc_call_state_machine( data, call, &leg )!=0) {
		LM_ERR("failed to get first call destination \n");
		ret = -5;
		goto error;
	}

	lock_release( data->lock );
	LM_DBG("new destination for call(%p) is %.*s (state=%d)\n",
		call, leg.len, leg.s, call->state);

	/* call still waits for agent ? */
	if (call->state!=CC_CALL_TOAGENT) {
		LM_DBG("** onhold++ Not to agent [%p]\n", call);
		update_stat( stg_onhold_calls, +1);
		update_stat( flow->st_onhold_calls, +1);
		dec = 1;
	}

	/* send call to selected destination */
	if (set_call_leg( msg, call, &leg)< 0 ) {
		LM_ERR("failed to set new destination for call\n");
		if (dec) { 
			LM_DBG("** onhold-- Error [%p]\n", call);
			update_stat( stg_onhold_calls, -1);
			update_stat( flow->st_onhold_calls, -1);
		}
		pkg_free(leg.s);
		goto error1;
	}

	pkg_free(leg.s);

	if(cc_db_insert_call(call) < 0) {
		LM_ERR("Failed to insert call record in db\n");
	}

	return 1;
error:
	lock_release( data->lock );
error1:
	if (call) { free_cc_call( data, call); flow->ongoing_calls--; }
	return ret;
}
Example #23
0
unsigned long hp_rpm_get_frags(struct hp_block *hpb)
{
	return get_stat_val(rpm_frags);
}
Example #24
0
unsigned long hp_rpm_get_free(struct hp_block *hpb)
{
	return hpb->size - get_stat_val(rpm_rused);
}
Example #25
0
unsigned long hp_rpm_get_real_used(struct hp_block *hpb)
{
	return get_stat_val(rpm_rused);
}
Example #26
0
unsigned long hp_shm_get_used(struct hp_block *hpb)
{
	return get_stat_val(shm_used);
}
/*
 * This function is called to handle SNMP GET requests.  
 *
 * The row which this function is called with, will store a message code.  The
 * function will retrieve the 'number of messages in' and 'number of messages
 * out' statistic for this particular message code from the statistics
 * framework.  
 *
 * The function will then subtract from this value the value it was initialized
 * with when the row was first created.  In this sense, the row shows how many
 * ins and how many outs have been received (With respect to the message code)
 * since this row was created. 
 */
int kamailioSIPStatusCodesTable_get_value(
			netsnmp_request_info *request,
			netsnmp_index *item,
			netsnmp_table_request_info *table_info )
{
	stat_var *the_stat;

	netsnmp_variable_list *var = request->requestvb;

	kamailioSIPStatusCodesTable_context *context = 
		(kamailioSIPStatusCodesTable_context *)item;

	/* Retrieve the statusCodeIdx so we can calculate deltas between current
	 * values and previous values. */
	int statusCodeIdx = context->kamailioSIPStatusCodeValue;

	switch(table_info->colnum) 
	{
		case COLUMN_KAMAILIOSIPSTATUSCODEINS:

			context->kamailioSIPStatusCodeIns = 0;

			the_stat = get_stat_var_from_num_code(statusCodeIdx, 0);

			if (the_stat != NULL)  
			{
				/* Calculate the Delta */
				context->kamailioSIPStatusCodeIns = get_stat_val(the_stat) -
					context->startingInStatusCodeValue;
			}

			snmp_set_var_typed_value(var, ASN_COUNTER,
					(unsigned char*)
					&context->kamailioSIPStatusCodeIns,
					sizeof(context->kamailioSIPStatusCodeIns));
			break;
	
		case COLUMN_KAMAILIOSIPSTATUSCODEOUTS:
			
			context->kamailioSIPStatusCodeOuts = 0;

			the_stat = get_stat_var_from_num_code(statusCodeIdx, 1);

			if (the_stat != NULL)
			{
				/* Calculate the Delta */
				context->kamailioSIPStatusCodeOuts =
					get_stat_val(the_stat) -
					context->startingOutStatusCodeValue;
			}
			snmp_set_var_typed_value(var, ASN_COUNTER,
					 (unsigned char*)
					 &context->kamailioSIPStatusCodeOuts,
					 sizeof(context->kamailioSIPStatusCodeOuts) );
		break;
	
		case COLUMN_KAMAILIOSIPSTATUSCODEROWSTATUS:
			/** RowStatus = ASN_INTEGER */
			snmp_set_var_typed_value(var, ASN_INTEGER,
					 (unsigned char*)
					 &context->kamailioSIPStatusCodeRowStatus,
					 sizeof(context->kamailioSIPStatusCodeRowStatus) );
		break;
	
	default: /** We shouldn't get here */
		snmp_log(LOG_ERR, "unknown column in "
				 "kamailioSIPStatusCodesTable_get_value\n");
		return SNMP_ERR_GENERR;
	}
	return SNMP_ERR_NOERROR;
}
Example #28
0
/*
 * although there is a lot of duplicate code, we get the best performance:
 *
 * - the _unsafe version will not be used too much anyway (usually at startup)
 * - hp_shm_malloc is faster (no 3rd parameter, no extra if blocks)
 */
void *hp_shm_malloc_unsafe(struct hp_block *qm, unsigned long size)
{
    struct hp_frag *frag;
    unsigned int init_hash, hash, sec_hash;
    int i;

    /* size must be a multiple of ROUNDTO */
    size = ROUNDUP(size);

    /*search for a suitable free frag*/

    for (hash = GET_HASH(size), init_hash = hash; hash < HP_HASH_SIZE; hash++) {
        if (!qm->free_hash[hash].is_optimized) {
            frag = qm->free_hash[hash].first;

            for (; frag; frag = frag->u.nxt_free)
                if (frag->size >= size)
                    goto found;

        } else {
            /* optimized size. search through its own hash! */
            for (i = 0, sec_hash = HP_HASH_SIZE +
                                   hash * shm_secondary_hash_size +
                                   optimized_get_indexes[hash];
                    i < shm_secondary_hash_size;
                    i++, sec_hash = (sec_hash + 1) % shm_secondary_hash_size) {

                frag = qm->free_hash[sec_hash].first;
                for (; frag; frag = frag->u.nxt_free)
                    if (frag->size >= size) {
                        /* free fragments are detached in a simple round-robin manner */
                        optimized_get_indexes[hash] =
                            (optimized_get_indexes[hash] + i + 1)
                            % shm_secondary_hash_size;
                        hash = sec_hash;
                        goto found;
                    }
            }
        }

        /* try in a bigger bucket */
    }

    /* out of memory... we have to shut down */
    LM_CRIT("not enough shared memory, please increase the \"-m\" parameter!\n");
    abort();

found:
    hp_frag_detach(qm, frag);
    if (stats_are_ready())
        update_stats_shm_frag_detach(frag);
    else {
        qm->used += frag->size;
        qm->real_used += frag->size + FRAG_OVERHEAD;
    }

    /* split the fragment if possible */
    shm_frag_split_unsafe(qm, frag, size);

#ifndef HP_MALLOC_FAST_STATS
    if (stats_are_ready()) {
        unsigned long real_used;

        real_used = get_stat_val(shm_rused);
        if (real_used > qm->max_real_used)
            qm->max_real_used = real_used;
    } else if (qm->real_used > qm->max_real_used)
        qm->max_real_used = qm->real_used;
#endif

    if (mem_hash_usage)
        mem_hash_usage[init_hash]++;

    return (char *)frag + sizeof *frag;
}
Example #29
0
unsigned int calc_tcp_load(void *val)
{
	return ( get_stat_val((stat_var*)val) * 100)/tcp_children_no;
}