mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
fix health lastSeen format
This commit is contained in:
parent
57a7c04a4c
commit
34d5edd6b9
3 changed files with 9 additions and 6 deletions
|
@ -45,6 +45,13 @@ func FormatDuration(d time.Duration) string {
|
|||
return strings.Join(parts[:len(parts)-1], ", ") + " and " + parts[len(parts)-1]
|
||||
}
|
||||
|
||||
func FormatLastSeen(t time.Time) string {
|
||||
if t.IsZero() {
|
||||
return "never"
|
||||
}
|
||||
return FormatTime(t)
|
||||
}
|
||||
|
||||
func FormatTime(t time.Time) string {
|
||||
return t.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
|
|
@ -28,10 +28,6 @@ func (jsonRepr *JSONRepresentation) MarshalJSON() ([]byte, error) {
|
|||
if url == "http://:0" {
|
||||
url = ""
|
||||
}
|
||||
lastSeen := "never"
|
||||
if !jsonRepr.LastSeen.IsZero() {
|
||||
lastSeen = strutils.FormatTime(jsonRepr.LastSeen)
|
||||
}
|
||||
return json.Marshal(map[string]any{
|
||||
"name": jsonRepr.Name,
|
||||
"config": jsonRepr.Config,
|
||||
|
@ -43,7 +39,7 @@ func (jsonRepr *JSONRepresentation) MarshalJSON() ([]byte, error) {
|
|||
"latency": jsonRepr.Latency.Seconds(),
|
||||
"latencyStr": strconv.Itoa(int(jsonRepr.Latency.Milliseconds())) + " ms",
|
||||
"lastSeen": jsonRepr.LastSeen.Unix(),
|
||||
"lastSeenStr": lastSeen,
|
||||
"lastSeenStr": strutils.FormatLastSeen(jsonRepr.LastSeen),
|
||||
"detail": jsonRepr.Detail,
|
||||
"url": url,
|
||||
"extra": jsonRepr.Extra,
|
||||
|
|
|
@ -189,7 +189,7 @@ func (mon *monitor) checkUpdateHealth() error {
|
|||
if result.Healthy != (mon.status.Swap(status) == health.StatusHealthy) {
|
||||
extras := map[string]any{
|
||||
"Service Name": mon.service,
|
||||
"Last Seen": strutils.FormatTime(mon.lastSeen),
|
||||
"Last Seen": strutils.FormatLastSeen(mon.lastSeen),
|
||||
}
|
||||
if !mon.url.Load().Nil() {
|
||||
extras["Service URL"] = mon.url.Load().String()
|
||||
|
|
Loading…
Add table
Reference in a new issue