Skip to content

Commit

Permalink
Add flag to drop metrics that don't match the mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
victorcete committed Oct 30, 2015
1 parent c2d0533 commit f9d4f11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Metrics that don't match any mapping in the configuration file are translated
into Prometheus metrics without any labels and with certain characters escaped
(`_` -> `__`; `-` -> `__`; `.` -> `_`).

If you have a very large set of metrics you may want to skip the ones that don't
match the mapping configuration. If that is the case you can force this behaviour
using the `-graphite.mapping-strict-match` flag, and it will only store those metrics
you really want.

An example mapping configuration:

test.dispatcher.*.*.*
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
graphiteAddress = flag.String("graphite.listen-address", ":9109", "TCP and UDP address on which to accept samples.")
mappingConfig = flag.String("graphite.mapping-config", "", "Metric mapping configuration file name.")
sampleExpiry = flag.Duration("graphite.sample-expiry", 5*time.Minute, "How long a sample is valid for.")
strictMatch = flag.Bool("graphite.mapping-strict-match", false, "Only store metrics that match the mapping configuration.")
lastProcessed = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "graphite_last_processed_timestamp_seconds",
Expand Down Expand Up @@ -96,6 +97,10 @@ func (c *graphiteCollector) processLine(line string) {
name = labels["name"]
delete(labels, "name")
} else {
// If graphite.mapping-strict-match flag is set, we will drop this metric.
if *strictMatch {
return
}
name = invalidMetricChars.ReplaceAllString(parts[0], "_")
}

Expand Down

0 comments on commit f9d4f11

Please sign in to comment.