From 439075199cc3535b6a96cd83c1188d1b46b88b87 Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sat, 28 Oct 2023 17:16:38 +0000 Subject: [PATCH 1/9] Added statistics monitoring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Exposing zone statistic for Bind9 in web interface. https://kb.isc.org/docs/monitoring-recommendations-for-bind-9 Co-authored-by: William Bergmann Børresen --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index e0b39ab..7604baf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,7 @@ services: ports: - ${DNS_BIND_IP}:53:53/udp - ${DNS_BIND_IP}:53:53/tcp + - ${DNS_BIND_IP}:8053:8053/tcp ## HTTPS requests are now handled in monolithic directly ## you could choose to return to sniproxy if desired From 8175aadfc7546fc6362bcac70b37396e01380797 Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sat, 28 Oct 2023 17:26:50 +0000 Subject: [PATCH 2/9] Reverted port allocation to bind9 metrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: William Bergmann Børresen --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7604baf..e0b39ab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,6 @@ services: ports: - ${DNS_BIND_IP}:53:53/udp - ${DNS_BIND_IP}:53:53/tcp - - ${DNS_BIND_IP}:8053:8053/tcp ## HTTPS requests are now handled in monolithic directly ## you could choose to return to sniproxy if desired From 6e40b5bc3e36cf0ea598b0b20414a42491ca8bef Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sat, 28 Oct 2023 17:45:26 +0000 Subject: [PATCH 3/9] Added exporter for Bind metrics in prometheus format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: William Bergmann Børresen --- docker-compose.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index e0b39ab..a1dafb4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,23 @@ services: ports: - ${DNS_BIND_IP}:53:53/udp - ${DNS_BIND_IP}:53:53/tcp + networks: + default: + metrics: + aliases: + - lancache-dns + +## Metrics exporter for bind. This can be disabled, if you don't want to export metrics to prometheus + + metrics: + image: prometheuscommunity/bind-exporter:v0.3.0 + args: + - --web.listen-address=:9119 # This is the port the exporter will listen on + - --bind.stats-url http://lancache-dns:8053 + networks: + metrics: + aliases: + - bind-exporter ## HTTPS requests are now handled in monolithic directly ## you could choose to return to sniproxy if desired @@ -29,3 +46,9 @@ services: volumes: - ${CACHE_ROOT}/cache:/data/cache - ${CACHE_ROOT}/logs:/data/logs + networks: + default: + +networks: + default: + metrics: From 10ac283948780272346ba7fc38219cc18b6b8de8 Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sat, 28 Oct 2023 18:08:45 +0000 Subject: [PATCH 4/9] Added NGINX prometheus exporter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: William Bergmann Børresen --- docker-compose.yml | 49 +++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a1dafb4..f4eb114 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,22 +10,10 @@ services: - ${DNS_BIND_IP}:53:53/tcp networks: default: - metrics: + dns-metrics: aliases: - lancache-dns -## Metrics exporter for bind. This can be disabled, if you don't want to export metrics to prometheus - - metrics: - image: prometheuscommunity/bind-exporter:v0.3.0 - args: - - --web.listen-address=:9119 # This is the port the exporter will listen on - - --bind.stats-url http://lancache-dns:8053 - networks: - metrics: - aliases: - - bind-exporter - ## HTTPS requests are now handled in monolithic directly ## you could choose to return to sniproxy if desired # @@ -48,7 +36,40 @@ services: - ${CACHE_ROOT}/logs:/data/logs networks: default: + monolithic-metrics: + aliases: + - lancache-monolithic + +## Metrics exporter for DNS and Monolithic +## This can be disabled, if you don't want to export metrics to prometheus +## To disable, comment out the next two services + + dns-metrics: + image: prometheuscommunity/bind-exporter:v0.3.0 + args: + - --web.listen-address=:9119 # This is the port the exporter will listen on + - --bind.stats-url http://lancache-dns:8053 + ports: + - ${METRIC_BIND_IP:-${DNS_BIND_IP}}:9119:9119 + networks: + dns-metrics: + aliases: + - bind-exporter + + monolithic-metrics: + image: nginx/nginx-prometheus-exporter:0.10.0 + args: + - --nginx.scrape-uri=http://lancache-monolithic:8080/nginx_status + ports: + - ${METRIC_BIND_IP:-${DNS_BIND_IP}}:9113:9113 + networks: + monolithic-metrics: + aliases: + - monolithic-exporter + +## Network definitions, do not change these, unless you know what you are doing networks: default: - metrics: + dns-metrics: + monolithic-metrics: From a2f46d00c9cb5f7ff5dccd8fe67f3e052afc3839 Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sat, 28 Oct 2023 19:37:42 +0000 Subject: [PATCH 5/9] Added healthcheck to services to improve stability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also adds labels for the ease of filtering in Prometheus/Grafana Co-authored-by: William Bergmann Børresen --- .env | 4 ++++ docker-compose.yml | 40 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.env b/.env index a3f3a3c..0fc8a24 100644 --- a/.env +++ b/.env @@ -12,6 +12,10 @@ LANCACHE_IP=10.0.39.1 ## IP address on the host that the DNS server should bind to DNS_BIND_IP=10.0.39.1 +## IP address for metrics exporters to bind to +## Leave blank to bind to DNS_BIND_IP +METRIC_BIND_IP= + ## DNS Resolution for forwarded DNS lookups UPSTREAM_DNS=8.8.8.8 diff --git a/docker-compose.yml b/docker-compose.yml index f4eb114..2b9d93e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,13 @@ services: ports: - ${DNS_BIND_IP}:53:53/udp - ${DNS_BIND_IP}:53:53/tcp + labels: + lancache.dns: "true" + healthcheck: + test: ["CMD", "dig", "+norecurse", "+short" ,"+retry=0", "@127.0.0.1", "lancache.net"] + interval: 10s + timeout: 5s + retries: 5 networks: default: dns-metrics: @@ -34,6 +41,13 @@ services: volumes: - ${CACHE_ROOT}/cache:/data/cache - ${CACHE_ROOT}/logs:/data/logs + labels: + lancache.monolithic: "true" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/nginx_status"] + interval: 10s + timeout: 5s + retries: 5 networks: default: monolithic-metrics: @@ -46,11 +60,22 @@ services: dns-metrics: image: prometheuscommunity/bind-exporter:v0.3.0 - args: + restart: *restart-policy + command: - --web.listen-address=:9119 # This is the port the exporter will listen on - - --bind.stats-url http://lancache-dns:8053 + - --bind.stats-url=http://lancache-dns:8053 ports: - ${METRIC_BIND_IP:-${DNS_BIND_IP}}:9119:9119 + labels: + lancache.dns.metrics: "true" + depends_on: + dns: + condition: service_healthy + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:9119/metrics"] + interval: 10s + timeout: 5s + retries: 5 networks: dns-metrics: aliases: @@ -58,10 +83,19 @@ services: monolithic-metrics: image: nginx/nginx-prometheus-exporter:0.10.0 - args: + restart: *restart-policy + command: - --nginx.scrape-uri=http://lancache-monolithic:8080/nginx_status ports: - ${METRIC_BIND_IP:-${DNS_BIND_IP}}:9113:9113 + labels: + lancache.monolithic.metrics: "true" + depends_on: + monolithic: + condition: service_healthy + # healthcheck: + # Healthcheck cannot be done on image, as it is a scratch image + # Without any healthcheck functionality networks: monolithic-metrics: aliases: From eb84ce27f1e5fb9cac4246520e13c35b230c6a5d Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sat, 28 Oct 2023 19:38:37 +0000 Subject: [PATCH 6/9] Documented `METRIC_BIND_IP` in README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: William Bergmann Børresen --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 6604ab4..27aa2bc 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,46 @@ There are a few ways to make your local network aware of the cache server. This allows the `lancache-dns` service to provide clients with the appropriate local IPs for cached services, and all other requests will be passed to `UPSTREAM_DNS`. 2. Use the configuration generators available from [UKLANs' cache-domains](https://github.com/uklans/cache-domains) project to create configuration data to load into your network's existing DNS infrastructure +## `METRIC_BIND_IP` +This sets the IP address that the metric services will listen on. If your cache host has exactly one IP address +(eg. `192.168.0.10`), specify that here. If your cache host has multiple IPs, specify exactly one and use that. + +This may be used to segregate the cache and dns ip endpoints from the metrics endpoints. + +For prometheus to scrape the metrics, you will need to add the following to your prometheus.yml file: + +> Please note, that Prometheus is not included in this docker-compose stack. + +```yaml +scrape_configs: + - job_name: 'lancache' + static_configs: + - targets: [':'] +``` + +- `` is the IP address you set in the `METRIC_BIND_IP` environment variable +- `` is the port of the metric services. Please see below for the ports used by the metric services. + +| Service | Port | +|------------|------| +| Bind (DNS) | 9119 | +| Monolithic | 9113 | + +### Prometheus example + +The following is a full example of a prometheus.yml file that will scrape the metrics from the lancache services. + +```yaml +scrape_configs: + - job_name: 'lancache-dns' + static_configs: + - targets: ['192.168.0.10:9119'] + - job_name: 'lancache-monolithic' + static_configs: + - targets: ['192.168.0.10:9113'] +``` + + ## `UPSTREAM_DNS` This allows you to choose one or more IP addresses for upstream DNS resolution if a name is not matched by the `lancache-dns` service (e.g. non-cached services, local hostname resolution). From 74687a49da4ad42689ce2f059afc1c77502896bd Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sun, 9 Mar 2025 19:44:37 +0100 Subject: [PATCH 7/9] Split metrics docker-compose file into a seperate file --- .env | 2 +- docker-compose.metrics.yml | 109 +++++++++++++++++++++++++++++++++++++ docker-compose.yml | 80 +-------------------------- 3 files changed, 111 insertions(+), 80 deletions(-) create mode 100644 docker-compose.metrics.yml diff --git a/.env b/.env index 0fc8a24..18afbfc 100644 --- a/.env +++ b/.env @@ -12,7 +12,7 @@ LANCACHE_IP=10.0.39.1 ## IP address on the host that the DNS server should bind to DNS_BIND_IP=10.0.39.1 -## IP address for metrics exporters to bind to +## IP address for metrics exporters to bind to. Only used in the docker-compose.prometheus.yml file ## Leave blank to bind to DNS_BIND_IP METRIC_BIND_IP= diff --git a/docker-compose.metrics.yml b/docker-compose.metrics.yml new file mode 100644 index 0000000..2b9d93e --- /dev/null +++ b/docker-compose.metrics.yml @@ -0,0 +1,109 @@ +version: '2' +x-restart-policy: &restart-policy "no" +services: + dns: + image: lancachenet/lancache-dns:latest + env_file: .env + restart: *restart-policy + ports: + - ${DNS_BIND_IP}:53:53/udp + - ${DNS_BIND_IP}:53:53/tcp + labels: + lancache.dns: "true" + healthcheck: + test: ["CMD", "dig", "+norecurse", "+short" ,"+retry=0", "@127.0.0.1", "lancache.net"] + interval: 10s + timeout: 5s + retries: 5 + networks: + default: + dns-metrics: + aliases: + - lancache-dns + +## HTTPS requests are now handled in monolithic directly +## you could choose to return to sniproxy if desired +# +# sniproxy: +# image: lancachenet/sniproxy:latest +# env_file: .env +# restart: *restart-policy +# ports: +# - 443:443/tcp + + monolithic: + image: lancachenet/monolithic:latest + env_file: .env + restart: *restart-policy + ports: + - 80:80/tcp + - 443:443/tcp + volumes: + - ${CACHE_ROOT}/cache:/data/cache + - ${CACHE_ROOT}/logs:/data/logs + labels: + lancache.monolithic: "true" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080/nginx_status"] + interval: 10s + timeout: 5s + retries: 5 + networks: + default: + monolithic-metrics: + aliases: + - lancache-monolithic + +## Metrics exporter for DNS and Monolithic +## This can be disabled, if you don't want to export metrics to prometheus +## To disable, comment out the next two services + + dns-metrics: + image: prometheuscommunity/bind-exporter:v0.3.0 + restart: *restart-policy + command: + - --web.listen-address=:9119 # This is the port the exporter will listen on + - --bind.stats-url=http://lancache-dns:8053 + ports: + - ${METRIC_BIND_IP:-${DNS_BIND_IP}}:9119:9119 + labels: + lancache.dns.metrics: "true" + depends_on: + dns: + condition: service_healthy + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:9119/metrics"] + interval: 10s + timeout: 5s + retries: 5 + networks: + dns-metrics: + aliases: + - bind-exporter + + monolithic-metrics: + image: nginx/nginx-prometheus-exporter:0.10.0 + restart: *restart-policy + command: + - --nginx.scrape-uri=http://lancache-monolithic:8080/nginx_status + ports: + - ${METRIC_BIND_IP:-${DNS_BIND_IP}}:9113:9113 + labels: + lancache.monolithic.metrics: "true" + depends_on: + monolithic: + condition: service_healthy + # healthcheck: + # Healthcheck cannot be done on image, as it is a scratch image + # Without any healthcheck functionality + networks: + monolithic-metrics: + aliases: + - monolithic-exporter + +## Network definitions, do not change these, unless you know what you are doing + +networks: + default: + dns-metrics: + monolithic-metrics: diff --git a/docker-compose.yml b/docker-compose.yml index 2b9d93e..3648c62 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,19 +7,7 @@ services: restart: *restart-policy ports: - ${DNS_BIND_IP}:53:53/udp - - ${DNS_BIND_IP}:53:53/tcp - labels: - lancache.dns: "true" - healthcheck: - test: ["CMD", "dig", "+norecurse", "+short" ,"+retry=0", "@127.0.0.1", "lancache.net"] - interval: 10s - timeout: 5s - retries: 5 - networks: - default: - dns-metrics: - aliases: - - lancache-dns + - ${DNS_BIND_IP}:53:53/tcp ## HTTPS requests are now handled in monolithic directly ## you could choose to return to sniproxy if desired @@ -41,69 +29,3 @@ services: volumes: - ${CACHE_ROOT}/cache:/data/cache - ${CACHE_ROOT}/logs:/data/logs - labels: - lancache.monolithic: "true" - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/nginx_status"] - interval: 10s - timeout: 5s - retries: 5 - networks: - default: - monolithic-metrics: - aliases: - - lancache-monolithic - -## Metrics exporter for DNS and Monolithic -## This can be disabled, if you don't want to export metrics to prometheus -## To disable, comment out the next two services - - dns-metrics: - image: prometheuscommunity/bind-exporter:v0.3.0 - restart: *restart-policy - command: - - --web.listen-address=:9119 # This is the port the exporter will listen on - - --bind.stats-url=http://lancache-dns:8053 - ports: - - ${METRIC_BIND_IP:-${DNS_BIND_IP}}:9119:9119 - labels: - lancache.dns.metrics: "true" - depends_on: - dns: - condition: service_healthy - healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:9119/metrics"] - interval: 10s - timeout: 5s - retries: 5 - networks: - dns-metrics: - aliases: - - bind-exporter - - monolithic-metrics: - image: nginx/nginx-prometheus-exporter:0.10.0 - restart: *restart-policy - command: - - --nginx.scrape-uri=http://lancache-monolithic:8080/nginx_status - ports: - - ${METRIC_BIND_IP:-${DNS_BIND_IP}}:9113:9113 - labels: - lancache.monolithic.metrics: "true" - depends_on: - monolithic: - condition: service_healthy - # healthcheck: - # Healthcheck cannot be done on image, as it is a scratch image - # Without any healthcheck functionality - networks: - monolithic-metrics: - aliases: - - monolithic-exporter - -## Network definitions, do not change these, unless you know what you are doing - -networks: - default: - dns-metrics: - monolithic-metrics: From 40c8ccae82df82f216ffdcd8a296f667ddcd0d56 Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sun, 9 Mar 2025 19:44:57 +0100 Subject: [PATCH 8/9] Update documentation to better reflect the metrics exporters available and the seperation into two docker compose files --- README.md | 130 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 93 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 27aa2bc..1238eb2 100644 --- a/README.md +++ b/README.md @@ -29,44 +29,8 @@ There are a few ways to make your local network aware of the cache server. 2. Use the configuration generators available from [UKLANs' cache-domains](https://github.com/uklans/cache-domains) project to create configuration data to load into your network's existing DNS infrastructure ## `METRIC_BIND_IP` -This sets the IP address that the metric services will listen on. If your cache host has exactly one IP address -(eg. `192.168.0.10`), specify that here. If your cache host has multiple IPs, specify exactly one and use that. - -This may be used to segregate the cache and dns ip endpoints from the metrics endpoints. - -For prometheus to scrape the metrics, you will need to add the following to your prometheus.yml file: - -> Please note, that Prometheus is not included in this docker-compose stack. - -```yaml -scrape_configs: - - job_name: 'lancache' - static_configs: - - targets: [':'] -``` - -- `` is the IP address you set in the `METRIC_BIND_IP` environment variable -- `` is the port of the metric services. Please see below for the ports used by the metric services. - -| Service | Port | -|------------|------| -| Bind (DNS) | 9119 | -| Monolithic | 9113 | - -### Prometheus example - -The following is a full example of a prometheus.yml file that will scrape the metrics from the lancache services. - -```yaml -scrape_configs: - - job_name: 'lancache-dns' - static_configs: - - targets: ['192.168.0.10:9119'] - - job_name: 'lancache-monolithic' - static_configs: - - targets: ['192.168.0.10:9113'] -``` +This is only used in prometheus version of the docker-compose file. Read more about it in the [metrics section](#metrics). ## `UPSTREAM_DNS` This allows you to choose one or more IP addresses for upstream DNS resolution if a name is not matched by the `lancache-dns` service (e.g. non-cached services, local hostname resolution). @@ -117,6 +81,98 @@ This setting allows you to set the timezone that is used by the docker container For a list of all timezones see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. +# Metrics + +A metrics-enabled LanCache docker-compose file is available, which provides Prometheus exporters for metric endpoints in the LanCache stack. +The exporters allow a Prometheus server to scrape metrics from the LanCache stack and visualize them in Grafana. + +The metrics stack is available in the `docker-compose.metrics.yml` file. + +In order to use this instead of the regular `docker-compose.yml` file, you need to run the following command: + +```bash +docker-compose -f docker-compose.metrics.yml up -d +``` + +*The `-f` specifies the file to use, and the `-d` runs the stack in detached mode.* + +**Running this version of the docker-compose file, is an advanced option and requires knowledge of Prometheus and Grafana.** +This setup ***does not*** provide a Prometheus and Grafana server, you need to provide these yourself and configure them to scrape the metrics from the LanCache stack. +This should ***not*** be seen as a full guide on how to deploy Prometheus and Grafana, but only the needed information to get the metrics from the plan cache stack. A good guide to setting up Prometheus and Grafana in Docker can be found in Docker's [Awesome Compose list](https://github.com/docker/awesome-compose/tree/master/prometheus-grafana). + +An example Prometheus scraping configuration is provided in the [additional settings](#additional-settings) section. + +The metrics stack provides the following exporters: + +- `dns-metrics`: Provides bind (DNS) metrics, available at `http://:9119` + It utilises the [bind_exporter](https://github.com/prometheus-community/bind_exporter) to provide metrics. +- `monolithic-metrics`: Provides nginx (monolithic) metrics, available at `http://:9113` + It utilises the [nginx-prometheus-exporter](https://github.com/nginx/nginx-prometheus-exporter) to provide metrics. + +The stack also adds labels to each service, allowing you to utilise services such as [cAdvisor](https://github.com/google/cadvisor) to scrape metrics from the containers, providing CPU, memory, disk and network metrics.   + +The following services have been labelled, allowing for easy filtering in cAdvisor: + +- `dns`: has the label `lancache.dns` +- `monolithic`: has the label `lancache.monolithic` +- `dns-metrics`: has the label `lancache.dns.metrics` +- `monolithic-metrics`: has the label `lancache.monolithic.metrics` + +*Sniproxy does not have a metrics endpoint and is not labelled.* + +The following dashboards can be used and give a good overview of the metrics that are retrieved with the use of the exporters described here, including [cAdvisor](https://github.com/google/cadvisor) and [node-exporter](https://github.com/prometheus/node_exporter): + +- [Bind exporter dashboard](https://grafana.com/grafana/dashboards/1666-bind-dns/) + Full Bind (DNS) exporter dashboard. Shows most of the metrics that are available from the bind_exporter. +- [NGINX exporter dashboard](./grafana/nginx-exporter.json) + Custom NGINX exporter dashboard, built on top of the official [NGINX exporter dashboard](https://github.com/nginx/nginx-prometheus-exporter/blob/main/grafana/README.md), with additional data retrieved through [cAdvisor](https://github.com/google/cadvisor). This therefore requires cAdvisor to be scraped by the same Prometheus server, in order to show the additional data. +- [cAdvisor dashboard](https://grafana.com/grafana/dashboards/14282-cadvisor-exporter/) + Full cAdvisor dashboard, showing CPU, memory, disk and network metrics for all containers on the host. +- [Node exporter dashboard](https://grafana.com/grafana/dashboards/1860) + Full node exporter dashboard, showing CPU, memory, disk and network metrics for the host. + +## Additional settings + +### `METRIC_BIND_IP` + +This sets the IP address that the metric services will listen to. If your cache host has exactly one IP address (eg. `192.168.0.10`), specify that here. If your cache host has multiple IPs, specify exactly one and use that. +This will default to the [`DNS_BIND_IP`](#dns_bind_ip) if not set. + +This may be used to segregate the cache and DNS IP endpoints from the metrics endpoints. + +For Prometheus to scrape the metrics, you will need to add the following to your prometheus.yml file: + +> Please note, that Prometheus is not included in this docker-compose stack. + +```yaml +scrape_configs: + - job_name: 'lancache' +    static_configs: + - targets: [':'] +``` + +- `` is the IP address you set in the `METRIC_BIND_IP` environment variable +- `` is the port of the metric services. Please see below for the ports used by the metric services. + +| Service | Port | +| ------------------ | ---- | +| Bind (DNS) | 9119 | +| Monolithic (NGINX) | 9113 | + +### Prometheus example + +The following is a full example of a prometheus.yml file that will scrape the metrics from the LanCache services. + +```yaml +scrape_configs: + - job_name: 'lancache-dns' +    static_configs: + - targets: ['192.168.0.10:9119'] + - job_name: 'lancache-monolithic' +    static_configs: + - targets: ['192.168.0.10:9113'] +``` + # More information The LanCache docker-stack is generated automatically from the data over at [UKLans](https://github.com/uklans/cache-domains). All services that are listed in the UKLans repository are available and supported inside this docker-compose. From 146bec34bf02e4a8187c54eae63416035880195b Mon Sep 17 00:00:00 2001 From: The0Mikkel Date: Sun, 9 Mar 2025 19:45:31 +0100 Subject: [PATCH 9/9] Add custom NGINX dashboard that utalises NGINX exporter and cAdvisor --- grafana/nginx-exporter.json | 659 ++++++++++++++++++++++++++++++++++++ 1 file changed, 659 insertions(+) create mode 100644 grafana/nginx-exporter.json diff --git a/grafana/nginx-exporter.json b/grafana/nginx-exporter.json new file mode 100644 index 0000000..5ce00ec --- /dev/null +++ b/grafana/nginx-exporter.json @@ -0,0 +1,659 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "description": "NGINX Prometheus exporter dashboard with additional metrics from cAdvisor", + "editable": true, + "fiscalYearStartMonth": 0, + "gnetId": 12708, + "graphTooltip": 1, + "id": 3, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [ + { + "options": { + "0": { + "text": "Down" + }, + "1": { + "text": "Up" + } + }, + "type": "value" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "#E02F44", + "value": null + }, + { + "color": "#FF9830", + "value": 1 + }, + { + "color": "#299c46", + "value": 1 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 3, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 8, + "links": [], + "maxDataPoints": 100, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "horizontal", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.2.0", + "repeat": "instance", + "repeatDirection": "h", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "expr": "nginx_up{instance=~\"$instance\"}", + "format": "time_series", + "instant": false, + "intervalFactor": 1, + "refId": "A" + } + ], + "title": "NGINX Status for $instance", + "type": "stat" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "description": "", + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 3 + }, + "hiddenSeries": false, + "id": 10, + "legend": { + "alignAsTable": false, + "avg": false, + "current": false, + "hideEmpty": false, + "max": false, + "min": false, + "rightSide": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "10.2.0", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "expr": "irate(nginx_connections_accepted{instance=~\"$instance\"}[5m])", + "format": "time_series", + "instant": false, + "intervalFactor": 1, + "legendFormat": "{{instance}} accepted", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "expr": "irate(nginx_connections_handled{instance=~\"$instance\"}[5m])", + "format": "time_series", + "instant": false, + "intervalFactor": 1, + "legendFormat": "{{instance}} handled", + "refId": "B" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Processed connections", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 1, + "format": "short", + "label": "Connections (rate)", + "logBase": 1, + "show": true + }, + { + "format": "short", + "label": "", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "decimals": 0, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 3 + }, + "hiddenSeries": false, + "id": 12, + "legend": { + "alignAsTable": false, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "10.2.0", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "expr": "nginx_connections_active{instance=~\"$instance\"}", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "{{instance}} active", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "expr": "nginx_connections_reading{instance=~\"$instance\"}", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "{{instance}} reading", + "refId": "B" + }, + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "expr": "nginx_connections_waiting{instance=~\"$instance\"}", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "{{instance}} waiting", + "refId": "C" + }, + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "expr": "nginx_connections_writing{instance=~\"$instance\"}", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "{{instance}} writing", + "refId": "D" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Active Connections", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "decimals": 0, + "format": "short", + "label": "Connections", + "logBase": 1, + "show": true + }, + { + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 11 + }, + "id": 15, + "links": [], + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "pluginVersion": "10.2.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "expr": "irate(nginx_http_requests_total{instance=~\"$instance\"}[5m])", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "{{instance}} total requests", + "refId": "A" + } + ], + "title": "Requests rate", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": true, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "line" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "dark-blue", + "value": 0 + } + ] + }, + "unit": "decbytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 19 + }, + "id": 16, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "disableTextWrap": false, + "editorMode": "code", + "expr": "rate(container_network_receive_bytes_total{name=\"lancache-docker-compose-monolithic-1\"}[$__rate_interval])", + "fullMetaSearch": false, + "includeNullMetadata": false, + "instant": false, + "legendFormat": "Recieved bytes", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "disableTextWrap": false, + "editorMode": "code", + "exemplar": false, + "expr": "- rate(container_network_transmit_bytes_total{name=\"lancache-docker-compose-monolithic-1\"}[$__rate_interval])", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": false, + "instant": false, + "legendFormat": "Transmitted bytes", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Network traffic", + "type": "timeseries" + } + ], + "refresh": "5s", + "schemaVersion": 38, + "tags": [ + "nginx", + "prometheus", + "nginx prometheus exporter" + ], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "default", + "value": "default" + }, + "hide": 0, + "includeAll": false, + "label": "datasource", + "multi": false, + "name": "DS_PROMETHEUS", + "options": [], + "query": "prometheus", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "type": "datasource" + }, + { + "current": { + "selected": true, + "text": [ + "172.31.0.3:9113" + ], + "value": [ + "172.31.0.3:9113" + ] + }, + "datasource": { + "type": "prometheus", + "uid": "f83a8fa9-79cb-4b78-bece-23e479969c1c" + }, + "definition": "label_values(nginx_up, instance)", + "hide": 0, + "includeAll": true, + "label": "", + "multi": true, + "name": "instance", + "options": [], + "query": "label_values(nginx_up, instance)", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tagsQuery": "", + "type": "query", + "useTags": false + } + ] + }, + "time": { + "from": "now-3h", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ], + "time_options": [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" + ] + }, + "timezone": "", + "title": "NGINX exporter", + "uid": "MsjffzSZz", + "version": 9, + "weekStart": "" + } \ No newline at end of file