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

Commit

Permalink
Merge pull request #9 from rebuy-de/histogram
Browse files Browse the repository at this point in the history
Hopefully properly count the prometheus histogram
  • Loading branch information
bjoernhaeuser authored Nov 26, 2018
2 parents 2c8e374 + f298b1d commit 48776da
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
19 changes: 16 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
FROM ndiazg/nginx-prometheus-exporter as mtail
FROM alpine:3.8 as mtail

ENV GOPATH /go
ENV PATH /go/bin:$PATH

RUN apk add --no-cache --update musl musl-dev go git bash make

RUN mkdir -p /go/src/github.com/google/ && \
git clone https://github.com/google/mtail.git /go/src/github.com/google/mtail && \
cd /go/src/github.com/google/mtail && \
git checkout v3.0.0-rc17 && \
make install_deps && make install

RUN ls -la /go/bin

FROM fish/nginx-exporter:v0.1.0 as status

FROM alpine:3.7
FROM alpine:3.8

RUN apk add --no-cache supervisor

COPY --from=mtail /usr/local/bin/mtail /usr/local/bin/mtail
COPY --from=mtail /go/bin/mtail /usr/local/bin/mtail
COPY --from=status /usr/local/bin/nginx_exporter /usr/local/bin/nginx_exporter
COPY assets/merger.yaml /etc/exporter-merger.yaml
COPY assets/supervisord.conf /etc/supervisord.conf
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A meta nginx exporter that combines two different exporters
## References

* The mtail programm is based on
[ndiazg/nginx-prometheus-exporter](https://github.com/ndiazg/nginx-prometheus-exporter).
[google/mtail](https://github.com/google/mtail).
* The status page exporter is from
[discordianfish/nginx_exporter](https://github.com/discordianfish/nginx_exporter).
* The exporter merger is from
Expand Down Expand Up @@ -92,7 +92,7 @@ The exporter provides three metric endpoints:

- `3093` -- mtail exporter
- `9113` -- status page exporter
- `9397` -- merged mertrics from mtail and status page exporter
- `9397` -- merged metrics from mtail and status page exporter

### Kubernetes

Expand Down
49 changes: 37 additions & 12 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,65 @@ 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]++
nginx_request_duration_milliseconds_sum[$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds

$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_sum["+Inf"][$vhost][tolower($request_method)][$status] += $request_seconds * 1000 + $request_milliseconds

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

0 comments on commit 48776da

Please sign in to comment.