Files
nginx-logtail/cmd/cli/main.go

56 lines
1.7 KiB
Go

package main
import (
"fmt"
"os"
)
const usage = `logtail-cli — debug shell for nginx-logtail collectors and aggregators
Usage:
logtail-cli topn [flags] ranked label → count list
logtail-cli trend [flags] per-minute time series
logtail-cli stream [flags] live snapshot feed
logtail-cli targets [flags] list targets known to the queried endpoint
Subcommand flags (all subcommands):
--target host:port[,host:port,...] endpoints to query (default: localhost:9090)
--json emit newline-delimited JSON
--website STRING filter: exact website match
--prefix STRING filter: exact client-prefix match
--uri STRING filter: exact request URI match
--status EXPR filter: HTTP status expression (200, !=200, >=400, <500, …)
--website-re REGEX filter: RE2 regex against website
--uri-re REGEX filter: RE2 regex against request URI
topn flags:
--n INT number of entries (default 10)
--window STR 1m 5m 15m 60m 6h 24h (default 5m)
--group-by STR website prefix uri status (default website)
trend flags:
--window STR 1m 5m 15m 60m 6h 24h (default 5m)
`
func main() {
if len(os.Args) < 2 {
fmt.Fprint(os.Stderr, usage)
os.Exit(1)
}
switch os.Args[1] {
case "topn":
runTopN(os.Args[2:])
case "trend":
runTrend(os.Args[2:])
case "stream":
runStream(os.Args[2:])
case "targets":
runTargets(os.Args[2:])
case "-h", "--help", "help":
fmt.Print(usage)
default:
fmt.Fprintf(os.Stderr, "unknown subcommand %q\n\n%s", os.Args[1], usage)
os.Exit(1)
}
}