Skip to content

Commit

Permalink
Fix example prometheus config (bad regex)
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote committed Jul 29, 2024
1 parent adb812b commit 694c206
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
35 changes: 20 additions & 15 deletions prometheus/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ scrape_configs:
- files:
- '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
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
relabel_configs:
# Targets are structured as <alias>:<target z32 key>:hostname:service (we extract each part)
- source_labels: [__address__]
regex: "(.+):.{52}:.+"
replacement: "$1"
target_label: instance
- source_labels: [instance]
replacement: "/scrape/$1/metrics"
target_label: __metrics_path__ # => instead of default /metrics
- source_labels: [__address__]
regex: ".+:.{52}:([^:]+):.+"
replacement: "$1"
target_label: hostname
- source_labels: [__address__]
regex: ".+:.{52}:[^:]+:(.+)"
replacement: "$1"
target_label: service
- source_labels: [__address__]
replacement: "localhost:30000" # Replace with the port where the dht-prometheus http server runs
target_label: __address__
21 changes: 12 additions & 9 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,23 @@ 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 target name
replacement: "/scrape/$1/metrics" # Captured part + /metrics appendix
regex: "(.+):.{52}:.+"
replacement: "$1"
target_label: instance
- source_labels: [instance]
replacement: "/scrape/$1/metrics"
target_label: __metrics_path__ # => instead of default /metrics
- source_labels: [__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
regex: ".+:.{52}:([^:]+):.+"
replacement: "$1"
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
regex: ".+:.{52}:[^:]+:(.+)"
replacement: "$1"
target_label: service
- source_labels: [__address__]
replacement: "${bridgeHttpAddress}"
target_label: __address__
`

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

0 comments on commit 694c206

Please sign in to comment.