aboutsummaryrefslogtreecommitdiff
path: root/src/stream/ngx_stream_variables.c
diff options
context:
space:
mode:
authorVladimir Homutov <vl@nginx.com>2016-08-26 15:33:04 +0300
committerVladimir Homutov <vl@nginx.com>2016-08-26 15:33:04 +0300
commitf04b65358e543275affc4cee13c90cd568ae438a (patch)
treee598ec8788ad8f1c8a6e3880e7e84bdc3c6a5746 /src/stream/ngx_stream_variables.c
parent1258126f0c9070315c494d31b71ae912c9aa82c8 (diff)
downloadnginx-f04b65358e543275affc4cee13c90cd568ae438a.tar.gz
nginx-f04b65358e543275affc4cee13c90cd568ae438a.zip
Stream: the $session_time variable.
The variable keeps time spent on processing the stream session.
Diffstat (limited to 'src/stream/ngx_stream_variables.c')
-rw-r--r--src/stream/ngx_stream_variables.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/stream/ngx_stream_variables.c b/src/stream/ngx_stream_variables.c
index 147236540..40572f2aa 100644
--- a/src/stream/ngx_stream_variables.c
+++ b/src/stream/ngx_stream_variables.c
@@ -23,6 +23,8 @@ static ngx_int_t ngx_stream_variable_server_port(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_stream_variable_bytes(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_stream_variable_session_time(ngx_stream_session_t *s,
+ ngx_stream_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_stream_variable_connection(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data);
@@ -63,6 +65,9 @@ static ngx_stream_variable_t ngx_stream_core_variables[] = {
{ ngx_string("bytes_received"), NULL, ngx_stream_variable_bytes,
1, 0, 0 },
+ { ngx_string("session_time"), NULL, ngx_stream_variable_session_time,
+ 0, NGX_STREAM_VAR_NOCACHEABLE, 0 },
+
{ ngx_string("connection"), NULL,
ngx_stream_variable_connection, 0, 0, 0 },
@@ -491,6 +496,35 @@ ngx_stream_variable_bytes(ngx_stream_session_t *s,
static ngx_int_t
+ngx_stream_variable_session_time(ngx_stream_session_t *s,
+ ngx_stream_variable_value_t *v, uintptr_t data)
+{
+ u_char *p;
+ ngx_time_t *tp;
+ ngx_msec_int_t ms;
+
+ p = ngx_pnalloc(s->connection->pool, NGX_TIME_T_LEN + 4);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ tp = ngx_timeofday();
+
+ ms = (ngx_msec_int_t)
+ ((tp->sec - s->start_sec) * 1000 + (tp->msec - s->start_msec));
+ ms = ngx_max(ms, 0);
+
+ v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+ v->data = p;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_stream_variable_connection(ngx_stream_session_t *s,
ngx_stream_variable_value_t *v, uintptr_t data)
{