diff --git a/Dockerfile b/Dockerfile index 7718492..7f27ffa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 5df373d..d506eac 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/assets/nginx.mtail b/assets/nginx.mtail index 41a6090..b0ac633 100644 --- a/assets/nginx.mtail +++ b/assets/nginx.mtail @@ -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"'; @@ -22,44 +26,65 @@ counter nginx_response_size_bytes_sum by vhost, method, code, cache_status /"(?P[[: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]++ }