From d4937e29f1cbb7df3d96ecda1e8e74c99883168f Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Fri, 31 Jul 2020 03:51:56 -0400 Subject: [PATCH] [mod_accesslog,mod_rrdtool] HTTP/2 basic accounting Note: rrdtool counts do not include HTTP/2 protocol overhead. Continue to count mod_rrdtool per request rather than per connection so that data is updated after each request, rather than aggregated to the end of a potentially long-lived connection with many keep-alives. --- src/mod_accesslog.c | 12 +++++++++--- src/mod_rrdtool.c | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mod_accesslog.c b/src/mod_accesslog.c index 05fd3bc0..b4fc21b7 100644 --- a/src/mod_accesslog.c +++ b/src/mod_accesslog.c @@ -982,7 +982,9 @@ static int log_access_record (const request_st * const r, buffer * const b, form case FORMAT_BYTES_OUT_NO_HEADER: { - off_t bytes = con->bytes_written - r->bytes_written_ckpt; + off_t bytes = r->http_version <= HTTP_VERSION_1_1 + ? con->bytes_written - r->bytes_written_ckpt + : r->write_queue->bytes_out; if (bytes > 0) { bytes -= (off_t)r->resp_header_len; buffer_append_int(b, bytes > 0 ? bytes : 0); @@ -1022,7 +1024,9 @@ static int log_access_record (const request_st * const r, buffer * const b, form break; case FORMAT_BYTES_OUT: { - off_t bytes = con->bytes_written - r->bytes_written_ckpt; + off_t bytes = r->http_version <= HTTP_VERSION_1_1 + ? con->bytes_written - r->bytes_written_ckpt + : r->write_queue->bytes_out; if (bytes > 0) { buffer_append_int(b, bytes); } else { @@ -1032,7 +1036,9 @@ static int log_access_record (const request_st * const r, buffer * const b, form } case FORMAT_BYTES_IN: { - off_t bytes = con->bytes_read - r->bytes_read_ckpt; + off_t bytes = r->http_version <= HTTP_VERSION_1_1 + ? con->bytes_read - r->bytes_read_ckpt + : r->read_queue->bytes_in + (off_t)r->rqst_header_len; if (bytes > 0) { buffer_append_int(b, bytes); } else { diff --git a/src/mod_rrdtool.c b/src/mod_rrdtool.c index dfdb0e97..6fd376d0 100644 --- a/src/mod_rrdtool.c +++ b/src/mod_rrdtool.c @@ -424,8 +424,14 @@ REQUESTDONE_FUNC(mod_rrd_account) { rrd_config * const rrd = p->conf.rrd; if (NULL == rrd) return HANDLER_GO_ON; ++rrd->requests; + if (r->http_version <= HTTP_VERSION_1_1) { rrd->bytes_written += (r->con->bytes_written - r->bytes_written_ckpt); rrd->bytes_read += (r->con->bytes_read - r->bytes_read_ckpt); + } + else { + rrd->bytes_written += r->write_queue->bytes_out; + rrd->bytes_read += r->read_queue->bytes_in; + } return HANDLER_GO_ON; }