[Asterisk-code-review] res pjsip/pjsip options: Add StatsD statistics for PJSIP con... (asterisk[13])

Matt Jordan asteriskteam at digium.com
Wed Nov 18 21:25:48 CST 2015


Matt Jordan has uploaded a new change for review.

  https://gerrit.asterisk.org/1654

Change subject: res_pjsip/pjsip_options: Add StatsD statistics for PJSIP contacts
......................................................................

res_pjsip/pjsip_options: Add StatsD statistics for PJSIP contacts

This patch adds the ability to send StatsD statistics related to the
state of PJSIP contacts. This includes:
 * A GUAGE statistic measuring the count of contacts in a particular state.
   This measures how many contacts are reachable, unreachable, etc.
 * The RTT time for each contact, if those contacts are qualified. This
   provides StatsD engines useful time-based data about each contact.

ASTERISK-25571

Change-Id: Ib8378d73afedfc622be0643b87c542557e0b332c
---
M CHANGES
M res/res_pjsip/pjsip_options.c
2 files changed, 22 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/1654/1

diff --git a/CHANGES b/CHANGES
index 348927b..fcbbcec 100644
--- a/CHANGES
+++ b/CHANGES
@@ -55,6 +55,14 @@
  * The ability to use "like" has been added to the pjsip list and show
    CLI commands.  For instance: CLI> pjsip list endpoints like abc
 
+ * If res_statsd is loaded and a StatsD server is configured, basic statistics
+   regarding the state of PJSIP contacts will not be emitted. This includes:
+   - A GUAGE statistic for the overall number of contacts in a particular
+     state, e.g.:
+       PJSIP.contacts.states.Reachable
+   - A TIMER statistic for the RTT time for each qualified contact, e.g.:
+       PJSIP.contacts.alice@@127.0.0.1:5061.rtt
+
 func_callerid
 -------------------
  * CALLERID(pres) is now documented as a valid alternative to setting both
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 32ee401..58519a9 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -29,6 +29,7 @@
 #include "asterisk/cli.h"
 #include "asterisk/time.h"
 #include "asterisk/test.h"
+#include "asterisk/statsd.h"
 #include "include/res_pjsip_private.h"
 
 #define DEFAULT_LANGUAGE "en"
@@ -113,6 +114,9 @@
 		return NULL;
 	}
 
+	ast_statsd_log_string_va("PJSIP.contacts.states.%s", AST_STATSD_GUAGE,
+		"+1", 1.0, ast_sip_get_contact_status_label(status->status));
+
 	return status;
 }
 
@@ -143,6 +147,12 @@
 
 	update->last_status = status->status;
 	update->status = value;
+	if (update->last_status != update->status) {
+		ast_statsd_log_string_va("PJSIP.contacts.states.%s", AST_STATSD_GUAGE,
+			"-1", 1.0, ast_sip_get_contact_status_label(update->last_status));
+		ast_statsd_log_string_va("PJSIP.contacts.states.%s", AST_STATSD_GUAGE,
+			"+1", 1.0, ast_sip_get_contact_status_label(update->status));
+	}
 
 	/* if the contact is available calculate the rtt as
 	   the diff between the last start time and "now" */
@@ -151,10 +161,12 @@
 
 	update->rtt_start = ast_tv(0, 0);
 
+	ast_statsd_log_full_va("PJSIP.contacts.%s.rtt", AST_STATSD_TIMER,
+		update->rtt / 1000, 1.0, ast_sorcery_object_get_id(update));
 	ast_test_suite_event_notify("AOR_CONTACT_QUALIFY_RESULT",
 		"Contact: %s\r\n"
-			"Status: %s\r\n"
-			"RTT: %" PRId64,
+		"Status: %s\r\n"
+		"RTT: %" PRId64,
 		ast_sorcery_object_get_id(update),
 		ast_sip_get_contact_status_label(update->status),
 		update->rtt);

-- 
To view, visit https://gerrit.asterisk.org/1654
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib8378d73afedfc622be0643b87c542557e0b332c
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Matt Jordan <mjordan at digium.com>



More information about the asterisk-code-review mailing list