diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-04-05 12:39:20 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-04-05 12:39:20 -0700 |
| commit | af1f64d2448dc0fa6271533d1ad69ad9cd77c066 (patch) | |
| tree | 3f6911eccac9ff16fdb8db788204d438320835e2 /weed/command/watch.go | |
| parent | b10679fcf0932cda1391f0ebc8e42343522cac0f (diff) | |
| download | seaweedfs-af1f64d2448dc0fa6271533d1ad69ad9cd77c066.tar.xz seaweedfs-af1f64d2448dc0fa6271533d1ad69ad9cd77c066.zip | |
change from 'weed tail' to 'weed watch'
Diffstat (limited to 'weed/command/watch.go')
| -rw-r--r-- | weed/command/watch.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/weed/command/watch.go b/weed/command/watch.go new file mode 100644 index 000000000..6a0f4e2aa --- /dev/null +++ b/weed/command/watch.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() { + cmdWatch.Run = runWatch // break init cycle +} + +var cmdWatch = &Command{ + UsageLine: "watch <wip> [-filer=localhost:8888] [-target=/]", + Short: "see recent changes on a filer", + Long: `See recent changes on a filer. + + `, +} + +var ( + watchFiler = cmdWatch.Flag.String("filer", "localhost:8888", "filer hostname:port") + watchTarget = cmdWatch.Flag.String("target", "/", "a folder or file on filer") +) + +func runWatch(cmd *Command, args []string) bool { + + grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.client") + + watchErr := pb.WithFilerClient(*watchFiler, grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { + + stream, err := client.ListenForEvents(context.Background(), &filer_pb.ListenForEventsRequest{ + ClientName: "watch", + Directory: *watchTarget, + 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 watchErr != nil { + fmt.Printf("watch %s: %v\n", *watchFiler, watchErr) + } + + return true +} |
