Hinzufügen von Zugdaten
This commit is contained in:
parent
81da1334bc
commit
489f7bb509
1 changed files with 50 additions and 42 deletions
20
go/main.go
20
go/main.go
|
@ -51,12 +51,12 @@ type UserDetailsResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
currentConnections = promauto.NewGaugeVec(
|
currentTrainStatuses = promauto.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "traewelling_current_connections",
|
Name: "traewelling_current_train_statuses",
|
||||||
Help: "Anzahl der aktuellen Verbindungen pro Benutzer",
|
Help: "Anzahl der aktuellen Züge eines Benutzers",
|
||||||
},
|
},
|
||||||
[]string{"username"},
|
[]string{"username", "line_name", "origin", "destination"},
|
||||||
)
|
)
|
||||||
totalTrainDistance = promauto.NewGaugeVec(
|
totalTrainDistance = promauto.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
|
@ -162,7 +162,15 @@ func updateMetricsForUser(username string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
currentConnections.WithLabelValues(username).Set(float64(len(statusData.Data)))
|
for _, trip := range statusData.Data {
|
||||||
|
currentTrainStatuses.WithLabelValues(
|
||||||
|
username,
|
||||||
|
trip.Train.LineName,
|
||||||
|
trip.Train.Origin.Name,
|
||||||
|
trip.Train.Destination.Name,
|
||||||
|
).Set(1) // Jede aktive Verbindung wird als 1 gesetzt
|
||||||
|
}
|
||||||
|
|
||||||
totalTrainDistance.WithLabelValues(username).Set(float64(userDetails.Data.TrainDistance) / 1000)
|
totalTrainDistance.WithLabelValues(username).Set(float64(userDetails.Data.TrainDistance) / 1000)
|
||||||
totalTrainDuration.WithLabelValues(username).Set(float64(userDetails.Data.TrainDuration))
|
totalTrainDuration.WithLabelValues(username).Set(float64(userDetails.Data.TrainDuration))
|
||||||
totalPoints.WithLabelValues(username).Set(float64(userDetails.Data.Points))
|
totalPoints.WithLabelValues(username).Set(float64(userDetails.Data.Points))
|
||||||
|
@ -188,7 +196,7 @@ func main() {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
updateMetrics()
|
updateMetrics()
|
||||||
time.Sleep(5 * time.Minute)
|
time.Sleep(5 * time.Minute) // Aktualisierung alle 5 Minuten
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue