Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
b4a6d9c6
Commit
b4a6d9c6
authored
9 years ago
by
Cameron Sparr
Browse files
Options
Downloads
Patches
Plain Diff
Change prometheus replacer to reverse regex replacer
closes #1474
parent
6afe9cee
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/outputs/prometheus_client/prometheus_client.go
+4
-5
4 additions, 5 deletions
plugins/outputs/prometheus_client/prometheus_client.go
with
4 additions
and
5 deletions
plugins/outputs/prometheus_client/prometheus_client.go
+
4
−
5
View file @
b4a6d9c6
...
...
@@ -5,7 +5,6 @@ import (
"log"
"net/http"
"regexp"
"strings"
"sync"
"github.com/influxdata/telegraf"
...
...
@@ -14,7 +13,7 @@ import (
)
var
(
sanitized
Char
s
=
strings
.
NewReplacer
(
"/"
,
"_"
,
"@"
,
"_"
,
" "
,
"_"
,
"-"
,
"_"
,
"."
,
"_"
)
invalidName
Char
RE
=
regexp
.
MustCompile
(
`[^a-zA-Z0-9_]`
)
// Prometheus metric names must match this regex
// see https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels
...
...
@@ -111,12 +110,12 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
for
_
,
point
:=
range
metrics
{
key
:=
point
.
Name
()
key
=
sanitized
Char
s
.
Replace
(
key
)
key
=
invalidName
Char
RE
.
Replace
AllString
(
key
,
"_"
)
var
labels
[]
string
l
:=
prometheus
.
Labels
{}
for
k
,
v
:=
range
point
.
Tags
()
{
k
=
sanitized
Char
s
.
Replace
(
k
)
k
=
invalidName
Char
RE
.
Replace
AllString
(
k
,
"_"
)
if
len
(
k
)
==
0
{
continue
}
...
...
@@ -137,7 +136,7 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
}
// sanitize the measurement name
n
=
sanitized
Char
s
.
Replace
(
n
)
n
=
invalidName
Char
RE
.
Replace
AllString
(
n
,
"_"
)
var
mname
string
if
n
==
"value"
{
mname
=
key
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment