feat: add metric set for relays
This commit is contained in:
parent
38f9a75157
commit
59cefcdf67
1 changed files with 102 additions and 34 deletions
136
main.go
136
main.go
|
@ -15,14 +15,20 @@ type Telemetry struct {
|
|||
EventType string `json:"type"`
|
||||
QualityChangeUp bool `json:"isUp"`
|
||||
Offset float32 `json:"offset"`
|
||||
Relay string `json:"relay"`
|
||||
}
|
||||
|
||||
type metrics struct {
|
||||
buffering *prometheus.CounterVec
|
||||
recovery *prometheus.CounterVec
|
||||
errorMetric *prometheus.CounterVec
|
||||
qualityUp *prometheus.CounterVec
|
||||
qualityDown *prometheus.CounterVec
|
||||
bufferingSlug *prometheus.CounterVec
|
||||
bufferingRelay *prometheus.CounterVec
|
||||
recoverySlug *prometheus.CounterVec
|
||||
recoveryRelay *prometheus.CounterVec
|
||||
errorMetricSlug *prometheus.CounterVec
|
||||
errorMetricRelay *prometheus.CounterVec
|
||||
qualityUpSlug *prometheus.CounterVec
|
||||
qualityUpRelay *prometheus.CounterVec
|
||||
qualityDownSlug *prometheus.CounterVec
|
||||
qualityDownRelay *prometheus.CounterVec
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -70,14 +76,21 @@ func telemetryHandler(m metrics) echo.HandlerFunc {
|
|||
for _, v := range *t {
|
||||
switch v.EventType {
|
||||
case typeBuffering:
|
||||
m.buffering.WithLabelValues(v.Slug).Inc()
|
||||
m.bufferingSlug.WithLabelValues(v.Slug).Inc()
|
||||
m.bufferingRelay.WithLabelValues(v.Relay).Inc()
|
||||
case typeRecovery:
|
||||
m.recovery.WithLabelValues(v.Slug).Inc()
|
||||
m.recoverySlug.WithLabelValues(v.Slug).Inc()
|
||||
m.recoveryRelay.WithLabelValues(v.Relay).Inc()
|
||||
case typeError:
|
||||
m.errorMetricSlug.WithLabelValues(v.Slug).Inc()
|
||||
m.errorMetricRelay.WithLabelValues(v.Relay).Inc()
|
||||
case typeQualitySwitch:
|
||||
if v.QualityChangeUp {
|
||||
m.qualityUp.WithLabelValues(v.Slug).Inc()
|
||||
m.qualityUpSlug.WithLabelValues(v.Slug).Inc()
|
||||
m.qualityUpRelay.WithLabelValues(v.Relay).Inc()
|
||||
} else {
|
||||
m.qualityDown.WithLabelValues(v.Slug).Inc()
|
||||
m.qualityDownSlug.WithLabelValues(v.Slug).Inc()
|
||||
m.qualityDownRelay.WithLabelValues(v.Relay).Inc()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,61 +100,116 @@ func telemetryHandler(m metrics) echo.HandlerFunc {
|
|||
}
|
||||
|
||||
func initMetrics() (metrics, error) {
|
||||
metricBuffering := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
metricBufferingSlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "player",
|
||||
Subsystem: "slug",
|
||||
Name: "buffering",
|
||||
}, []string{"slug"})
|
||||
|
||||
metricRecovery := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
metricBufferingRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "player",
|
||||
Subsystem: "relay",
|
||||
Name: "buffering",
|
||||
}, []string{"relay"})
|
||||
|
||||
metricRecoverySlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "slug",
|
||||
Name: "recovery",
|
||||
}, []string{"slug"})
|
||||
|
||||
metricError := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
metricRecoveryRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "player",
|
||||
Subsystem: "relay",
|
||||
Name: "recovery",
|
||||
}, []string{"relay"})
|
||||
|
||||
metricErrorSlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "slug",
|
||||
Name: "error",
|
||||
}, []string{"slug"})
|
||||
|
||||
metricQualitySwitchUp := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
metricErrorRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "player",
|
||||
Subsystem: "relay",
|
||||
Name: "error",
|
||||
}, []string{"relay"})
|
||||
|
||||
metricQualitySwitchUpSlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "slug",
|
||||
Name: "quality_switch_up",
|
||||
}, []string{"slug"})
|
||||
|
||||
metricQualitySwitchDown := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
metricQualitySwitchUpRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "player",
|
||||
Subsystem: "relay",
|
||||
Name: "quality_switch_up",
|
||||
}, []string{"relay"})
|
||||
|
||||
metricQualitySwitchDownSlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "slug",
|
||||
Name: "quality_switch_down",
|
||||
}, []string{"slug"})
|
||||
|
||||
if err := prometheus.Register(metricBuffering); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register buffering metric: %w", err)
|
||||
metricQualitySwitchDownRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "telemetry",
|
||||
Subsystem: "relay",
|
||||
Name: "quality_switch_down",
|
||||
}, []string{"relay"})
|
||||
|
||||
if err := prometheus.Register(metricBufferingSlug); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register buffering slug metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricRecovery); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register recovery metric: %w", err)
|
||||
if err := prometheus.Register(metricBufferingRelay); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register buffering relay metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricError); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register error metric: %w", err)
|
||||
if err := prometheus.Register(metricRecoverySlug); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register recovery slug metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricQualitySwitchUp); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register quality_switch_up metric: %w", err)
|
||||
if err := prometheus.Register(metricRecoveryRelay); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register recovery relay metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricQualitySwitchDown); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register quality_switch_down metric: %w", err)
|
||||
if err := prometheus.Register(metricErrorSlug); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register error slug metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricErrorRelay); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register error relay metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricQualitySwitchUpSlug); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register quality_switch_up slug metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricQualitySwitchUpRelay); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register quality_switch_up relay metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricQualitySwitchDownSlug); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register quality_switch_down slug metric: %w", err)
|
||||
}
|
||||
|
||||
if err := prometheus.Register(metricQualitySwitchDownRelay); err != nil {
|
||||
return metrics{}, fmt.Errorf("failed to register quality_switch_down relay metric: %w", err)
|
||||
}
|
||||
|
||||
return metrics{
|
||||
buffering: metricBuffering,
|
||||
recovery: metricRecovery,
|
||||
errorMetric: metricError,
|
||||
qualityUp: metricQualitySwitchUp,
|
||||
qualityDown: metricQualitySwitchDown,
|
||||
bufferingSlug: metricBufferingSlug,
|
||||
bufferingRelay: metricBufferingRelay,
|
||||
recoverySlug: metricRecoverySlug,
|
||||
recoveryRelay: metricRecoveryRelay,
|
||||
errorMetricSlug: metricErrorSlug,
|
||||
errorMetricRelay: metricErrorRelay,
|
||||
qualityUpSlug: metricQualitySwitchUpSlug,
|
||||
qualityUpRelay: metricQualitySwitchUpRelay,
|
||||
qualityDownSlug: metricQualitySwitchDownSlug,
|
||||
qualityDownRelay: metricQualitySwitchDownRelay,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue