Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system time to /info #11291

Merged
merged 1 commit into from Mar 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/client/commands.go
Expand Up @@ -578,6 +578,14 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
if remoteInfo.Exists("NGoroutines") {
fmt.Fprintf(cli.out, "Goroutines: %d\n", remoteInfo.GetInt("NGoroutines"))
}
if remoteInfo.Exists("SystemTime") {
t, err := remoteInfo.GetTime("SystemTime")
if err != nil {
log.Errorf("Error reading system time: %v", err)
} else {
fmt.Fprintf(cli.out, "System Time: %s\n", t.Format(time.UnixDate))
}
}
if remoteInfo.Exists("NEventsListener") {
fmt.Fprintf(cli.out, "EventsListeners: %d\n", remoteInfo.GetInt("NEventsListener"))
}
Expand Down
2 changes: 2 additions & 0 deletions daemon/info.go
Expand Up @@ -3,6 +3,7 @@ package daemon
import (
"os"
"runtime"
"time"

log "github.com/Sirupsen/logrus"
"github.com/docker/docker/autogen/dockerversion"
Expand Down Expand Up @@ -76,6 +77,7 @@ func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status {
v.SetBool("Debug", os.Getenv("DEBUG") != "")
v.SetInt("NFd", utils.GetTotalUsedFds())
v.SetInt("NGoroutines", runtime.NumGoroutine())
v.Set("SystemTime", time.Now().Format(time.RFC3339Nano))
v.Set("ExecutionDriver", daemon.ExecutionDriver().Name())
v.SetInt("NEventsListener", env.GetInt("count"))
v.Set("KernelVersion", kernelVersion)
Expand Down
4 changes: 2 additions & 2 deletions docs/sources/reference/api/docker_remote_api.md
Expand Up @@ -57,10 +57,10 @@ This endpoint now returns `Os`, `Arch` and `KernelVersion`.
**New!**
You can set ulimit settings to be used within the container.

`Get /info`
`GET /info`

**New!**
Add return value `HttpProxy`,`HttpsProxy` and `NoProxy` to this entrypoint.
This endpoint now returns `SystemTime`, `HttpProxy`,`HttpsProxy` and `NoProxy`.


## v1.17
Expand Down
1 change: 1 addition & 0 deletions docs/sources/reference/api/docker_remote_api_v1.18.md
Expand Up @@ -1452,6 +1452,7 @@ Display system-wide information
"Debug":false,
"NFd": 11,
"NGoroutines":21,
"SystemTime": "2015-03-10T11:11:23.730591467-07:00"
"NEventsListener":0,
"InitPath":"/usr/bin/docker",
"InitSha1":"",
Expand Down
1 change: 1 addition & 0 deletions docs/sources/reference/commandline/cli.md
Expand Up @@ -1242,6 +1242,7 @@ For example:
Debug mode (client): true
Fds: 10
Goroutines: 9
System Time: Tue Mar 10 18:38:57 UTC 2015
EventsListeners: 0
Init Path: /usr/bin/docker
Docker Root Dir: /var/lib/docker
Expand Down
10 changes: 10 additions & 0 deletions engine/env.go
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"strconv"
"strings"
"time"

"github.com/docker/docker/utils"
)
Expand Down Expand Up @@ -69,6 +70,15 @@ func (env *Env) SetBool(key string, value bool) {
}
}

func (env *Env) GetTime(key string) (time.Time, error) {
t, err := time.Parse(time.RFC3339Nano, env.Get(key))
return t, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but why not directly return time.Parse(...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erm, right. should I fix? @icecrime

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll survive :p

}

func (env *Env) SetTime(key string, t time.Time) {
env.Set(key, t.Format(time.RFC3339Nano))
}

func (env *Env) GetInt(key string) int {
return int(env.GetInt64(key))
}
Expand Down
22 changes: 22 additions & 0 deletions engine/env_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"testing"
"time"

"github.com/docker/docker/pkg/testutils"
)
Expand Down Expand Up @@ -94,6 +95,27 @@ func TestSetenvBool(t *testing.T) {
}
}

func TestSetenvTime(t *testing.T) {
job := mkJob(t, "dummy")

now := time.Now()
job.SetenvTime("foo", now)
if val, err := job.GetenvTime("foo"); err != nil {
t.Fatalf("GetenvTime failed to parse: %v", err)
} else {
nowStr := now.Format(time.RFC3339)
valStr := val.Format(time.RFC3339)
if nowStr != valStr {
t.Fatalf("GetenvTime returns incorrect value: %s, Expected: %s", valStr, nowStr)
}
}

job.Setenv("bar", "Obviously I'm not a date")
if val, err := job.GetenvTime("bar"); err == nil {
t.Fatalf("GetenvTime was supposed to fail, instead returned: %s", val)
}
}

func TestSetenvInt(t *testing.T) {
job := mkJob(t, "dummy")

Expand Down
8 changes: 8 additions & 0 deletions engine/job.go
Expand Up @@ -145,6 +145,14 @@ func (job *Job) SetenvBool(key string, value bool) {
job.env.SetBool(key, value)
}

func (job *Job) GetenvTime(key string) (value time.Time, err error) {
return job.env.GetTime(key)
}

func (job *Job) SetenvTime(key string, value time.Time) {
job.env.SetTime(key, value)
}

func (job *Job) GetenvSubEnv(key string) *Env {
return job.env.GetSubEnv(key)
}
Expand Down