Skip to content

Commit

Permalink
modules/cdp: changed stats to use internal counters instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybeepee committed Feb 5, 2015
1 parent 23b4d93 commit 1b262d1
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 141 deletions.
6 changes: 4 additions & 2 deletions modules/cdp/api_process.c
Expand Up @@ -47,8 +47,10 @@
#include "transaction.h"
#include "receiver.h"
#include "peerstatemachine.h"
#include "cdp_stats.h"

extern unsigned int* latency_threshold_p; /**<max delay for Diameter call */
extern struct cdp_counters_h cdp_cnts_h;

handler_list *handlers = 0; /**< list of handlers */
gen_lock_t *handlers_lock; /**< lock for list of handlers */
Expand Down Expand Up @@ -108,8 +110,8 @@ int api_callback(peer *p,AAAMessage *msg,void* ptr)
if (elapsed_msecs > *latency_threshold_p) {
LM_ERR("Received diameter response outside of threshold (%d) - %ld\n", *latency_threshold_p, elapsed_msecs);
}
update_stat(replies_received, 1);
update_stat(replies_response_time, elapsed_msecs);
counter_inc(cdp_cnts_h.replies_received);
counter_add(cdp_cnts_h.replies_response_time, elapsed_msecs);
auto_drop = t->auto_drop;
if (t->cb){
(t->cb)(0,*(t->ptr),msg, elapsed_msecs);
Expand Down
47 changes: 47 additions & 0 deletions modules/cdp/cdp_stats.c
@@ -0,0 +1,47 @@
#include "cdp_stats.h"

struct cdp_counters_h cdp_cnts_h;
enum sctp_info_req { CDP_AVG_RSP };

static counter_val_t cdp_internal_stats(counter_handle_t h, void* what);

counter_def_t cdp_cnt_defs[] = {
{&cdp_cnts_h.timeout, "timeout", 0, 0, 0,
"number of timeouts on CDP requests"},
{&cdp_cnts_h.replies_received, "replies_received", 0, 0, 0,
"total number of replies received"},
{&cdp_cnts_h.replies_response_time, "replies_response_time", 0, 0, 0,
"total time waiting for replies"},
{0, "average_response_time", 0,
cdp_internal_stats, (void*) (long) CDP_AVG_RSP,
"average response time for CDP replies"},
{0, 0, 0, 0, 0, 0}
};

int cdp_init_counters() {
if (counter_register_array("cdp", cdp_cnt_defs) < 0)
goto error;
return 0;
error:
return -1;
}

void cdp_destroy_counters() {

}

/** helper function for some stats (which are kept internally).
*/
static counter_val_t cdp_internal_stats(counter_handle_t h, void* what) {
enum sctp_info_req w;

w = (int) (long) what;
switch (w) {
case CDP_AVG_RSP:
if (counter_get_val(cdp_cnts_h.replies_received) == 0)
return 0;
else
return counter_get_val(cdp_cnts_h.replies_response_time)/counter_get_val(cdp_cnts_h.replies_received);
};
return 0;
}
15 changes: 15 additions & 0 deletions modules/cdp/cdp_stats.h
@@ -0,0 +1,15 @@
#ifndef CDP_STATS_H
#define CDP_STATS_H

#include "../../counters.h"

struct cdp_counters_h {
counter_handle_t timeout;
counter_handle_t replies_received;
counter_handle_t replies_response_time;
counter_handle_t avg_response_time;
};
#endif /* CDP_STATS_H */

int cdp_init_counters();
void cdp_destroy_counters();
27 changes: 5 additions & 22 deletions modules/cdp/mod.c
Expand Up @@ -55,6 +55,7 @@
#include "../../rpc.h"
#include "../../rpc_lookup.h"
#include "../../cfg/cfg_struct.h"
#include "cdp_stats.h"

MODULE_VERSION

Expand Down Expand Up @@ -170,12 +171,6 @@ static param_export_t cdp_params[] = {
{ 0, 0, 0 }
};

stat_export_t mod_stats[] = {
{"avg_response_time" , STAT_IS_FUNC, (stat_var**)get_avg_cdp_response_time },
{"timeouts" , 0, (stat_var**)&stat_cdp_timeouts },
{0,0,0}
};

/**
* Exported module interface
*/
Expand All @@ -184,7 +179,7 @@ struct module_exports exports = {
DEFAULT_DLFLAGS,
cdp_cmds, /**< Exported functions */
cdp_params, /**< Exported parameters */
mod_stats,
0,
0, /**< MI cmds */
0, /**< pseudovariables */
0, /**< extra processes */
Expand All @@ -206,23 +201,11 @@ static int cdp_init( void )
LM_ERR("failed to register RPC commands for CDP module\n");
return -1;
}
#ifdef STATISTICS
/* register statistics */
if ( register_stat("cdp", "replies_response_time", &replies_response_time,0 )!=0 ) {
LM_ERR("failed to register stat\n");
return -1;
}

if ( register_stat("cdp", "replies_received", &replies_received, 0)!=0 ) {
LM_ERR("failed to register stat\n");
return -1;
}

if (register_module_stats( exports.name, mod_stats)!=0 ) {
LM_ERR("failed to register core statistics\n");
return -1;
if (cdp_init_counters() != 0) {
LM_ERR("Failed to register counters for CDP modules\n");
return -1;
}
#endif

if (!diameter_peer_init(config_file)){
LM_ERR("error initializing the diameter peer\n");
Expand Down
1 change: 0 additions & 1 deletion modules/cdp/mod.h
Expand Up @@ -47,7 +47,6 @@
#define _CDP__H

#include "../../sr_module.h"
#include "statistics.h"

#define M_NAME "cdp"

Expand Down
56 changes: 0 additions & 56 deletions modules/cdp/statistics.c

This file was deleted.

57 changes: 0 additions & 57 deletions modules/cdp/statistics.h

This file was deleted.

6 changes: 4 additions & 2 deletions modules/cdp/transaction.c
Expand Up @@ -47,8 +47,9 @@

#include "timer.h"
#include "globals.h"
#include "cdp_stats.h"


extern struct cdp_counters_h cdp_cnts_h;
cdp_trans_list_t *trans_list=0; /**< list of transactions */

/**
Expand Down Expand Up @@ -197,7 +198,8 @@ int cdp_trans_timer(time_t now, void* ptr)
while(x)
{
if (now>x->expires){
update_stat(stat_cdp_timeouts, 1); //Transaction has timed out waiting for response
counter_inc(cdp_cnts_h.timeout); //Transaction has timed out waiting for response

x->ans = 0;
if (x->cb){
(x->cb)(1,*(x->ptr),0, (now - x->expires));
Expand Down
1 change: 0 additions & 1 deletion modules/cdp/transaction.h
Expand Up @@ -47,7 +47,6 @@
#define __TRANSACTION_H_

#include <time.h>
#include "statistics.h"
#include "utils.h"
#include "diameter.h"
#include "diameter_api.h"
Expand Down

0 comments on commit 1b262d1

Please sign in to comment.