2015-12-10 20:30:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
2016-02-12 18:17:59 +00:00
|
|
|
"time"
|
2015-12-10 20:30:04 +00:00
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
"github.com/docker/containerd/api/grpc/types"
|
|
|
|
netcontext "golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2016-01-23 22:40:55 +00:00
|
|
|
var eventsCommand = cli.Command{
|
2015-12-10 20:30:04 +00:00
|
|
|
Name: "events",
|
|
|
|
Usage: "receive events from the containerd daemon",
|
2016-02-12 18:17:59 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "timestamp,t",
|
|
|
|
Usage: "get events from a specific time stamp in RFC3339Nano format",
|
|
|
|
},
|
|
|
|
},
|
2015-12-10 20:30:04 +00:00
|
|
|
Action: func(context *cli.Context) {
|
2016-02-12 18:17:59 +00:00
|
|
|
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),
|
|
|
|
})
|
2015-12-10 20:30:04 +00:00
|
|
|
if err != nil {
|
|
|
|
fatal(err.Error(), 1)
|
|
|
|
}
|
|
|
|
w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
|
2016-02-12 18:17:59 +00:00
|
|
|
fmt.Fprint(w, "TIME\tTYPE\tID\tPID\tSTATUS\n")
|
2015-12-10 20:30:04 +00:00
|
|
|
w.Flush()
|
|
|
|
for {
|
|
|
|
e, err := events.Recv()
|
|
|
|
if err != nil {
|
|
|
|
fatal(err.Error(), 1)
|
|
|
|
}
|
2016-02-12 18:17:59 +00:00
|
|
|
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)
|
2015-12-10 20:30:04 +00:00
|
|
|
w.Flush()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|