Last active
July 24, 2023 13:06
-
-
Save RichiH/f2ffb824d428d8ca0c7c40cd62022b56 to your computer and use it in GitHub Desktop.
Prometheus relabelling to get rid of port number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
============================================ | |
============================================ | |
============================================ | |
This does what it should: | |
regex: (.+?)(:80)? | |
Also see https://golang.org/pkg/regexp/syntax/ | |
============================================ | |
============================================ | |
============================================ | |
This returns 'instance="XX"' | |
- targets: | |
- XX:80 | |
relabel_configs: | |
- source_labels: [ __address__ ] | |
target_label: instance | |
regex: '(.*):80' | |
replacement: '${1}' | |
============================================ | |
But auto-attached :80 does not go away and results in 'instance="XX:80"' | |
- targets: | |
- XX | |
relabel_configs: | |
- source_labels: [ __address__ ] | |
target_label: instance | |
regex: '(.*):80' | |
replacement: '${1}' | |
============================================ | |
Returns 'instance="XX"' | |
- targets: | |
- XX | |
relabel_configs: | |
- source_labels: [ __address__ ] | |
target_label: instance | |
regex: '(.*)(:80)?' | |
replacement: '${1}' | |
============================================ | |
Returns 'instance="XX:80"' | |
- targets: | |
- XX:80 | |
relabel_configs: | |
- source_labels: [ __address__ ] | |
target_label: instance | |
regex: '(.*)(:80)?' | |
replacement: '${1}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In cases where you use a difference
scheme
(such ashttps
) or port (e.g.8080
), the regex you supplied above will not work.You should consider making the regex independent of the port.