Skip to content

Commit

Permalink
Update prometheus example config
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote committed Jul 28, 2024
1 parent 9e111b4 commit 3a35026
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 11 additions & 3 deletions prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This is an example config.

global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_interval: 1s
evaluation_interval: 1s

# Source for relabeling approach: https://stackoverflow.com/questions/59866342/prometheus-dynamic-metrics-path
scrape_configs:
Expand All @@ -12,9 +12,17 @@ scrape_configs:
- 'targets.json'
relabel_configs:
- source_labels: [__address__]
regex: "(.+):.{52}" # Targets are structured as <targetname>:<target z32 key>, and at prometheus level we only need the target name
regex: "(.+):.{52}:.+" # Targets are structured as <targetname>:<target z32 key>, and at prometheus level we only need the target name
replacement: "/scrape/$1/metrics" # Captured part + /metrics appendix
target_label: __metrics_path__ # => instead of default /metrics
- source_labels: [__address__]
replacement: "localhost:30000" # Replace with the port where the dht-prometheus http server runs
target_label: __address__
- source_labels: [__address__]
regex: ".+:.{52}:([^:]+):.+:" # Targets are structured as <targetname>:<target z32 key>, and at prometheus level we only need the target name
replacement: "$1" # Captured part + /metrics appendix
target_label: hostname
- source_labels: [__address__]
regex: ".+:.{52}:[^:]+:(.+):" # Targets are structured as <targetname>:<target z32 key>, and at prometheus level we only need the target name
replacement: "$1" # Captured part + /metrics appendix
target_label: service
18 changes: 13 additions & 5 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const z32 = require('z32')
const BRIDGE_EXECUTABLE = path.join(path.dirname(__dirname), 'run.js')
const PROMETHEUS_EXECUTABLE = path.join(path.dirname(__dirname), 'prometheus', 'prometheus')

const DEBUG = false
const DEBUG_PROMETHEUS = false
const DEBUG = true
const DEBUG_PROMETHEUS = true

// Note: move this inside the test if we ever have >1 integration test
promClient.collectDefaultMetrics() // So we have something to scrape
Expand Down Expand Up @@ -350,12 +350,20 @@ scrape_configs:
- '${promTargetsLoc}'
relabel_configs:
- source_labels: [__address__]
regex: "(.+):.{52}:.+" # Targets are structured as <targetname>:<target z32 key>, and at prometheus level we only need the key
regex: "(.+):.{52}:.+" # Targets are structured as <targetname>:<target z32 key>, and at prometheus level we only need the target name
replacement: "/scrape/$1/metrics" # Captured part + /metrics appendix
target_label: __metrics_path__ # => instead of default /metrics
- source_labels: [__address__]
replacement: "${bridgeHttpAddress}"
target_label: __address__ # => That's the actual address
replacement: "${bridgeHttpAddress}" # Replace with the port where the dht-prometheus http server runs
target_label: __address__
- source_labels: [__address__]
regex: ".+:.{52}:([^:]+):.+:" # Targets are structured as <targetname>:<target z32 key>, and at prometheus level we only need the target name
replacement: "$1" # Captured part + /metrics appendix
target_label: hostname
- source_labels: [__address__]
regex: ".+:.{52}:[^:]+:(.+):" # Targets are structured as <targetname>:<target z32 key>, and at prometheus level we only need the target name
replacement: "$1" # Captured part + /metrics appendix
target_label: service
`

await fs.promises.writeFile(loc, content)
Expand Down

0 comments on commit 3a35026

Please sign in to comment.