Skip to content

Commit

Permalink
add cache parameter for custom cache time
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Oct 22, 2023
1 parent 7f24270 commit 91af3e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand All @@ -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 |
|----------------------------------------|------------------------------------------|
Expand Down
9 changes: 9 additions & 0 deletions probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 91af3e1

Please sign in to comment.