Skip to content

Commit

Permalink
Add a protocol-specific timer metric.
Browse files Browse the repository at this point in the history
  • Loading branch information
Castaglia committed Mar 26, 2017
1 parent 476a5a3 commit 0097de9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mod_statsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static const char *statsd_exclude_filter = NULL;
static pr_regex_t *statsd_exclude_pre = NULL;
#endif /* PR_USE_REGEX */
static float statsd_sampling = STATSD_DEFAULT_SAMPLING;
static uint64_t statsd_sess_start_ms = 0;
static struct statsd *statsd = NULL;

static int statsd_sess_init(void);
Expand Down Expand Up @@ -455,6 +456,7 @@ static void statsd_exit_ev(const void *event_data, void *user_data) {
if (statsd != NULL) {
char *metric;
const char *proto;
uint64_t now_ms = 0, sess_ms;

metric = get_conn_metric(session.pool, NULL);
statsd_metric_gauge(statsd, metric, -1, STATSD_METRIC_GAUGE_FL_ADJUST);
Expand All @@ -463,6 +465,10 @@ static void statsd_exit_ev(const void *event_data, void *user_data) {
metric = get_conn_metric(session.pool, proto);
statsd_metric_gauge(statsd, metric, -1, STATSD_METRIC_GAUGE_FL_ADJUST);

pr_gettimeofday_millis(&now_ms);
sess_ms = now_ms - statsd_sess_start_ms;
statsd_metric_timer(statsd, metric, sess_ms);

statsd_statsd_close(statsd);
statsd = NULL;
}
Expand Down Expand Up @@ -738,6 +744,14 @@ static int statsd_sess_init(void) {
statsd_tls_data_handshake_error_ev, NULL);
}

/* We only want to set the session start time once; this function could be
* called again due to e.g. a HOST command, and we do not want to reset
* the start time in that case.
*/
if (statsd_sess_start_ms == 0) {
pr_gettimeofday_millis(&statsd_sess_start_ms);
}

return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions mod_statsd.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,14 @@ <h2><a name="Usage">Usage</a></h2>
Timers:
<pre>
<i>command</i>.<i>response-code</i>
<i>protocol</i>.connection
tls.handshake.ctrl
</pre>
Examples:
<pre>
PASS.331
ftp.connection
sftp.connection
tls.handshake.ctrl
</pre>

Expand Down

0 comments on commit 0097de9

Please sign in to comment.