From 1b262d1ffd768717f9865525f29a65a2bea8577d Mon Sep 17 00:00:00 2001 From: Jason Penton Date: Thu, 5 Feb 2015 16:52:46 +0200 Subject: [PATCH] modules/cdp: changed stats to use internal counters instead --- modules/cdp/api_process.c | 6 +++-- modules/cdp/cdp_stats.c | 47 ++++++++++++++++++++++++++++++++ modules/cdp/cdp_stats.h | 15 +++++++++++ modules/cdp/mod.c | 27 ++++--------------- modules/cdp/mod.h | 1 - modules/cdp/statistics.c | 56 -------------------------------------- modules/cdp/statistics.h | 57 --------------------------------------- modules/cdp/transaction.c | 6 +++-- modules/cdp/transaction.h | 1 - 9 files changed, 75 insertions(+), 141 deletions(-) create mode 100644 modules/cdp/cdp_stats.c create mode 100644 modules/cdp/cdp_stats.h delete mode 100644 modules/cdp/statistics.c delete mode 100644 modules/cdp/statistics.h diff --git a/modules/cdp/api_process.c b/modules/cdp/api_process.c index 9516183b98e..56ca2db5f5c 100644 --- a/modules/cdp/api_process.c +++ b/modules/cdp/api_process.c @@ -47,8 +47,10 @@ #include "transaction.h" #include "receiver.h" #include "peerstatemachine.h" +#include "cdp_stats.h" extern unsigned int* latency_threshold_p; /** *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); diff --git a/modules/cdp/cdp_stats.c b/modules/cdp/cdp_stats.c new file mode 100644 index 00000000000..6e2985d2e6a --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/modules/cdp/cdp_stats.h b/modules/cdp/cdp_stats.h new file mode 100644 index 00000000000..e6747feaa61 --- /dev/null +++ b/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(); \ No newline at end of file diff --git a/modules/cdp/mod.c b/modules/cdp/mod.c index 90900d31a51..4b0189562a1 100644 --- a/modules/cdp/mod.c +++ b/modules/cdp/mod.c @@ -55,6 +55,7 @@ #include "../../rpc.h" #include "../../rpc_lookup.h" #include "../../cfg/cfg_struct.h" +#include "cdp_stats.h" MODULE_VERSION @@ -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 */ @@ -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 */ @@ -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"); diff --git a/modules/cdp/mod.h b/modules/cdp/mod.h index ef4475ebab6..e52102fea1c 100644 --- a/modules/cdp/mod.h +++ b/modules/cdp/mod.h @@ -47,7 +47,6 @@ #define _CDP__H #include "../../sr_module.h" -#include "statistics.h" #define M_NAME "cdp" diff --git a/modules/cdp/statistics.c b/modules/cdp/statistics.c deleted file mode 100644 index d4d31691733..00000000000 --- a/modules/cdp/statistics.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2012 Smile Communications, jason.penton@smilecoms.com - * Copyright (C) 2012 Smile Communications, richard.good@smilecoms.com - * - * The initial version of this code was written by Dragos Vingarzan - * (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the - * Fruanhofer Institute. It was and still is maintained in a separate - * branch of the original SER. We are therefore migrating it to - * Kamailio/SR and look forward to maintaining it from here on out. - * 2011/2012 Smile Communications, Pty. Ltd. - * ported/maintained/improved by - * Jason Penton (jason(dot)penton(at)smilecoms.com and - * Richard Good (richard(dot)good(at)smilecoms.com) as part of an - * effort to add full IMS support to Kamailio/SR using a new and - * improved architecture - * - * NB: Alot of this code was originally part of OpenIMSCore, - * FhG Fokus. - * Copyright (C) 2004-2006 FhG Fokus - * Thanks for great work! This is an effort to - * break apart the various CSCF functions into logically separate - * components. We hope this will drive wider use. We also feel - * that in this way the architecture is more complete and thereby easier - * to manage in the Kamailio/SR environment - * - * This file is part of Kamailio, a free SIP server. - * - * Kamailio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version - * - * Kamailio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "statistics.h" - -unsigned long get_avg_cdp_response_time() { - - long rpls_received = get_stat_val(replies_received); - if (!rpls_received) - return 0; - - return get_stat_val(replies_response_time)/rpls_received; -} - diff --git a/modules/cdp/statistics.h b/modules/cdp/statistics.h deleted file mode 100644 index 470df0595a9..00000000000 --- a/modules/cdp/statistics.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2012 Smile Communications, jason.penton@smilecoms.com - * Copyright (C) 2012 Smile Communications, richard.good@smilecoms.com - * - * The initial version of this code was written by Dragos Vingarzan - * (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the - * Fruanhofer Institute. It was and still is maintained in a separate - * branch of the original SER. We are therefore migrating it to - * Kamailio/SR and look forward to maintaining it from here on out. - * 2011/2012 Smile Communications, Pty. Ltd. - * ported/maintained/improved by - * Jason Penton (jason(dot)penton(at)smilecoms.com and - * Richard Good (richard(dot)good(at)smilecoms.com) as part of an - * effort to add full IMS support to Kamailio/SR using a new and - * improved architecture - * - * NB: Alot of this code was originally part of OpenIMSCore, - * FhG Fokus. - * Copyright (C) 2004-2006 FhG Fokus - * Thanks for great work! This is an effort to - * break apart the various CSCF functions into logically separate - * components. We hope this will drive wider use. We also feel - * that in this way the architecture is more complete and thereby easier - * to manage in the Kamailio/SR environment - * - * This file is part of Kamailio, a free SIP server. - * - * Kamailio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version - * - * Kamailio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef STATISTICS_H_ -#define STATISTICS_H_ - -#include "../../lib/kcore/statistics.h" - -stat_var* stat_cdp_timeouts; -stat_var* replies_received; -stat_var* replies_response_time; - -unsigned long get_avg_cdp_response_time(); - -#endif /* STATISTICS_H_ */ diff --git a/modules/cdp/transaction.c b/modules/cdp/transaction.c index e0e50aad50b..f98f6af2fd0 100644 --- a/modules/cdp/transaction.c +++ b/modules/cdp/transaction.c @@ -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 */ /** @@ -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)); diff --git a/modules/cdp/transaction.h b/modules/cdp/transaction.h index b5b562604e8..5524993ca8b 100644 --- a/modules/cdp/transaction.h +++ b/modules/cdp/transaction.h @@ -47,7 +47,6 @@ #define __TRANSACTION_H_ #include -#include "statistics.h" #include "utils.h" #include "diameter.h" #include "diameter_api.h"