chore(backend): move metrics to the main package

This commit is contained in:
Łukasz Mierzwa
2019-05-12 12:11:10 +01:00
parent fbdd171a85
commit 5dd3b35f35
3 changed files with 16 additions and 13 deletions
+6 -6
View File
@@ -28,8 +28,8 @@ const (
)
type alertmanagerMetrics struct {
cycles float64
errors map[string]float64
Cycles float64
Errors map[string]float64
}
type alertmanagerStatus struct {
@@ -61,7 +61,7 @@ type Alertmanager struct {
lastError string
status alertmanagerStatus
// metrics tracked per alertmanager instance
metrics alertmanagerMetrics
Metrics alertmanagerMetrics
// headers to send with each AlertManager request
HTTPHeaders map[string]string
}
@@ -389,7 +389,7 @@ func (am *Alertmanager) pullAlerts(version string) error {
// Pull data from upstream Alertmanager instance
func (am *Alertmanager) Pull() error {
am.metrics.cycles++
am.Metrics.Cycles++
version := am.probeVersion()
@@ -399,7 +399,7 @@ func (am *Alertmanager) Pull() error {
if err != nil {
am.clearData()
am.setError(err.Error())
am.metrics.errors[labelValueErrorsSilences]++
am.Metrics.Errors[labelValueErrorsSilences]++
return err
}
@@ -407,7 +407,7 @@ func (am *Alertmanager) Pull() error {
if err != nil {
am.clearData()
am.setError(err.Error())
am.metrics.errors[labelValueErrorsAlerts]++
am.Metrics.Errors[labelValueErrorsAlerts]++
return err
}
+2 -2
View File
@@ -32,8 +32,8 @@ func NewAlertmanager(name, upstreamURI string, opts ...Option) (*Alertmanager, e
autocomplete: []models.Autocomplete{},
knownLabels: []string{},
HTTPHeaders: map[string]string{},
metrics: alertmanagerMetrics{
errors: map[string]float64{
Metrics: alertmanagerMetrics{
Errors: map[string]float64{
labelValueErrorsAlerts: 0,
labelValueErrorsSilences: 0,
},
@@ -1,6 +1,9 @@
package alertmanager
package main
import "github.com/prometheus/client_golang/prometheus"
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prymitive/karma/internal/alertmanager"
)
type karmaCollector struct {
collectedAlerts *prometheus.Desc
@@ -46,17 +49,17 @@ func (c *karmaCollector) Describe(ch chan<- *prometheus.Desc) {
}
func (c *karmaCollector) Collect(ch chan<- prometheus.Metric) {
upstreams := GetAlertmanagers()
upstreams := alertmanager.GetAlertmanagers()
for _, am := range upstreams {
ch <- prometheus.MustNewConstMetric(
c.cyclesTotal,
prometheus.CounterValue,
am.metrics.cycles,
am.Metrics.Cycles,
am.Name,
)
for key, val := range am.metrics.errors {
for key, val := range am.Metrics.Errors {
ch <- prometheus.MustNewConstMetric(
c.errorsTotal,
prometheus.CounterValue,