forked from mailru/graphite-nginx-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphite_module_v1_7_7.patch
123 lines (109 loc) · 3.98 KB
/
graphite_module_v1_7_7.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
diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
index 2c4e114..98ae6ba 100644
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -1228,6 +1228,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);
@@ -1307,6 +1317,13 @@ ngx_ssl_handshake(ngx_connection_t *c)
#endif
#endif
+#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
+
return NGX_OK;
}
diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h
index 2a14980..daac038 100644
--- a/src/event/ngx_event_openssl.h
+++ b/src/event/ngx_event_openssl.h
@@ -79,6 +79,14 @@ struct ngx_ssl_connection_s {
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 --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index 287fd36..656dc75 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -424,7 +424,16 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
}
+#if (NGX_GRAPHITE)
+ struct timeval start_tp;
+ ngx_gettimeofday(&start_tp);
+#endif
rc = ngx_http_gzip_filter_deflate(r, ctx);
+#if (NGX_GRAPHITE)
+ struct timeval stop_tp;
+ ngx_gettimeofday(&stop_tp);
+ r->gzip_time += (stop_tp.tv_sec - start_tp.tv_sec) * 1000 + (stop_tp.tv_usec - start_tp.tv_usec) / 1000.0;
+#endif
if (rc == NGX_OK) {
break;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 7e40e78..3d7336d 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1384,7 +1395,17 @@ ngx_http_core_content_phase(ngx_http_request_t *r,
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 start_tp;
+ ngx_gettimeofday(&start_tp);
+#endif
+ ngx_int_t rc = r->content_handler(r);
+#if (NGX_GRAPHITE)
+ struct timeval stop_tp;
+ ngx_gettimeofday(&stop_tp);
+ r->content_time += (stop_tp.tv_sec - start_tp.tv_sec) * 1000 + (stop_tp.tv_usec - start_tp.tv_usec) / 1000.0;
+#endif
+ ngx_http_finalize_request(r, rc);
return NGX_OK;
}
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 283c582..68690ec 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -580,6 +580,20 @@ struct ngx_http_request_s {
unsigned http_minor:16;
unsigned http_major:16;
+
+#define NGX_GRAPHITE_PATCH
+
+#if (NGX_GRAPHITE)
+ double content_time;
+#endif
+
+#if ((NGX_HTTP_GZIP) && (NGX_GRAPHITE))
+ double gzip_time;
+#endif
+
+#if (NGX_GRAPHITE)
+ double lua_time;
+#endif
};