diff --git a/CHANGELOG.md b/CHANGELOG.md index f8de430..b706c76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/nginx_role/tree/develop) +### Fixed +- *[#65](https://github.com/idealista/nginx_role/issues/65) No value passed error in prometheus metrics* @jmonterrubio + ## [2.1.0](https://github.com/idealista/nginx_role/tree/2.1.0) (2019-09-09) [Full Changelog](https://github.com/idealista/nginx_role/compare/2.1.0...2.0.1) ### Fixed diff --git a/templates/metrics/prometheus.conf.j2 b/templates/metrics/prometheus.conf.j2 index 59e1a2f..ef5b0ef 100644 --- a/templates/metrics/prometheus.conf.j2 +++ b/templates/metrics/prometheus.conf.j2 @@ -85,16 +85,20 @@ log_by_lua_block { upstream_bytes_sent = getWithIndex(ngx.var.upstream_bytes_sent, idx) end http_upstream_requests:inc(1, {addr, upstream_status}) - http_upstream_response_time:observe(tonumber(upstream_response_time), {addr}) - http_upstream_header_time:observe(tonumber(upstream_header_time), {addr}) + if upstream_response_time ~= nil and tonumber(upstream_response_time) ~= nil then + http_upstream_response_time:observe(tonumber(upstream_response_time), {addr}) + end + if http_upstream_header_time ~= nil and tonumber(http_upstream_header_time) ~= nil then + http_upstream_header_time:observe(tonumber(upstream_header_time), {addr}) + end -- ngx.config.nginx_version >= 1011004 - if upstream_first_byte_time ~= nil then + if upstream_first_byte_time ~= nil and tonumber(upstream_first_byte_time) ~= nil then http_upstream_first_byte_time:observe(tonumber(upstream_first_byte_time), {addr}) end - if upstream_connect_time ~= nil then + if upstream_connect_time ~= nil and tonumber(upstream_connect_time) ~= nil then http_upstream_connect_time:observe(tonumber(upstream_connect_time), {addr}) end - if upstream_session_time ~= nil then + if upstream_session_time ~= nil and tonumber(upstream_session_time) ~= nil then http_upstream_session_time:observe(tonumber(upstream_session_time), {addr}) end if upstream_bytes_received ~= nil then