mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
fix docker healthcheck formatting
This commit is contained in:
parent
17e8532e6f
commit
68b2d79700
2 changed files with 8 additions and 12 deletions
|
@ -1,8 +1,6 @@
|
|||
package monitor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/docker"
|
||||
"github.com/yusing/go-proxy/internal/net/types"
|
||||
|
||||
|
@ -36,16 +34,10 @@ func (mon *DockerHealthMonitor) CheckHealth() (result *health.HealthCheckResult,
|
|||
}
|
||||
result = new(health.HealthCheckResult)
|
||||
result.Healthy = cont.State.Health.Status == dockerTypes.Healthy
|
||||
detail := new(bytes.Buffer)
|
||||
for _, status := range cont.State.Health.Log {
|
||||
detail.WriteString(status.Output)
|
||||
detail.WriteString("\n")
|
||||
}
|
||||
result.Detail = detail.String()
|
||||
if len(cont.State.Health.Log) > 0 {
|
||||
last := cont.State.Health.Log[len(cont.State.Health.Log)-1].End
|
||||
first := cont.State.Health.Log[0].Start
|
||||
result.Latency = last.Sub(first)
|
||||
lastLog := cont.State.Health.Log[len(cont.State.Health.Log)-1]
|
||||
result.Detail = lastLog.Output
|
||||
result.Latency = lastLog.End.Sub(lastLog.Start)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -28,6 +28,10 @@ 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,
|
||||
|
@ -39,7 +43,7 @@ func (jsonRepr *JSONRepresentation) MarshalJSON() ([]byte, error) {
|
|||
"latency": jsonRepr.Latency.Seconds(),
|
||||
"latencyStr": strconv.Itoa(int(jsonRepr.Latency.Milliseconds())) + " ms",
|
||||
"lastSeen": jsonRepr.LastSeen.Unix(),
|
||||
"lastSeenStr": strutils.FormatTime(jsonRepr.LastSeen),
|
||||
"lastSeenStr": lastSeen,
|
||||
"detail": jsonRepr.Detail,
|
||||
"url": url,
|
||||
"extra": jsonRepr.Extra,
|
||||
|
|
Loading…
Add table
Reference in a new issue