Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Restored compatibility with Logstash 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
alxrem committed Dec 12, 2017
1 parent 6393368 commit 3cca496
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {

func (e *Exporter) collectMetrics(stats *Stats, ch chan<- prometheus.Metric) {
for _, k := range []string{"jvm", "events", "process", "reloads"} {
e.collectTree(k, (*stats)[k], prometheus.Labels{}, ch)
if tree, ok := (*stats)[k]; ok {
e.collectTree(k, tree, prometheus.Labels{}, ch)
}
}

for key, data := range (*stats)["pipelines"].(map[string]interface{}) {
e.collectPipeline(key, data, ch)
if pipelines, ok := (*stats)["pipelines"]; ok {
for pipelineName, data := range pipelines.(map[string]interface{}) {
e.collectPipeline(pipelineName, data, ch)
}
} else {
e.collectPipeline("", (*stats)["pipeline"], ch)
}
}

Expand Down Expand Up @@ -114,7 +120,10 @@ func (e *Exporter) collectPipeline(pipelineName string, data interface{}, ch cha
return
}

labels := prometheus.Labels{"pipeline": pipelineName}
labels := prometheus.Labels{}
if pipelineName != "" {
labels["pipeline"] = pipelineName
}

for _, k := range []string{"events", "reloads", "queue"} {
e.collectTree("pipeline_"+k, stats[k], labels, ch)
Expand All @@ -133,7 +142,9 @@ func (e *Exporter) collectPlugins(name string, section string, data interface{},
labels := prometheus.Labels{
"id": plugin["id"].(string),
"name": plugin["name"].(string),
"pipeline": pipelineName,
}
if pipelineName != "" {
labels["pipeline"] = pipelineName
}
delete(plugin, "id")
delete(plugin, "name")
Expand Down

0 comments on commit 3cca496

Please sign in to comment.