Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus: Add a metric when a worker starts. #1228

Merged
merged 2 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Enable support to log credentials on logging policy [PR #1217](https://github.com/3scale/APIcast/pull/1217) [THREESCALE-5273](https://issues.redhat.com/browse/THREESCALE-5273)
- Add a way to support more than 1000 services in a single instance [PR #1222](https://github.com/3scale/APIcast/pull/1222) [THREESCALE-5308](https://issues.redhat.com/browse/THREESCALE-5308)
- Added new original_request_uri tag on Opentracing [PR #1223](https://github.com/3scale/APIcast/pull/1223) [THREESCALE-5669](https://issues.redhat.com/browse/THREESCALE-5669)

- Added a new metric when the `worker_process` starts [PR #1228](https://github.com/3scale/APIcast/pull/1228) [THREESCALE-5965](https://issues.redhat.com/browse/THREESCALE-5965)

### Fixed

Expand Down
1 change: 1 addition & 0 deletions doc/prometheus-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| total_response_time_seconds | Time needed to sent a response to the client (in seconds) | histogram | service_id, service_system_name | Default |
| upstream_response_time_seconds | Response times from upstream servers (in seconds) | histogram | service_id, service_system_name | Default |
| upstream_status | HTTP status from upstream servers | counter | status, service_id, service_system_name | Default |
| worker_process | Number of times that a worker process has been started. | counter | - | Default |
| threescale_backend_calls | Authorize and report requests to the 3scale backend (Apisonator) | counter | endpoint(authrep, auth, report), status(2xx, 4xx, 5xx) | APIcast |
| batching_policy_auths_cache_hits | Hits in the auths cache of the 3scale batching policy | counter | - | 3scale Batcher |
| batching_policy_auths_cache_misses | Misses in the auths cache of the 3scale batching policy | counter | - | 3scale Batcher |
Expand Down
5 changes: 5 additions & 0 deletions gateway/src/apicast/policy/nginx_metrics/nginx_metrics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ local http_connections_metric = prometheus('gauge', 'nginx_http_connections', '
local shdict_capacity_metric = prometheus('gauge', 'openresty_shdict_capacity', 'OpenResty shared dictionary capacity', {'dict'})
local shdict_free_space_metric = prometheus('gauge', 'openresty_shdict_free_space', 'OpenResty shared dictionary free space', {'dict'})
local apicast_status_metric = prometheus('counter', "apicast_status", "HTTP status generated by APIcast", {"status"})
local worker_process_metric = prometheus('counter', "worker_process", "Number of times that a nginx worker has been started", {})

local response_times = prometheus(
'histogram',
Expand All @@ -89,6 +90,10 @@ local response_times = prometheus(
{ 'service_id', 'service_system_name' }
)

function _M.init_worker()
metrics_updater.inc(worker_process_metric)
end

function _M.init()
errlog.set_filter_level(filter_level())

Expand Down
3 changes: 3 additions & 0 deletions t/prometheus-metrics.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ openresty_shdict_free_space{dict="limiter"} 1032192
openresty_shdict_free_space{dict="locks"} 1032192
openresty_shdict_free_space{dict="prometheus_metrics"} 16662528
openresty_shdict_free_space{dict="rate_limit_headers"} 20840448
# HELP worker_process Number of times that a nginx worker has been started
# TYPE worker_process counter
worker_process{} 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the {} mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's needed.

--- error_code: 200
--- no_error_log
[error]
Expand Down