mirror of
https://github.com/TwiN/gatus.git
synced 2025-01-03 12:39:39 +01:00
add func to store for getting single service status
and use that in the watchdog
This commit is contained in:
parent
5eb289c4d3
commit
4d24a4d647
@ -41,6 +41,18 @@ func (ims *InMemoryStore) GetAll() map[string]*core.ServiceStatus {
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetServiceStatus returns the service status for a given service name in the given group
|
||||||
|
func (ims *InMemoryStore) GetServiceStatus(group, name string) *core.ServiceStatus {
|
||||||
|
key := fmt.Sprintf("%s_%s", group, name)
|
||||||
|
serviceResultsMutex.RLock()
|
||||||
|
serviceStatus, exists := serviceStatuses[key]
|
||||||
|
serviceResultsMutex.RUnlock()
|
||||||
|
if !exists {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return serviceStatus
|
||||||
|
}
|
||||||
|
|
||||||
// Insert inserts the observed result for the specified service into the in memory store
|
// Insert inserts the observed result for the specified service into the in memory store
|
||||||
func (ims *InMemoryStore) Insert(service *core.Service, result *core.Result) {
|
func (ims *InMemoryStore) Insert(service *core.Service, result *core.Result) {
|
||||||
key := fmt.Sprintf("%s_%s", service.Group, service.Name)
|
key := fmt.Sprintf("%s_%s", service.Group, service.Name)
|
||||||
|
@ -30,10 +30,8 @@ func GetServiceStatusesAsJSON() ([]byte, error) {
|
|||||||
|
|
||||||
// GetUptimeByServiceGroupAndName returns the uptime of a service based on its group and name
|
// GetUptimeByServiceGroupAndName returns the uptime of a service based on its group and name
|
||||||
func GetUptimeByServiceGroupAndName(group, name string) *core.Uptime {
|
func GetUptimeByServiceGroupAndName(group, name string) *core.Uptime {
|
||||||
key := fmt.Sprintf("%s_%s", group, name)
|
serviceStatus := store.GetServiceStatus(group, name)
|
||||||
serviceStatuses := store.GetAll()
|
if serviceStatus == nil {
|
||||||
serviceStatus, exists := serviceStatuses[key]
|
|
||||||
if !exists {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return serviceStatus.Uptime
|
return serviceStatus.Uptime
|
||||||
|
Loading…
Reference in New Issue
Block a user