Skip to content

Commit

Permalink
metric name/label changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhowlett committed Aug 8, 2015
1 parent ada559e commit d7bcea6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ To make things even easier, this repo also includes:

You can run the container like so:

docker run -d -p 8000 mhowlett/ngx_stub_status_prometheus
docker run -d -p 8000 mhowlett/ngx-stub-status-prometheus

This starts up nginx with a test configuration. If you browse to http://127.0.0.1:8000/metrics you should see the status information.

To supply your own configuration, you could add a data volume at the standard nginx config file location:

docker run -d -v mynginx.conf:/etc/nginx/nginx.conf mhowlett/nginx_stub_status_prometheus
docker run -d -v mynginx.conf:/etc/nginx/nginx.conf mhowlett/nginx-stub-status-prometheus

Or you could put it in a different location and specify this as an argument:

docker run -d -v you-will-need-something-here mhowlett/nginx_stub_status_prometheus nginx -c /absolute/path/to/mynginx.conf
docker run -d -v you-will-need-something-here mhowlett/nginx-stub-status-prometheus nginx -c /absolute/path/to/mynginx.conf

### Building

Expand Down
66 changes: 48 additions & 18 deletions ngx_http_stub_status_prometheus_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,24 @@ static ngx_int_t ngx_http_stub_status_prometheus_handler(ngx_http_request_t *r)
}

size =
sizeof("# HELP nginx_active_connections_current Current number of active connections\n") - 1 +
sizeof("# TYPE nginx_active_connections_current gauge\n") - 1 +
sizeof("nginx_active_connections_current \n") +
NGX_ATOMIC_T_LEN +
sizeof("# HELP nginx_connections_current Number of connections currently being processed by nginx\n") - 1 +
sizeof("# TYPE nginx_connections_current gauge\n") - 1 +
sizeof("nginx_connections_current{state=\"active\"} \n") +
sizeof("nginx_connections_current{state=\"reading\"} \n") +
sizeof("nginx_connections_current{state=\"writing\"} \n") +
sizeof("nginx_connections_current{state=\"waiting\"} \n") +
4 * NGX_ATOMIC_T_LEN +
sizeof("# HELP nginx_connections_total Total number of connections processed by nginx\n") - 1 +
sizeof("# TYPE nginx_connections_total counter\n") - 1 +
sizeof("nginx_connections_total{stage=\"accepts\"} \n") +
sizeof("nginx_connections_total{stage=\"handled\"} \n") +
2 * NGX_ATOMIC_T_LEN +
3 * NGX_ATOMIC_T_LEN +
sizeof("# HELP nginx_connections_accepted_total Total number of connections accepted by nginx\n") - 1 +
sizeof("# TYPE nginx_connections_accepted_total counter\n") - 1 +
sizeof("nginx_connections_accepted_total \n") +
NGX_ATOMIC_T_LEN +
sizeof("# HELP nginx_connections_handled_total Total number of connections handled by nginx\n") - 1 +
sizeof("# TYPE nginx_connections_handled_total counter\n") - 1 +
sizeof("nginx_connections_handled_total \n") +
NGX_ATOMIC_T_LEN +
sizeof("# HELP nginx_requests_total Total number of requests processed by nginx\n") - 1 +
sizeof("# TYPE nginx_requests_total counter\n") - 1 +
sizeof("nginx_requests_total \n") +
Expand All @@ -114,19 +120,31 @@ static ngx_int_t ngx_http_stub_status_prometheus_handler(ngx_http_request_t *r)

b->last = ngx_cpymem(
b->last,
"# HELP nginx_connections_current Number of connections currently being processed by nginx\n",
sizeof("# HELP nginx_connections_current Number of connections currently being processed by nginx\n") - 1
"# HELP nginx_active_connections_current Current number of active connections\n",
sizeof("# HELP nginx_active_connections_current Current number of active connections\n") - 1
);

b->last = ngx_cpymem(
b->last,
"# TYPE nginx_connections_current gauge\n",
sizeof("# TYPE nginx_connections_current gauge\n") - 1
"# TYPE nginx_active_connections_current gauge\n",
sizeof("# TYPE nginx_active_connections_current gauge\n") - 1
);

b->last = ngx_sprintf(
b->last,
"nginx_connections_current{state=\"active\"} %uA\n", ac
"nginx_active_connections_current %uA\n", ac
);

b->last = ngx_cpymem(
b->last,
"# HELP nginx_connections_current Number of connections currently being processed by nginx\n",
sizeof("# HELP nginx_connections_current Number of connections currently being processed by nginx\n") - 1
);

b->last = ngx_cpymem(
b->last,
"# TYPE nginx_connections_current gauge\n",
sizeof("# TYPE nginx_connections_current gauge\n") - 1
);

b->last = ngx_sprintf(
Expand All @@ -146,24 +164,36 @@ static ngx_int_t ngx_http_stub_status_prometheus_handler(ngx_http_request_t *r)

b->last = ngx_cpymem(
b->last,
"# HELP nginx_connections_total Total number of connections processed by nginx\n",
sizeof("# HELP nginx_connections_total Total number of connections processed by nginx\n") - 1
"# HELP nginx_connections_accepted_total Total number of connections accepted by nginx\n",
sizeof("# HELP nginx_connections_accepted_total Total number of connections accepted by nginx\n") - 1
);

b->last = ngx_cpymem(
b->last,
"# TYPE nginx_connections_total counter\n",
sizeof("# TYPE nginx_connections_total counter\n") - 1
"# TYPE nginx_connections_accepted_total counter\n",
sizeof("# TYPE nginx_connections_accepted_total counter\n") - 1
);

b->last = ngx_sprintf(
b->last,
"nginx_connections_total{stage=\"accepts\"} %uA\n", ap
"nginx_connections_accepted_total %uA\n", ap
);

b->last = ngx_cpymem(
b->last,
"# HELP nginx_connections_handled_total Total number of connections handled by nginx\n",
sizeof("# HELP nginx_connections_handled_total Total number of connections handled by nginx\n") - 1
);

b->last = ngx_cpymem(
b->last,
"# TYPE nginx_connections_handled_total counter\n",
sizeof("# TYPE nginx_connections_handled_total counter\n") - 1
);

b->last = ngx_sprintf(
b->last,
"nginx_connections_total{stage=\"handled\"} %uA\n", hn
"nginx_connections_handled_total %uA\n", hn
);

b->last = ngx_cpymem(
Expand Down

0 comments on commit d7bcea6

Please sign in to comment.