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"`
|
EventType string `json:"type"`
|
||||||
QualityChangeUp bool `json:"isUp"`
|
QualityChangeUp bool `json:"isUp"`
|
||||||
Offset float32 `json:"offset"`
|
Offset float32 `json:"offset"`
|
||||||
|
Relay string `json:"relay"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type metrics struct {
|
type metrics struct {
|
||||||
buffering *prometheus.CounterVec
|
bufferingSlug *prometheus.CounterVec
|
||||||
recovery *prometheus.CounterVec
|
bufferingRelay *prometheus.CounterVec
|
||||||
errorMetric *prometheus.CounterVec
|
recoverySlug *prometheus.CounterVec
|
||||||
qualityUp *prometheus.CounterVec
|
recoveryRelay *prometheus.CounterVec
|
||||||
qualityDown *prometheus.CounterVec
|
errorMetricSlug *prometheus.CounterVec
|
||||||
|
errorMetricRelay *prometheus.CounterVec
|
||||||
|
qualityUpSlug *prometheus.CounterVec
|
||||||
|
qualityUpRelay *prometheus.CounterVec
|
||||||
|
qualityDownSlug *prometheus.CounterVec
|
||||||
|
qualityDownRelay *prometheus.CounterVec
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -70,14 +76,21 @@ func telemetryHandler(m metrics) echo.HandlerFunc {
|
||||||
for _, v := range *t {
|
for _, v := range *t {
|
||||||
switch v.EventType {
|
switch v.EventType {
|
||||||
case typeBuffering:
|
case typeBuffering:
|
||||||
m.buffering.WithLabelValues(v.Slug).Inc()
|
m.bufferingSlug.WithLabelValues(v.Slug).Inc()
|
||||||
|
m.bufferingRelay.WithLabelValues(v.Relay).Inc()
|
||||||
case typeRecovery:
|
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:
|
case typeQualitySwitch:
|
||||||
if v.QualityChangeUp {
|
if v.QualityChangeUp {
|
||||||
m.qualityUp.WithLabelValues(v.Slug).Inc()
|
m.qualityUpSlug.WithLabelValues(v.Slug).Inc()
|
||||||
|
m.qualityUpRelay.WithLabelValues(v.Relay).Inc()
|
||||||
} else {
|
} 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) {
|
func initMetrics() (metrics, error) {
|
||||||
metricBuffering := prometheus.NewCounterVec(prometheus.CounterOpts{
|
metricBufferingSlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: "telemetry",
|
Namespace: "telemetry",
|
||||||
Subsystem: "player",
|
Subsystem: "slug",
|
||||||
Name: "buffering",
|
Name: "buffering",
|
||||||
}, []string{"slug"})
|
}, []string{"slug"})
|
||||||
|
|
||||||
metricRecovery := prometheus.NewCounterVec(prometheus.CounterOpts{
|
metricBufferingRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: "telemetry",
|
Namespace: "telemetry",
|
||||||
Subsystem: "player",
|
Subsystem: "relay",
|
||||||
|
Name: "buffering",
|
||||||
|
}, []string{"relay"})
|
||||||
|
|
||||||
|
metricRecoverySlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: "telemetry",
|
||||||
|
Subsystem: "slug",
|
||||||
Name: "recovery",
|
Name: "recovery",
|
||||||
}, []string{"slug"})
|
}, []string{"slug"})
|
||||||
|
|
||||||
metricError := prometheus.NewCounterVec(prometheus.CounterOpts{
|
metricRecoveryRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: "telemetry",
|
Namespace: "telemetry",
|
||||||
Subsystem: "player",
|
Subsystem: "relay",
|
||||||
|
Name: "recovery",
|
||||||
|
}, []string{"relay"})
|
||||||
|
|
||||||
|
metricErrorSlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: "telemetry",
|
||||||
|
Subsystem: "slug",
|
||||||
Name: "error",
|
Name: "error",
|
||||||
}, []string{"slug"})
|
}, []string{"slug"})
|
||||||
|
|
||||||
metricQualitySwitchUp := prometheus.NewCounterVec(prometheus.CounterOpts{
|
metricErrorRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: "telemetry",
|
Namespace: "telemetry",
|
||||||
Subsystem: "player",
|
Subsystem: "relay",
|
||||||
|
Name: "error",
|
||||||
|
}, []string{"relay"})
|
||||||
|
|
||||||
|
metricQualitySwitchUpSlug := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: "telemetry",
|
||||||
|
Subsystem: "slug",
|
||||||
Name: "quality_switch_up",
|
Name: "quality_switch_up",
|
||||||
}, []string{"slug"})
|
}, []string{"slug"})
|
||||||
|
|
||||||
metricQualitySwitchDown := prometheus.NewCounterVec(prometheus.CounterOpts{
|
metricQualitySwitchUpRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: "telemetry",
|
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",
|
Name: "quality_switch_down",
|
||||||
}, []string{"slug"})
|
}, []string{"slug"})
|
||||||
|
|
||||||
if err := prometheus.Register(metricBuffering); err != nil {
|
metricQualitySwitchDownRelay := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||||
return metrics{}, fmt.Errorf("failed to register buffering metric: %w", err)
|
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 {
|
if err := prometheus.Register(metricBufferingRelay); err != nil {
|
||||||
return metrics{}, fmt.Errorf("failed to register recovery metric: %w", err)
|
return metrics{}, fmt.Errorf("failed to register buffering relay metric: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := prometheus.Register(metricError); err != nil {
|
if err := prometheus.Register(metricRecoverySlug); err != nil {
|
||||||
return metrics{}, fmt.Errorf("failed to register error metric: %w", err)
|
return metrics{}, fmt.Errorf("failed to register recovery slug metric: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := prometheus.Register(metricQualitySwitchUp); err != nil {
|
if err := prometheus.Register(metricRecoveryRelay); err != nil {
|
||||||
return metrics{}, fmt.Errorf("failed to register quality_switch_up metric: %w", err)
|
return metrics{}, fmt.Errorf("failed to register recovery relay metric: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := prometheus.Register(metricQualitySwitchDown); err != nil {
|
if err := prometheus.Register(metricErrorSlug); err != nil {
|
||||||
return metrics{}, fmt.Errorf("failed to register quality_switch_down metric: %w", err)
|
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{
|
return metrics{
|
||||||
buffering: metricBuffering,
|
bufferingSlug: metricBufferingSlug,
|
||||||
recovery: metricRecovery,
|
bufferingRelay: metricBufferingRelay,
|
||||||
errorMetric: metricError,
|
recoverySlug: metricRecoverySlug,
|
||||||
qualityUp: metricQualitySwitchUp,
|
recoveryRelay: metricRecoveryRelay,
|
||||||
qualityDown: metricQualitySwitchDown,
|
errorMetricSlug: metricErrorSlug,
|
||||||
|
errorMetricRelay: metricErrorRelay,
|
||||||
|
qualityUpSlug: metricQualitySwitchUpSlug,
|
||||||
|
qualityUpRelay: metricQualitySwitchUpRelay,
|
||||||
|
qualityDownSlug: metricQualitySwitchDownSlug,
|
||||||
|
qualityDownRelay: metricQualitySwitchDownRelay,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue