2021-09-09 12:25:25 +00:00
|
|
|
//go:build !plan9 && !js
|
2020-07-31 18:57:48 +00:00
|
|
|
// +build !plan9,!js
|
2017-11-12 17:54:25 +00:00
|
|
|
|
2022-08-28 11:21:57 +00:00
|
|
|
// Package cachestats provides the cachestats command.
|
2017-11-12 17:54:25 +00:00
|
|
|
package cachestats
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/backend/cache"
|
|
|
|
"github.com/rclone/rclone/cmd"
|
2020-04-29 09:09:17 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2017-11-12 17:54:25 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
|
|
|
}
|
|
|
|
|
|
|
|
var commandDefinition = &cobra.Command{
|
|
|
|
Use: "cachestats source:",
|
|
|
|
Short: `Print cache stats for a remote`,
|
|
|
|
Long: `
|
|
|
|
Print cache stats for a remote in JSON format
|
|
|
|
`,
|
2020-04-29 09:09:17 +00:00
|
|
|
Hidden: true,
|
2022-11-26 22:40:49 +00:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.39",
|
|
|
|
"status": "Deprecated",
|
|
|
|
},
|
2017-11-12 17:54:25 +00:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
2020-04-29 09:09:17 +00:00
|
|
|
fs.Logf(nil, `"rclone cachestats" is deprecated, use "rclone backend stats %s" instead`, args[0])
|
2017-11-12 17:54:25 +00:00
|
|
|
|
|
|
|
fsrc := cmd.NewFsSrc(args)
|
2017-11-24 10:21:23 +00:00
|
|
|
cmd.Run(false, false, command, func() error {
|
2017-11-12 17:54:25 +00:00
|
|
|
var fsCache *cache.Fs
|
|
|
|
fsCache, ok := fsrc.(*cache.Fs)
|
|
|
|
if !ok {
|
2017-11-24 10:21:23 +00:00
|
|
|
unwrap := fsrc.Features().UnWrap
|
|
|
|
if unwrap != nil {
|
|
|
|
fsCache, ok = unwrap().(*cache.Fs)
|
|
|
|
}
|
2017-11-12 17:54:25 +00:00
|
|
|
if !ok {
|
2021-11-04 10:12:57 +00:00
|
|
|
return fmt.Errorf("%s: is not a cache remote", fsrc.Name())
|
2017-11-12 17:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m, err := fsCache.Stats()
|
2018-05-04 14:19:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-12 17:54:25 +00:00
|
|
|
|
|
|
|
raw, err := json.MarshalIndent(m, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%s\n", string(raw))
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|