seaweedfs/unmaintained/volume_tailer/volume_tailer.go

71 lines
1.8 KiB
Go
Raw Normal View History

2019-04-19 02:05:02 +08:00
package main
import (
"flag"
2019-04-19 12:17:43 +08:00
"log"
"time"
2019-04-19 02:05:02 +08:00
"github.com/chrislusf/seaweedfs/weed/operation"
"github.com/chrislusf/seaweedfs/weed/security"
weed_server "github.com/chrislusf/seaweedfs/weed/server"
"github.com/chrislusf/seaweedfs/weed/storage"
"github.com/spf13/viper"
2019-04-19 10:22:13 +08:00
"golang.org/x/tools/godoc/util"
2019-04-19 02:05:02 +08:00
)
var (
master = flag.String("master", "localhost:9333", "master server host and port")
volumeId = flag.Int("volumeId", -1, "a volume id")
2019-04-19 12:17:43 +08:00
rewindDuration = flag.Duration("rewind", -1, "rewind back in time. -1 means from the first entry. 0 means from now.")
2019-04-19 02:05:02 +08:00
timeoutSeconds = flag.Int("timeoutSeconds", 0, "disconnect if no activity after these seconds")
2019-04-19 10:22:13 +08:00
showTextFile = flag.Bool("showTextFile", false, "display textual file content")
2019-04-19 02:05:02 +08:00
)
func main() {
flag.Parse()
weed_server.LoadConfiguration("security", false)
grpcDialOption := security.LoadClientTLS(viper.Sub("grpc"), "client")
vid := storage.VolumeId(*volumeId)
2019-04-19 12:17:43 +08:00
var sinceTimeNs int64
if *rewindDuration == 0 {
sinceTimeNs = time.Now().UnixNano()
} else if *rewindDuration == -1 {
sinceTimeNs = 0
} else if *rewindDuration > 0 {
sinceTimeNs = time.Now().Add(-*rewindDuration).UnixNano()
}
err := storage.TailVolume(*master, grpcDialOption, vid, uint64(sinceTimeNs), *timeoutSeconds, func(n *storage.Needle) (err error) {
2019-04-19 11:04:44 +08:00
if n.Size == 0 {
println("-", n.String())
return nil
} else {
println("+", n.String())
}
if *showTextFile {
data := n.Data
if n.IsGzipped() {
if data, err = operation.UnGzipData(data); err != nil {
return err
}
}
if util.IsText(data) {
println(string(data))
}
println("-", n.String(), "compressed", n.IsGzipped(), "original size", len(data))
}
return nil
})
if err != nil {
log.Printf("Error VolumeTail volume %d: %v", vid, err)
}
}