aboutsummaryrefslogtreecommitdiff
path: root/weed/command/tail.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-04-05 00:51:16 -0700
committerChris Lu <chris.lu@gmail.com>2020-04-05 00:51:16 -0700
commitbf270d9e8c01052409464193b693d50fa09a70a9 (patch)
tree75d7faa1a56d984fd78954df8dca8b65d2f60a00 /weed/command/tail.go
parent2a2d92d06e440c661bc0b06ff9c5c7034e9fc465 (diff)
downloadseaweedfs-bf270d9e8c01052409464193b693d50fa09a70a9.tar.xz
seaweedfs-bf270d9e8c01052409464193b693d50fa09a70a9.zip
filer: able to tail meta data changes
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
+}