diff --git a/README.md b/README.md index dea1f6c..86f3782 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![DockerHub](https://img.shields.io/badge/DockerHub-webdevops%2Fmyuplink--exporter-blue)](https://hub.docker.com/r/webdevops/myuplink-exporter/) [![Quay.io](https://img.shields.io/badge/Quay.io-webdevops%2Fmyuplink--exporter-blue)](https://quay.io/repository/webdevops/myuplink-exporter) -A Prometheus exporter for myuplink.com metrics +A Prometheus exporter for myuplink.com device metrics Usage ----- @@ -28,16 +28,21 @@ Help Options: -h, --help Show this help message ``` -HTTP Endpoints --------------- +## HTTP Endpoints | Endpoint | Description | |------------|-----------------------------------------| | `/metrics` | Default prometheus golang metrics | | `/probe` | Probe devices metrics from myuplink.com | -Metrics -------- +### `/probe` + +| GET parameter | Default | Required | Multiple | Description | +|---------------|---------------------------|----------|----------|-------------------------------------------------| +| `cache` | | no | no | Cache time in time.Duration (eg. `30s` or `5m`) | + + +## Metrics | Metric | Description | |----------------------------------------|------------------------------------------| diff --git a/probe.go b/probe.go index ec02727..9fc4de7 100644 --- a/probe.go +++ b/probe.go @@ -41,6 +41,15 @@ func myuplinkProbe(w http.ResponseWriter, r *http.Request) { // use timeout as max cache time as mostly it's also the scrape time cacheTime := time.Duration(timeoutSeconds) * time.Second + if v := r.URL.Query().Get("cache"); v != "" { + cacheTime, err = time.ParseDuration(v) + if err != nil { + contextLogger.Error(err.Error()) + http.Error(w, fmt.Sprintf("failed to parse cache from query param: %s", err), http.StatusBadRequest) + return + } + } + metricSystem := prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "myuplink_system_info",