Welcome! Log In Create A New Profile

Advanced

[PATCH] add $unixtime to http variables

Roberto De Ioris
September 20, 2010 01:44PM
This is a patch to add $unixtime to the http variables.

It simply contains the output of time(NULL)

It could be useful to measure the time between the send
of a request to an upstream module and the time the application
server process it.

Example:

uwsgi_param UWSGI_TIME $unixtime;

Then in your app:

if int(time.time()) - int(env['UWSGI_TIME']):
print "*** SYSTEM IS RESPONDING SLOWLY ***"

I do not know if it is better to name it $time instead of $unixtime...


--- src/http/ngx_http_variables.c 2010-06-23 17:31:33.000000000 +0200
+++ ../nginx-ok/src/http/ngx_http_variables.c 2010-09-20
19:24:57.000000000 +0200
@@ -93,6 +93,9 @@
static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);

+static ngx_int_t ngx_http_variable_unixtime(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
+
/*
* TODO:
* Apache CGI: AUTH_TYPE, PATH_INFO (null), PATH_TRANSLATED
@@ -254,6 +257,9 @@
{ ngx_string("pid"), NULL, ngx_http_variable_pid,
0, 0, 0 },

+ { ngx_string("unixtime"), NULL, ngx_http_variable_unixtime,
+ 0, 0, 0 },
+
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
};

@@ -1640,6 +1646,26 @@


static ngx_int_t
+ngx_http_variable_unixtime(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ u_char *p;
+
+ p = ngx_pnalloc(r->pool, NGX_INT64_LEN);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ v->len = ngx_sprintf(p, "%T", time(NULL)) - p;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+ v->data = p;
+
+ return NGX_OK;
+}
+
+static ngx_int_t
ngx_http_variable_pid(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{


--
Roberto De Ioris
http://unbit.it

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

[PATCH] add $unixtime to http variables

Roberto De Ioris September 20, 2010 01:44PM

Re: [PATCH] add $unixtime to http variables

Roberto De Ioris September 20, 2010 02:54PM

Re: [PATCH] add $unixtime to http variables

Boris Dolgov September 20, 2010 03:28PM

Re: [PATCH] add $unixtime to http variables

Roberto De Ioris September 21, 2010 01:08AM

Re: [PATCH] add $unixtime to http variables

Kirill A. Korinskiy September 21, 2010 03:42AM

Re: [PATCH] add $unixtime to http variables

Maxim Dounin September 21, 2010 07:32AM

Re: [PATCH] add $unixtime to http variables

Roberto De Ioris September 22, 2010 02:00AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 323
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready