forked from mailru/graphite-nginx-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphite_module.patch
158 lines (140 loc) · 5.37 KB
/
graphite_module.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
diff -u3 -p -r a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c 2012-11-12 22:00:32.000000000 +0400
+++ b/src/event/ngx_event_openssl.c 2012-12-17 16:30:47.639146541 +0400
@@ -604,6 +604,16 @@ ngx_ssl_handshake(ngx_connection_t *c)
ngx_ssl_clear_error(c->log);
+#if (NGX_GRAPHITE)
+ struct timeval tp;
+ if (c->ssl->handshake_process == 0) {
+ c->ssl->handshake_process = 1;
+ ngx_gettimeofday(&tp);
+ c->ssl->handshake_start_sec = tp.tv_sec;
+ c->ssl->handshake_start_msec = tp.tv_usec / 1000;
+ }
+#endif
+
n = SSL_do_handshake(c->ssl->connection);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_do_handshake: %d", n);
@@ -667,6 +677,12 @@ ngx_ssl_handshake(ngx_connection_t *c)
c->ssl->handshaked = 1;
+#if (NGX_GRAPHITE)
+ c->ssl->handshake_process = 0;
+ ngx_gettimeofday(&tp);
+ c->ssl->handshake_end_sec = tp.tv_sec;
+ c->ssl->handshake_end_msec = tp.tv_usec / 1000;
+#endif
c->recv = ngx_ssl_recv;
c->send = ngx_ssl_write;
c->recv_chain = ngx_ssl_recv_chain;
diff -u3 -p -r a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
--- a/src/event/ngx_event_openssl.h 2012-11-13 14:42:16.000000000 +0400
+++ b/src/event/ngx_event_openssl.h 2012-12-17 16:30:47.639146541 +0400
@@ -42,6 +42,14 @@ typedef struct {
ngx_event_handler_pt saved_read_handler;
ngx_event_handler_pt saved_write_handler;
+#if (NGX_GRAPHITE)
+ ngx_uint_t handshake_process;
+ time_t handshake_start_sec;
+ ngx_msec_t handshake_start_msec;
+ time_t handshake_end_sec;
+ ngx_msec_t handshake_end_msec;
+#endif
+
unsigned handshaked:1;
unsigned renegotiation:1;
unsigned buffer:1;
diff -u3 -p -r a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
--- a/src/http/modules/ngx_http_gzip_filter_module.c 2012-02-13 19:23:43.000000000 +0400
+++ b/src/http/modules/ngx_http_gzip_filter_module.c 2012-12-17 16:30:52.299146347 +0400
@@ -363,6 +363,16 @@ ngx_http_gzip_body_filter(ngx_http_reque
}
}
+#if (NGX_GRAPHITE)
+ struct timeval tp;
+ if (r->gzip_process == 0) {
+ r->gzip_process = 1;
+ ngx_gettimeofday(&tp);
+ r->gzip_start_sec = tp.tv_sec;
+ r->gzip_start_msec = tp.tv_usec / 1000;
+ }
+#endif
+
if (in) {
if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) {
goto failed;
@@ -432,6 +442,11 @@ ngx_http_gzip_body_filter(ngx_http_reque
if (ctx->out == NULL) {
ngx_http_gzip_filter_free_copy_buf(r, ctx);
+#if (NGX_GRAPHITE)
+ ngx_gettimeofday(&tp);
+ r->gzip_end_sec = tp.tv_sec;
+ r->gzip_end_msec = tp.tv_usec / 1000;
+#endif
return ctx->busy ? NGX_AGAIN : NGX_OK;
}
@@ -456,6 +471,12 @@ ngx_http_gzip_body_filter(ngx_http_reque
ctx->nomem = 0;
if (ctx->done) {
+
+#if (NGX_GRAPHITE)
+ ngx_gettimeofday(&tp);
+ r->gzip_end_sec = tp.tv_sec;
+ r->gzip_end_msec = tp.tv_usec / 1000;
+#endif
return rc;
}
}
@@ -474,6 +495,12 @@ failed:
ngx_http_gzip_filter_free_copy_buf(r, ctx);
+#if (NGX_GRAPHITE)
+ ngx_gettimeofday(&tp);
+ r->gzip_end_sec = tp.tv_sec;
+ r->gzip_end_msec = tp.tv_usec / 1000;
+#endif
+
return NGX_ERROR;
}
diff -u3 -p -r a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c 2012-09-24 23:06:48.000000000 +0400
+++ b/src/http/ngx_http_core_module.c 2012-12-17 17:29:35.654998991 +0400
@@ -1393,7 +1393,19 @@ ngx_http_core_content_phase(ngx_http_req
if (r->content_handler) {
r->write_event_handler = ngx_http_request_empty_handler;
- ngx_http_finalize_request(r, r->content_handler(r));
+#if (NGX_GRAPHITE)
+ struct timeval tp;
+ ngx_gettimeofday(&tp);
+ r->content_start_sec = tp.tv_sec;
+ r->content_start_msec = tp.tv_usec / 1000;
+#endif
+ ngx_int_t rc = r->content_handler(r);
+#if (NGX_GRAPHITE)
+ ngx_gettimeofday(&tp);
+ r->content_end_sec = tp.tv_sec;
+ r->content_end_msec = tp.tv_usec / 1000;
+#endif
+ ngx_http_finalize_request(r, rc);
return NGX_OK;
}
diff -u3 -p -r a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
--- a/src/http/ngx_http_request.h 2012-07-02 21:41:52.000000000 +0400
+++ b/src/http/ngx_http_request.h 2012-12-17 17:05:39.755059043 +0400
@@ -562,6 +562,21 @@ struct ngx_http_request_s {
unsigned http_minor:16;
unsigned http_major:16;
+
+#if (NGX_GRAPHITE)
+ time_t content_start_sec;
+ ngx_msec_t content_start_msec;
+ time_t content_end_sec;
+ ngx_msec_t content_end_msec;
+#endif
+
+#if ((NGX_HTTP_GZIP) && (NGX_GRAPHITE))
+ ngx_uint_t gzip_process;
+ time_t gzip_start_sec;
+ ngx_msec_t gzip_start_msec;
+ time_t gzip_end_sec;
+ ngx_msec_t gzip_end_msec;
+#endif
};