/caddy-advanced-metrics

Per-host metrics for caddy with more useful metrics.

Primary LanguageGoMIT LicenseMIT

caddy-advanced-metrics

Metric your Caddy servers using Prometheus and Grafana with this simple plugin. It provided per-host metrics for your servers and more useful metrics.

Report Bug - Request Feature

Downloads Contributors Stargazers Issues License

About The Project

With this caddy module built on bases of xcaddy you can easily monitor your caddy servers using Prometheus and Grafana. It provides per-host metrics for your servers and more useful metrics. It is possible to monitor your hosts on the same Prometheus port.

Built With

  • xcaddy
  • Prometheus Go client library

Getting Started

Usage

{
	order advanced_metrics before file_server
  order advanced_metrics before reverse_proxy
}

:8080 {
    # Enable advanced metrics on port 1234 (http://localhost:1234/metrics)
    advanced_metrics {
      port 1234
      counter true # extension proposed by `aboisvert` 
      latency true # extension proposed by `aboisvert` 
    }

    # Enable file server
    file_server
}

:8081 {
    # Enable advanced metrics (default port 6611)
    advanced_metrics {
      counter true # extension proposed by `aboisvert` 
      latency false # extension proposed by `aboisvert` 
    }

    # Enable file server
    file_server
}

Download build

You can download the latest build from the releases page.

Prerequisites

  • Golang
  • xcaddy

Build and run

  1. Clone the repository
git clone https://github.com/sebastianbrunnert/caddy-advanced-metrics.git
  1. Install Golang dependencies
go mod download
  1. Build custom caddy binary using xcaddy
make build
  1. Run custom caddy binary

Now you can run your custom caddy binary with the advanced metrics module. You can use the following command to run the binary:

./caddy run --config ./examples/Caddyfile

or you can setup the caddy service using systemd.

nano /usr/lib/systemd/system/caddy.service
[Service]
ExecStart=/path/to/caddy run --config /path/to/Caddyfile

Docker Build Example

FROM alpine:3.18.4 AS build
RUN --mount=type=cache,target=/var/cache/apk \
    apk add go=1.20.10-r0 git
RUN --mount=type=cache,target=/root/go/pkg/mod \
    --mount=type=cache,target=/root/.cache/go-build \
  go install github.com/caddyserver/xcaddy/cmd/xcaddy@v0.3.5
RUN --mount=type=cache,target=/root/go/pkg/mod \
    --mount=type=cache,target=/root/.cache/go-build \
  ~/go/bin/xcaddy build v2.7.5 \
  --with github.com/greenpau/caddy-security \
  --with github.com/aboisvert/caddy-advanced-metrics@add-latency \
  --output dist/caddy

Roadmap

See the open issues for a list of proposed features (and known issues).

License

Distributed under the MIT License. See LICENSE for more information.