mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-07 08:07:42 +00:00
cmd/tailscale: add -active flag to 'tailscale status' to filter out inactive peers
This commit is contained in:
parent
96d806789f
commit
0551bec95b
@ -25,13 +25,14 @@
|
|||||||
|
|
||||||
var statusCmd = &ffcli.Command{
|
var statusCmd = &ffcli.Command{
|
||||||
Name: "status",
|
Name: "status",
|
||||||
ShortUsage: "status [-web] [-json]",
|
ShortUsage: "status [-active] [-web] [-json]",
|
||||||
ShortHelp: "Show state of tailscaled and its connections",
|
ShortHelp: "Show state of tailscaled and its connections",
|
||||||
Exec: runStatus,
|
Exec: runStatus,
|
||||||
FlagSet: (func() *flag.FlagSet {
|
FlagSet: (func() *flag.FlagSet {
|
||||||
fs := flag.NewFlagSet("status", flag.ExitOnError)
|
fs := flag.NewFlagSet("status", flag.ExitOnError)
|
||||||
fs.BoolVar(&statusArgs.json, "json", false, "output in JSON format (WARNING: format subject to change)")
|
fs.BoolVar(&statusArgs.json, "json", false, "output in JSON format (WARNING: format subject to change)")
|
||||||
fs.BoolVar(&statusArgs.web, "web", false, "run webserver with HTML showing status")
|
fs.BoolVar(&statusArgs.web, "web", false, "run webserver with HTML showing status")
|
||||||
|
fs.BoolVar(&statusArgs.active, "active", false, "filter output to only peers with active sessions (not applicable to web mode)")
|
||||||
fs.StringVar(&statusArgs.listen, "listen", "127.0.0.1:8384", "listen address; use port 0 for automatic")
|
fs.StringVar(&statusArgs.listen, "listen", "127.0.0.1:8384", "listen address; use port 0 for automatic")
|
||||||
fs.BoolVar(&statusArgs.browser, "browser", true, "Open a browser in web mode")
|
fs.BoolVar(&statusArgs.browser, "browser", true, "Open a browser in web mode")
|
||||||
return fs
|
return fs
|
||||||
@ -43,6 +44,7 @@
|
|||||||
web bool // run webserver
|
web bool // run webserver
|
||||||
listen string // in web mode, webserver address to listen on, empty means auto
|
listen string // in web mode, webserver address to listen on, empty means auto
|
||||||
browser bool // in web mode, whether to open browser
|
browser bool // in web mode, whether to open browser
|
||||||
|
active bool // in CLI mode, filter output to only peers with active sessions
|
||||||
}
|
}
|
||||||
|
|
||||||
func runStatus(ctx context.Context, args []string) error {
|
func runStatus(ctx context.Context, args []string) error {
|
||||||
@ -120,6 +122,11 @@ func runStatus(ctx context.Context, args []string) error {
|
|||||||
f := func(format string, a ...interface{}) { fmt.Fprintf(&buf, format, a...) }
|
f := func(format string, a ...interface{}) { fmt.Fprintf(&buf, format, a...) }
|
||||||
for _, peer := range st.Peers() {
|
for _, peer := range st.Peers() {
|
||||||
ps := st.Peer[peer]
|
ps := st.Peer[peer]
|
||||||
|
// TODO: let server report this active bool instead
|
||||||
|
active := !ps.LastWrite.IsZero() && time.Since(ps.LastWrite) < 2*time.Minute
|
||||||
|
if statusArgs.active && !active {
|
||||||
|
continue
|
||||||
|
}
|
||||||
f("%s %-7s %-15s %-18s tx=%8d rx=%8d ",
|
f("%s %-7s %-15s %-18s tx=%8d rx=%8d ",
|
||||||
peer.ShortString(),
|
peer.ShortString(),
|
||||||
ps.OS,
|
ps.OS,
|
||||||
@ -128,8 +135,6 @@ func runStatus(ctx context.Context, args []string) error {
|
|||||||
ps.TxBytes,
|
ps.TxBytes,
|
||||||
ps.RxBytes,
|
ps.RxBytes,
|
||||||
)
|
)
|
||||||
// TODO: let server report this active bool instead
|
|
||||||
active := !ps.LastWrite.IsZero() && time.Since(ps.LastWrite) < 2*time.Minute
|
|
||||||
relay := ps.Relay
|
relay := ps.Relay
|
||||||
if active && relay != "" && ps.CurAddr == "" {
|
if active && relay != "" && ps.CurAddr == "" {
|
||||||
relay = "*" + relay + "*"
|
relay = "*" + relay + "*"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user