From f9552a8ea3c50fb503566f7b2f53c942c8e5f6e9 Mon Sep 17 00:00:00 2001 From: Igor Kozlov Date: Wed, 9 Dec 2020 01:37:05 +0300 Subject: [PATCH 1/2] add-kafka-output-exporter --- collector/libbeat.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/collector/libbeat.go b/collector/libbeat.go index 292ad30..bc7d545 100644 --- a/collector/libbeat.go +++ b/collector/libbeat.go @@ -15,9 +15,11 @@ type LibBeat struct { Reloads float64 `json:"reloads"` } `json:"config"` Output LibBeatOutput `json:"output"` + Outputs LibBeatOutputs `json:"outputs"` Pipeline LibBeatPipeline `json:"pipeline"` } + //LibBeatEvents json structure type LibBeatEvents struct { Acked float64 `json:"acked"` @@ -45,6 +47,15 @@ type LibBeatOutput struct { Type string `json:"type"` } +//LibBeatOutputs json structure +type LibBeatOutputs struct { + Kafka struct { + Read float64 `json:"bytes_read"` + Write float64 `json:"bytes_write"` + } `json:"kafka"` + +} + //LibBeatPipeline json structure type LibBeatPipeline struct { Clients float64 `json:"clients"` @@ -119,7 +130,12 @@ func NewLibBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector nil, nil, ), eval: func(stats *Stats) float64 { - return stats.LibBeat.Output.Read.Bytes + if stats.LibBeat.Output.Type == "kafka" { + return stats.LibBeat.Outputs.Kafka.Read + } else { + return stats.LibBeat.Output.Read.Bytes + } + }, valType: prometheus.CounterValue, }, @@ -141,7 +157,11 @@ func NewLibBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector nil, nil, ), eval: func(stats *Stats) float64 { - return stats.LibBeat.Output.Write.Bytes + if stats.LibBeat.Output.Type == "kafka" { + return stats.LibBeat.Outputs.Kafka.Write + } else { + return stats.LibBeat.Output.Write.Bytes + } }, valType: prometheus.CounterValue, }, From a6cdaa7569f5b41ab154bad0286d84b0120b0271 Mon Sep 17 00:00:00 2001 From: Igor Kozlov Date: Wed, 9 Dec 2020 01:42:38 +0300 Subject: [PATCH 2/2] gofmt --- collector/libbeat.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/collector/libbeat.go b/collector/libbeat.go index bc7d545..c6c527c 100644 --- a/collector/libbeat.go +++ b/collector/libbeat.go @@ -15,11 +15,10 @@ type LibBeat struct { Reloads float64 `json:"reloads"` } `json:"config"` Output LibBeatOutput `json:"output"` - Outputs LibBeatOutputs `json:"outputs"` + Outputs LibBeatOutputs `json:"outputs"` Pipeline LibBeatPipeline `json:"pipeline"` } - //LibBeatEvents json structure type LibBeatEvents struct { Acked float64 `json:"acked"` @@ -50,10 +49,9 @@ type LibBeatOutput struct { //LibBeatOutputs json structure type LibBeatOutputs struct { Kafka struct { - Read float64 `json:"bytes_read"` + Read float64 `json:"bytes_read"` Write float64 `json:"bytes_write"` } `json:"kafka"` - } //LibBeatPipeline json structure @@ -131,7 +129,7 @@ func NewLibBeatCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collector ), eval: func(stats *Stats) float64 { if stats.LibBeat.Output.Type == "kafka" { - return stats.LibBeat.Outputs.Kafka.Read + return stats.LibBeat.Outputs.Kafka.Read } else { return stats.LibBeat.Output.Read.Bytes }