add event log and timestamp to events api
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
3dc59d565a
commit
9341a95c26
6 changed files with 191 additions and 111 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/containerd/api/grpc/types"
|
||||
|
@ -13,21 +14,39 @@ import (
|
|||
var eventsCommand = cli.Command{
|
||||
Name: "events",
|
||||
Usage: "receive events from the containerd daemon",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "timestamp,t",
|
||||
Usage: "get events from a specific time stamp in RFC3339Nano format",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) {
|
||||
c := getClient(context)
|
||||
events, err := c.Events(netcontext.Background(), &types.EventsRequest{})
|
||||
var (
|
||||
t int64
|
||||
c = getClient(context)
|
||||
)
|
||||
if ts := context.String("timestamp"); ts != "" {
|
||||
from, err := time.Parse(time.RFC3339Nano, ts)
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
}
|
||||
t = from.Unix()
|
||||
}
|
||||
events, err := c.Events(netcontext.Background(), &types.EventsRequest{
|
||||
Timestamp: uint64(t),
|
||||
})
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
|
||||
fmt.Fprint(w, "TYPE\tID\tPID\tSTATUS\n")
|
||||
fmt.Fprint(w, "TIME\tTYPE\tID\tPID\tSTATUS\n")
|
||||
w.Flush()
|
||||
for {
|
||||
e, err := events.Recv()
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%d\n", e.Type, e.Id, e.Pid, e.Status)
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", time.Unix(int64(e.Timestamp), 0).Format(time.RFC3339Nano), e.Type, e.Id, e.Pid, e.Status)
|
||||
w.Flush()
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue