Das Problem mit den Metriken wurde behoben, da veraltete Einträge von Statusen verwendet wurde. Alte Einträge werden nun einfach übersprungen
This commit is contained in:
parent
4aefb78dd1
commit
7f1e7e5e8c
2 changed files with 43 additions and 9 deletions
|
@ -5,7 +5,7 @@ services:
|
||||||
build:
|
build:
|
||||||
context: go/.
|
context: go/.
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
no_cache: true
|
#no_cache: true
|
||||||
#ports:
|
#ports:
|
||||||
# - "8080:8080" # Exponiere Port 8080 für Prometheus-Scraping
|
# - "8080:8080" # Exponiere Port 8080 für Prometheus-Scraping
|
||||||
restart: always # Neustart bei Fehlern oder Updates
|
restart: always # Neustart bei Fehlern oder Updates
|
||||||
|
|
50
go/main.go
50
go/main.go
|
@ -80,6 +80,7 @@ var (
|
||||||
},
|
},
|
||||||
[]string{"username"},
|
[]string{"username"},
|
||||||
)
|
)
|
||||||
|
existingTrips = map[string]bool{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func fetchStatuses(username string) (*StatusResponse, error) {
|
func fetchStatuses(username string) (*StatusResponse, error) {
|
||||||
|
@ -184,6 +185,30 @@ func updateMetricsForUser(username string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bereinige die existingTrips-Map
|
||||||
|
for key := range existingTrips {
|
||||||
|
found := false
|
||||||
|
for _, trip := range statusData.Data {
|
||||||
|
tripType := "unknown"
|
||||||
|
switch trip.Train.TripType {
|
||||||
|
case 0:
|
||||||
|
tripType = "personal"
|
||||||
|
case 1:
|
||||||
|
tripType = "business"
|
||||||
|
case 2:
|
||||||
|
tripType = "commute"
|
||||||
|
}
|
||||||
|
tripKey := fmt.Sprintf("%s_%s_%s_%s_%s_%s", username, trip.Train.LineName, trip.Train.Origin.Name, trip.Train.Destination.Name, trip.Train.Category, tripType)
|
||||||
|
if key == tripKey {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
delete(existingTrips, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, trip := range statusData.Data {
|
for _, trip := range statusData.Data {
|
||||||
active := isTrainActive(trip.Train.Origin.DepartureReal, trip.Train.Destination.ArrivalReal)
|
active := isTrainActive(trip.Train.Origin.DepartureReal, trip.Train.Destination.ArrivalReal)
|
||||||
|
|
||||||
|
@ -197,20 +222,29 @@ func updateMetricsForUser(username string) {
|
||||||
tripType = "commute"
|
tripType = "commute"
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTrainStatuses.WithLabelValues(
|
key := fmt.Sprintf("%s_%s_%s_%s_%s_%s", username, trip.Train.LineName, trip.Train.Origin.Name, trip.Train.Destination.Name, trip.Train.Category, tripType)
|
||||||
|
|
||||||
|
if existingTrips[key] {
|
||||||
|
log.Printf("Fahrt %s für Benutzer '%s' bereits vorhanden, überspringe...\n", trip.Train.LineName, username)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
metric := currentTrainStatuses.WithLabelValues(
|
||||||
username,
|
username,
|
||||||
trip.Train.LineName,
|
trip.Train.LineName,
|
||||||
trip.Train.Origin.Name,
|
trip.Train.Origin.Name,
|
||||||
trip.Train.Destination.Name,
|
trip.Train.Destination.Name,
|
||||||
trip.Train.Category,
|
trip.Train.Category,
|
||||||
tripType,
|
tripType,
|
||||||
).Set(func() float64 {
|
)
|
||||||
if active {
|
|
||||||
return 1
|
if active {
|
||||||
} else {
|
metric.Set(1)
|
||||||
return 0
|
} else {
|
||||||
}
|
metric.Set(0)
|
||||||
}())
|
}
|
||||||
|
|
||||||
|
existingTrips[key] = true
|
||||||
|
|
||||||
if active {
|
if active {
|
||||||
log.Printf("Aktive Verbindung für Benutzer '%s':\n", username)
|
log.Printf("Aktive Verbindung für Benutzer '%s':\n", username)
|
||||||
|
|
Loading…
Add table
Reference in a new issue