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

Nginx multi servers #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repository:
path: github.com/hnlq715/nginx-vts-exporter
path: github.com/StereoRu/nginx-vts-exporter
build:
flags: -a -tags netgo
ldflags: |
Expand All @@ -19,4 +19,4 @@ crossbuild:
- darwin/amd64
- darwin/386
- windows/amd64
- windows/386
- windows/386
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
FROM alpine:latest
MAINTAINER Sophos <[email protected]>

VOLUME /etc/nginx-vts-exporter/

WORKDIR /bin
COPY bin/nginx-vts-exporter /bin/
COPY bin/config.json /etc/nginx-vts-exporter/
COPY docker-entrypoint.sh /bin/
RUN chmod +x /bin/nginx-vts-exporter

Expand Down
42 changes: 28 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Simple server that scrapes Nginx vts stats and exports them via HTTP for Prometh
* [Dependency](#dependency)
* [Download](#download)
* [Compile](#compile)
* [Config](#config)
* [Run](#run)
* [Dockerized](#dockerized)
* [Environment variables](#environment-variables)
Expand Down Expand Up @@ -38,6 +39,14 @@ export the binary inside ./bin/ directory
./build-binary.sh
```

## Config
The application can have a configuration file.
By default, it is located in ```/etc/nginx-vts-exporter/config.json```
This can be overridden via the command line option ```-config.file /some/path/config.json```
Parameters specified in the configuration file are less priority than command line parameters or environment variables.
If the command-line parameter ```-nginx.scrape_uri http://somedomain.com/status/format/json``` is specified, it will be added to those listed in the configuration file.
If there is no parameter nginxScrapeURIs.hostName in the configuration file, it will be taken from the data nginx-vts-module

## Run

``` shell
Expand Down Expand Up @@ -89,13 +98,14 @@ Documents about exposed Prometheus metrics

Nginx data | Name | Exposed informations
------------------ | ------------------------------- | ------------------------
**Connections** | `{NAMESPACE}_server_connections`| status [active, reading, writing, waiting, accepted, handled]
**Connections** | `{NAMESPACE}_server_connections`| status [active, reading, writing, waiting, accepted, handled], hostName _(server hostName or hostName from config)_


**Metrics output example**

``` txt
# Server Connections
nginx_server_connections{status="accepted"} 70606
nginx_server_connections{status="accepted", hostName="ngx_host"} 70606
```

### Server zones
Expand All @@ -104,21 +114,25 @@ nginx_server_connections{status="accepted"} 70606

Nginx data | Name | Exposed informations
------------------ | ------------------------------- | ------------------------
**Requests** | `{NAMESPACE}_server_requests` | code [2xx, 3xx, 4xx, 5xx, total], host _(or domain name)_
**Bytes** | `{NAMESPACE}_server_bytes` | direction [in, out], host _(or domain name)_
**Cache** | `{NAMESPACE}_server_cache` | status [bypass, expired, hit, miss, revalidated, scarce, stale, updating], host _(or domain name)_
**Requests** | `{NAMESPACE}_server_requests` | code [2xx, 3xx, 4xx, 5xx, total], host _(or domain name)_, hostName _(server hostName or hostName from config)_
**Bytes** | `{NAMESPACE}_server_bytes` | direction [in, out], host _(or domain name)_, hostName _(server hostName or hostName from config)_
**Cache** | `{NAMESPACE}_server_cache` | status [bypass, expired, hit, miss, revalidated, scarce, stale, updating], host _(or domain name)_, hostName _(server hostName or hostName from config)_
**requestMsec** | `{NAMESPACE}_server_requestMsec` | host _(or domain name)_, hostName _(server hostName or hostName from config)_

**Metrics output example**

``` txt
# Server Requests
nginx_server_requests{code="1xx",host="test.domain.com"} 0
nginx_server_requests{code="1xx",host="test.domain.com", hostName="ngx_host"} 0

# Server Bytes
nginx_server_bytes{direction="in",host="test.domain.com"} 21
nginx_server_bytes{direction="in",host="test.domain.com", hostName="ngx_host"} 21

# Server Cache
nginx_server_cache{host="test.domain.com",status="bypass"} 2
nginx_server_cache{host="test.domain.com",status="bypass", hostName="ngx_host"} 2

# Server RequestMsec
nginx_server_requestMsec{host="test.domain.com", hostName="ngx_host"} 18
```

### Upstreams
Expand All @@ -127,19 +141,19 @@ nginx_server_cache{host="test.domain.com",status="bypass"} 2

Nginx data | Name | Exposed informations
------------------ | ------------------------------- | ------------------------
**Requests** | `{NAMESPACE}_upstream_requests` | code [2xx, 3xx, 4xx, 5xx and total], upstream _(or upstream name)_
**Bytes** | `{NAMESPACE}_upstream_bytes` | direction [in, out], upstream _(or upstream name)_
**Response time** | `{NAMESPACE}_upstream_response` | backend (or server), in_bytes, out_bytes, upstream _(or upstream name)_
**Requests** | `{NAMESPACE}_upstream_requests` | code [2xx, 3xx, 4xx, 5xx and total], upstream _(or upstream name)_, hostName _(server hostName or hostName from config)_
**Bytes** | `{NAMESPACE}_upstream_bytes` | direction [in, out], upstream _(or upstream name)_, hostName _(server hostName or hostName from config)_
**Response time** | `{NAMESPACE}_upstream_response` | backend (or server), in_bytes, out_bytes, upstream _(or upstream name)_, hostName _(server hostName or hostName from config)_

**Metrics output example**

``` txt
# Upstream Requests
nginx_upstream_requests{code="1xx",upstream="XXX-XXXXX-3000"} 0
nginx_upstream_requests{code="1xx",upstream="XXX-XXXXX-3000", hostName="ngx_host"} 0

# Upstream Bytes
nginx_upstream_bytes{direction="in",upstream="XXX-XXXXX-3000"} 0
nginx_upstream_bytes{direction="in",upstream="XXX-XXXXX-3000", hostName="ngx_host"} 0

# Upstream Response time
nginx_upstream_response{backend="10.2.15.10:3000",upstream="XXX-XXXXX-3000"} 99
nginx_upstream_response{backend="10.2.15.10:3000",upstream="XXX-XXXXX-3000", hostName="ngx_host"} 99
```
11 changes: 11 additions & 0 deletions bin/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"telemetryAddress": ":9913",
"telemetryEndpoint": "/metrics",
"metricsNamespace": "nginx",
"nginxScrapeURIs": [
{
"hostName": "localhost",
"uri": "http://localhost/status/format/json"
}
]
}
Binary file modified bin/nginx-vts-exporter
100644 → 100755
Binary file not shown.
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
set -eo pipefail
default_status="$NGIX_HOST/status/format/json"
default_status="$NGINX_HOST/status/format/json"
NGINX_STATUS=${NGINX_STATUS:-$default_status}
METRICS_NS=${METRICS_NS:-$DEFAULT_METRICS_NS}

Expand Down
Loading