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 (
|
||||
currentConnections = promauto.NewGaugeVec(
|
||||
currentTrainStatuses = promauto.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "traewelling_current_connections",
|
||||
Help: "Anzahl der aktuellen Verbindungen pro Benutzer",
|
||||
Name: "traewelling_current_train_statuses",
|
||||
Help: "Anzahl der aktuellen Züge eines Benutzers",
|
||||
},
|
||||
[]string{"username"},
|
||||
[]string{"username", "line_name", "origin", "destination"},
|
||||
)
|
||||
totalTrainDistance = promauto.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
|
@ -162,7 +162,15 @@ func updateMetricsForUser(username string) {
|
|||
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)
|
||||
totalTrainDuration.WithLabelValues(username).Set(float64(userDetails.Data.TrainDuration))
|
||||
totalPoints.WithLabelValues(username).Set(float64(userDetails.Data.Points))
|
||||
|
@ -188,7 +196,7 @@ func main() {
|
|||
go func() {
|
||||
for {
|
||||
updateMetrics()
|
||||
time.Sleep(5 * time.Minute)
|
||||
time.Sleep(5 * time.Minute) // Aktualisierung alle 5 Minuten
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue