-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: injecting only metric struct and substitution metric and co…
…llector files
- Loading branch information
1 parent
d0788a8
commit 9ab3263
Showing
3 changed files
with
51 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package internal | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
type Collector struct { | ||
cronsumerMetric *CronsumerMetric | ||
|
||
totalRetriedMessagesCounter *prometheus.Desc | ||
totalDiscardedMessagesCounter *prometheus.Desc | ||
} | ||
|
||
func NewCollector(cronsumerMetric *CronsumerMetric) *Collector { | ||
return &Collector{ | ||
cronsumerMetric: cronsumerMetric, | ||
|
||
totalRetriedMessagesCounter: prometheus.NewDesc( | ||
prometheus.BuildFQName(Name, "retried_messages_total", "current"), | ||
"Total number of retried messages.", | ||
[]string{}, | ||
nil, | ||
), | ||
totalDiscardedMessagesCounter: prometheus.NewDesc( | ||
prometheus.BuildFQName(Name, "discarded_messages_total", "current"), | ||
"Total number of discarded messages.", | ||
[]string{}, | ||
nil, | ||
), | ||
} | ||
} | ||
|
||
func (s *Collector) Describe(ch chan<- *prometheus.Desc) { | ||
prometheus.DescribeByCollect(s, ch) | ||
} | ||
|
||
func (s *Collector) Collect(ch chan<- prometheus.Metric) { | ||
ch <- prometheus.MustNewConstMetric( | ||
s.totalRetriedMessagesCounter, | ||
prometheus.CounterValue, | ||
float64(s.cronsumerMetric.TotalRetriedMessagesCounter), | ||
[]string{}..., | ||
) | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
s.totalDiscardedMessagesCounter, | ||
prometheus.CounterValue, | ||
float64(s.cronsumerMetric.TotalDiscardedMessagesCounter), | ||
[]string{}..., | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,8 @@ | ||
package internal | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
const Name = "kafka_cronsumer_" | ||
|
||
type Collector struct { | ||
kafkaCronsumer kafkaCronsumer | ||
|
||
totalRetriedMessagesCounter *prometheus.Desc | ||
totalDiscardedMessagesCounter *prometheus.Desc | ||
} | ||
|
||
func (s *Collector) Describe(ch chan<- *prometheus.Desc) { | ||
prometheus.DescribeByCollect(s, ch) | ||
} | ||
|
||
func (s *Collector) Collect(ch chan<- prometheus.Metric) { | ||
producerMetric := s.kafkaCronsumer.GetMetric() | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
s.totalRetriedMessagesCounter, | ||
prometheus.CounterValue, | ||
float64(producerMetric.TotalRetriedMessagesCounter), | ||
[]string{}..., | ||
) | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
s.totalDiscardedMessagesCounter, | ||
prometheus.CounterValue, | ||
float64(producerMetric.TotalDiscardedMessagesCounter), | ||
[]string{}..., | ||
) | ||
} | ||
|
||
type CronsumerMetric struct { | ||
TotalRetriedMessagesCounter int64 | ||
TotalDiscardedMessagesCounter int64 | ||
} | ||
|
||
func NewCollector(kafkaCronsumer kafkaCronsumer) *Collector { | ||
return &Collector{ | ||
kafkaCronsumer: kafkaCronsumer, | ||
|
||
totalRetriedMessagesCounter: prometheus.NewDesc( | ||
prometheus.BuildFQName(Name, "retried_messages_total", "current"), | ||
"Total number of retried messages.", | ||
[]string{}, | ||
nil, | ||
), | ||
totalDiscardedMessagesCounter: prometheus.NewDesc( | ||
prometheus.BuildFQName(Name, "discarded_messages_total", "current"), | ||
"Total number of discarded messages.", | ||
[]string{}, | ||
nil, | ||
), | ||
} | ||
} |