mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-14 11:21:17 +00:00
Merge pull request #48 from haguenau/tolerate-broken-metrics
Tolerate more forms of broken lines from StatsD
This commit is contained in:
commit
0c8b644ee1
2 changed files with 18 additions and 2 deletions
|
@ -204,6 +204,14 @@ func TestHandlePacket(t *testing.T) {
|
|||
name: "illegal stat type",
|
||||
in: "foo:2|t",
|
||||
},
|
||||
{
|
||||
name: "empty metric name",
|
||||
in: ":100|ms",
|
||||
},
|
||||
{
|
||||
name: "empty component",
|
||||
in: "foo:1|c|",
|
||||
},
|
||||
}
|
||||
|
||||
l := StatsDListener{}
|
||||
|
|
12
exporter.go
12
exporter.go
|
@ -352,7 +352,7 @@ func (l *StatsDListener) handlePacket(packet []byte, e chan<- Events) {
|
|||
}
|
||||
|
||||
elements := strings.SplitN(line, ":", 2)
|
||||
if len(elements) < 2 {
|
||||
if len(elements) < 2 || len(elements[0]) == 0 {
|
||||
networkStats.WithLabelValues("malformed_line").Inc()
|
||||
log.Errorln("Bad line from StatsD:", line)
|
||||
continue
|
||||
|
@ -365,7 +365,7 @@ func (l *StatsDListener) handlePacket(packet []byte, e chan<- Events) {
|
|||
} else {
|
||||
samples = strings.Split(elements[1], ":")
|
||||
}
|
||||
for _, sample := range samples {
|
||||
samples: for _, sample := range samples {
|
||||
components := strings.Split(sample, "|")
|
||||
samplingFactor := 1.0
|
||||
if len(components) < 2 || len(components) > 4 {
|
||||
|
@ -383,6 +383,14 @@ func (l *StatsDListener) handlePacket(packet []byte, e chan<- Events) {
|
|||
|
||||
labels := map[string]string{}
|
||||
if len(components) >= 3 {
|
||||
for _, component := range components[2:] {
|
||||
if len(component) == 0 {
|
||||
log.Errorln("Empty component on line: ", line)
|
||||
networkStats.WithLabelValues("malformed_component").Inc()
|
||||
continue samples
|
||||
}
|
||||
}
|
||||
|
||||
for _, component := range components[2:] {
|
||||
switch component[0] {
|
||||
case '@':
|
||||
|
|
Loading…
Reference in a new issue