aboutsummaryrefslogtreecommitdiff
path: root/weed/command/tail.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/command/tail.go')
-rw-r--r--weed/command/tail.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/weed/command/tail.go b/weed/command/tail.go
new file mode 100644
index 000000000..e81a4cfe2
--- /dev/null
+++ b/weed/command/tail.go
@@ -0,0 +1,63 @@
+package command
+
+import (
+ "context"
+ "fmt"
+ "io"
+
+ "github.com/chrislusf/seaweedfs/weed/pb"
+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
+ "github.com/chrislusf/seaweedfs/weed/security"
+ "github.com/chrislusf/seaweedfs/weed/util"
+)
+
+func init() {
+ cmdTail.Run = runTail // break init cycle
+}
+
+var cmdTail = &Command{
+ UsageLine: "tail <wip> [-filer=localhost:8888]",
+ Short: "see recent changes on a filer",
+ Long: `See recent changes on a filer.
+
+ `,
+}
+
+var (
+ tailFiler = cmdTail.Flag.String("filer", "localhost:8888", "filer hostname:port")
+ tailTarget = cmdTail.Flag.String("target", "/", "a folder or file on filer")
+)
+
+func runTail(cmd *Command, args []string) bool {
+
+ grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client")
+
+ tailErr := pb.WithFilerClient(*tailFiler, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
+
+ stream, err := client.ListenForEvents(context.Background(), &filer_pb.ListenForEventsRequest{
+ ClientName: "tail",
+ Directory: *tailTarget,
+ SinceNs: 0,
+ })
+ if err != nil {
+ return fmt.Errorf("listen: %v", err)
+ }
+
+ for {
+ resp, listenErr := stream.Recv()
+ if listenErr == io.EOF {
+ return nil
+ }
+ if listenErr != nil {
+ return listenErr
+ }
+ fmt.Printf("events: %+v\n", resp.EventNotification)
+ }
+
+ })
+ if tailErr != nil {
+ fmt.Printf("tail %s: %v\n", *tailFiler, tailErr)
+ }
+
+ return true
+}