advanced_metrics

package module
v0.0.0-...-b68dfc9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 12 Imported by: 0

README

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.

Documentation

Index

Constants

View Source
const DEBUG bool = false

Variables

This section is empty.

Functions

This section is empty.

Types

type AdvancedMetricsHandler

type AdvancedMetricsHandler struct {
	PrometheusPort int  `json:"port,omitempty"`
	Counter        bool `json:"counter,omitempty"`
	Latency        bool `json:"latency,omitempty"`
	// contains filtered or unexported fields
}

func (AdvancedMetricsHandler) CaddyModule

func (AdvancedMetricsHandler) CaddyModule() caddy.ModuleInfo

func (*AdvancedMetricsHandler) HandleRequest

func (*AdvancedMetricsHandler) Provision

func (am *AdvancedMetricsHandler) Provision(ctx caddy.Context) error

func (*AdvancedMetricsHandler) ServeHTTP

type AdvancedMetricsModule

type AdvancedMetricsModule struct {
	// contains filtered or unexported fields
}

func (*AdvancedMetricsModule) StartServer

func (am *AdvancedMetricsModule) StartServer()

type LoggingResponseWriter

type LoggingResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewLoggingResponseWriter

func NewLoggingResponseWriter(w http.ResponseWriter) *LoggingResponseWriter

func (*LoggingResponseWriter) WriteHeader

func (lrw *LoggingResponseWriter) WriteHeader(code int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL