Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
Hopefully properly count the prometheus histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernhaeuser committed Nov 13, 2018
1 parent 2c8e374 commit 303207b
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions assets/nginx.mtail
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
counter nginx_requests_total by vhost, method, code, cache_status
counter nginx_request_duration_milliseconds_sum by le, vhost, method, code
counter nginx_response_size_bytes_sum by vhost, method, code, cache_status

counter nginx_request_duration_milliseconds_bucket by le, vhost, method, code
counter nginx_request_duration_milliseconds_sum by vhost, method, code
counter nginx_request_duration_milliseconds_count by vhost, method, code


# log_format mtail '$server_name $remote_addr - $remote_user [$time_local] '
# '"$request" $status $bytes_sent $request_time'
# '"$http_referer" "$http_user_agent" "$content_type" "$upstream_cache_status"';
Expand All @@ -22,44 +26,68 @@ counter nginx_response_size_bytes_sum by vhost, method, code, cache_status
/"(?P<upstream_cache_status>[[:print:]]+)?"/ +
/$/ {
nginx_requests_total[$vhost][tolower($request_method)][$status][tolower($upstream_cache_status)]++

nginx_response_size_bytes_sum[$vhost][tolower($request_method)][$status][tolower($upstream_cache_status)] += $bytes_sent

nginx_request_duration_milliseconds_count[$vhost][tolower($request_method)][$status][tolower($upstream_cache_status)]++
nginx_request_duration_milliseconds_sum[$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds < 100

$request_seconds * 1000 + $request_milliseconds < 100 {
nginx_request_duration_milliseconds_sum["100"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["100"][$vhost][tolower($request_method)][$status]++
} else {
nginx_request_duration_milliseconds_bucket["100"][$vhost][tolower($request_method)][$status] += 0
}

$request_seconds * 1000 + $request_milliseconds < 200 {
nginx_request_duration_milliseconds_sum["200"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["200"][$vhost][tolower($request_method)][$status]++
} else {
nginx_request_duration_milliseconds_bucket["200"][$vhost][tolower($request_method)][$status] += 0
}

$request_seconds * 1000 + $request_milliseconds < 300 {
nginx_request_duration_milliseconds_sum["300"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["300"][$vhost][tolower($request_method)][$status]++
} else {
nginx_request_duration_milliseconds_bucket["300"][$vhost][tolower($request_method)][$status] += 0
}

$request_seconds * 1000 + $request_milliseconds < 500 {
nginx_request_duration_milliseconds_sum["500"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["500"][$vhost][tolower($request_method)][$status]++
} else {
nginx_request_duration_milliseconds_bucket["500"][$vhost][tolower($request_method)][$status] += 0
}

$request_seconds * 1000 + $request_milliseconds < 800 {
nginx_request_duration_milliseconds_sum["800"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["800"][$vhost][tolower($request_method)][$status]++
} else {
nginx_request_duration_milliseconds_bucket["800"][$vhost][tolower($request_method)][$status] += 0
}

$request_seconds * 1000 + $request_milliseconds < 1300 {
nginx_request_duration_milliseconds_sum["1300"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["1300"][$vhost][tolower($request_method)][$status]++
} else {
nginx_request_duration_milliseconds_bucket["1300"][$vhost][tolower($request_method)][$status] += 0
}

$request_seconds * 1000 + $request_milliseconds < 2100 {
nginx_request_duration_milliseconds_sum["2100"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["2100"][$vhost][tolower($request_method)][$status]++
} else {
nginx_request_duration_milliseconds_bucket["2100"][$vhost][tolower($request_method)][$status] += 0
}

$request_seconds * 1000 + $request_milliseconds < 3400 {
nginx_request_duration_milliseconds_sum["3400"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["3400"][$vhost][tolower($request_method)][$status] ++
} else {
nginx_request_duration_milliseconds_bucket["3400"][$vhost][tolower($request_method)][$status] += 0
}

$request_seconds * 1000 + $request_milliseconds < 5500 {
nginx_request_duration_milliseconds_sum["5500"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds
nginx_request_duration_milliseconds_bucket["5500"][$vhost][tolower($request_method)][$status]++
} else {
nginx_request_duration_milliseconds_bucket["5500"][$vhost][tolower($request_method)][$status] += 0
}

nginx_request_duration_milliseconds_bucket["+Inf"][$vhost][tolower($request_method)][$status]++

nginx_request_duration_milliseconds_sum["+Inf"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds

}

0 comments on commit 303207b

Please sign in to comment.