mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 17:50:39 +00:00
Merge pull request #853 from weaveworks/844-container-uptime
Add container uptime and restart count to details panel.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -30,6 +31,8 @@ const (
|
||||
ContainerHostname = "docker_container_hostname"
|
||||
ContainerIPsWithScopes = "docker_container_ips_with_scopes"
|
||||
ContainerState = "docker_container_state"
|
||||
ContainerUptime = "docker_container_uptime"
|
||||
ContainerRestartCount = "docker_container_restart_count"
|
||||
|
||||
NetworkRxDropped = "network_rx_dropped"
|
||||
NetworkRxBytes = "network_rx_bytes"
|
||||
@@ -331,12 +334,11 @@ func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node {
|
||||
ContainerCommand: c.container.Path + " " + strings.Join(c.container.Args, " "),
|
||||
ImageID: c.container.Image,
|
||||
ContainerHostname: c.Hostname(),
|
||||
ContainerState: state,
|
||||
}).WithSets(report.EmptySets.
|
||||
Add(ContainerPorts, c.ports(localAddrs)).
|
||||
Add(ContainerIPs, report.MakeStringSet(ips...)).
|
||||
Add(ContainerIPsWithScopes, report.MakeStringSet(ipsWithScopes...)),
|
||||
).WithLatest(
|
||||
ContainerState, mtime.Now(), state,
|
||||
).WithMetrics(
|
||||
c.metrics(),
|
||||
).WithParents(report.EmptySets.
|
||||
@@ -346,6 +348,11 @@ func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node {
|
||||
if c.container.State.Paused {
|
||||
result = result.WithControls(UnpauseContainer)
|
||||
} else if c.container.State.Running {
|
||||
uptime := (mtime.Now().Sub(c.container.State.StartedAt) / time.Second) * time.Second
|
||||
result = result.WithLatests(map[string]string{
|
||||
ContainerUptime: uptime.String(),
|
||||
ContainerRestartCount: strconv.Itoa(c.container.RestartCount),
|
||||
})
|
||||
result = result.WithControls(
|
||||
RestartContainer, StopContainer, PauseContainer, AttachContainer, ExecContainer,
|
||||
)
|
||||
|
||||
@@ -71,6 +71,7 @@ func TestContainer(t *testing.T) {
|
||||
}
|
||||
|
||||
// Now see if we go them
|
||||
uptime := (now.Sub(startTime) / time.Second) * time.Second
|
||||
want := report.MakeNode().WithLatests(map[string]string{
|
||||
"docker_container_command": " ",
|
||||
"docker_container_created": "01 Jan 01 00:00 UTC",
|
||||
@@ -79,6 +80,8 @@ func TestContainer(t *testing.T) {
|
||||
"docker_image_id": "baz",
|
||||
"docker_label_foo1": "bar1",
|
||||
"docker_label_foo2": "bar2",
|
||||
"docker_container_state": "running",
|
||||
"docker_container_uptime": uptime.String(),
|
||||
}).WithSets(report.EmptySets.
|
||||
Add("docker_container_ports", report.MakeStringSet("1.2.3.4:80->80/tcp", "81/tcp")).
|
||||
Add("docker_container_ips", report.MakeStringSet("1.2.3.4")).
|
||||
@@ -86,8 +89,6 @@ func TestContainer(t *testing.T) {
|
||||
).WithControls(
|
||||
docker.RestartContainer, docker.StopContainer, docker.PauseContainer,
|
||||
docker.AttachContainer, docker.ExecContainer,
|
||||
).WithLatest(
|
||||
"docker_container_state", now, "running",
|
||||
).WithMetrics(report.Metrics{
|
||||
"docker_cpu_total_usage": report.MakeMetric(),
|
||||
"docker_memory_usage": report.MakeMetric().Add(now, 12345),
|
||||
|
||||
@@ -158,11 +158,16 @@ func (m *mockDockerClient) send(event *client.APIEvents) {
|
||||
}
|
||||
|
||||
var (
|
||||
startTime = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
container1 = &client.Container{
|
||||
ID: "ping",
|
||||
Name: "pong",
|
||||
Image: "baz",
|
||||
State: client.State{Pid: 2, Running: true},
|
||||
State: client.State{
|
||||
Pid: 2,
|
||||
Running: true,
|
||||
StartedAt: startTime,
|
||||
},
|
||||
NetworkSettings: &client.NetworkSettings{
|
||||
IPAddress: "1.2.3.4",
|
||||
Ports: map[client.Port][]client.PortBinding{
|
||||
|
||||
@@ -24,6 +24,8 @@ var (
|
||||
ltst(docker.ContainerID, "ID"),
|
||||
ltst(docker.ImageID, "Image ID"),
|
||||
ltst(docker.ContainerState, "State"),
|
||||
ltst(docker.ContainerUptime, "Uptime"),
|
||||
ltst(docker.ContainerRestartCount, "Restart #"),
|
||||
sets(docker.ContainerIPs, "IPs"),
|
||||
sets(docker.ContainerPorts, "Ports"),
|
||||
ltst(docker.ContainerCreated, "Created"),
|
||||
|
||||
@@ -135,7 +135,7 @@ func (m LatestMap) String() string {
|
||||
buf := bytes.NewBufferString("{")
|
||||
for _, key := range keys {
|
||||
val, _ := m.Map.Lookup(key)
|
||||
fmt.Fprintf(buf, "%s: %s, ", key, val)
|
||||
fmt.Fprintf(buf, "%s: %s,\n", key, val)
|
||||
}
|
||||
fmt.Fprintf(buf, "}\n")
|
||||
return buf.String()
|
||||
|
||||
Reference in New Issue
Block a user