summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2022-02-08 16:50:30 -0600
committerSean E. Russell <ser@ser1.net>2022-02-09 13:18:39 -0600
commit66047ad64cf9211da7940d3c73b5811766591124 (patch)
tree6e7366c0f74aed10006198f1619cd27457be6fed /cmd
parent7b8bf412b1c832ef5702c933ce21e03b8fad201a (diff)
Fixes #158, adding a man page. This replaces the flags library in the process. It also changes some of the new no- flags.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gotop/description.txt96
-rw-r--r--cmd/gotop/main.go118
2 files changed, 153 insertions, 61 deletions
diff --git a/cmd/gotop/description.txt b/cmd/gotop/description.txt
new file mode 100644
index 0000000..eb038eb
--- /dev/null
+++ b/cmd/gotop/description.txt
@@ -0,0 +1,96 @@
+gotop shows system information in a terminal UI. It can be configured to have
+different layouts, color schemes, and widgets, and it is able to show
+information from other computers.
+
+Anything you change on the command line can be written to a config file
+using the `--write-config` argument, which can then be edited further.
+Just get your arguments the way you like, then run gotop again with the same
+arguments and the `--write-config` flag, and gotop will persist your
+options.
+
+Colorschemes are json files; put them in the config directory (usually
+~/.config/gotop/{name}.json) and load them with the `-c {name}` argument.
+The keys are:
+
+ Fg -- int, foreground color
+ Bg -- int, background color
+ BorderLabel -- int, color of widget text
+ BorderLine -- int, color of borders
+ CPULines -- array of ints for the colors of lines
+ BattLines -- array of ints for the colors of lines
+ MemLines -- array of ints for the colors of lines
+ ProcCursor -- int, color of the cursor in the process widget
+ Sparkline -- int, color of the graph bars
+ DiskBar -- int, color of the disk bars
+ TempLow -- int, color used for low temperatures
+ TempHigh -- int, color used for high temperatures
+
+For example:
+
+ { "Fg": 7, "CPULines": [4, 3, 2, 1, 5, 6, 7, 8] }
+
+Colorschemes are referred to by their name minus the .json suffix. More
+examples are here:
+
+ https://github.com/xxxserxxx/gotop/tree/master/colorschemes
+
+Layout files are plain text files, with widget names on rows roughly representing
+a grid. The format is ROWSPAN:WIDGETNAME/COLSPAN. COLSPAN is relative to the
+rest of the line, so a line saying "cpu mem/3" will give the CPU widget 25% of
+the width, and the memory widget 75% of the width. ROWSPAN is the height of
+the widget, so "2:cpu mem" will make the CPU widget 2 rows high, and the memory
+widget 1 row high. An example is:
+
+ 2:cpu
+ disk/1 2:mem/2
+ temp
+ 2:net 2:procs
+
+Save your layout under any file name either in the config directory or your current
+directory and reference the file name with the `-l` argument. More details about
+the rules are here:
+
+ https://github.com/xxxserxxx/gotop/blob/master/docs/layouts.md
+
+and examples are here:
+
+ https://github.com/xxxserxxx/gotop/tree/master/layouts
+
+gotop can function as both a metrics exporter and viewer. As an exporter, it
+exports Prometheus metrics, and it does not handle either encryption or
+authentication, and so should be run behind a reverse proxy. When gotop is run
+with the `-x` argument, gotop will export metrics on the given port. To try it,
+run
+
+ gotop -x :8884
+
+and then from another shell, run:
+
+ curl http://localhost:8884/metrics
+
+To show these metrics in gotop, instead of curl run:
+
+ gotop --remote-url http://localhost:8884/metrics
+
+You will see additional values in your widgets. To monitor remote machines,
+run gotop on them with the `-x` export flag behind a reverse proxy such as
+Caddy:
+
+ myserver.net {
+ basicauth / gtuser gtpass
+ reverse-proxy /metrics http://localhost:8884
+ }
+
+and then on your local gotop:
+
+ gotop --remote-url https://gtuser:gtpass@myserver.net/metrics
+
+Config files, layouts, and color schemes are searched for (in order):
+
+- In the current directory
+- In $XDG_CONFIG_DIR/gotop
+- In /etc/gotop (on Linux and MacOS)
+
+More information and detailed documentation can found at
+https://github.com/xxxserxxx/gotop`
+
diff --git a/cmd/gotop/main.go b/cmd/gotop/main.go
index da0208e..272eecc 100644
--- a/cmd/gotop/main.go
+++ b/cmd/gotop/main.go
@@ -2,6 +2,7 @@ package main
import (
"bufio"
+ _ "embed"
"flag"
"fmt"
"io"
@@ -21,10 +22,10 @@ import (
"github.com/VictoriaMetrics/metrics"
jj "github.com/cloudfoundry-attic/jibber_jabber"
+ "github.com/droundy/goopt"
ui "github.com/gizak/termui/v3"
"github.com/shibukawa/configdir"
"github.com/xxxserxxx/lingo/v2"
- "github.com/xxxserxxx/opflag"
"github.com/xxxserxxx/gotop/v4"
"github.com/xxxserxxx/gotop/v4/colorschemes"
@@ -55,50 +56,69 @@ var (
tr lingo.Translations
)
+//go:embed "description.txt"
+var description string
+
func parseArgs() error {
cds := conf.ConfigDir.QueryFolders(configdir.All)
cpaths := make([]string, len(cds))
for i, p := range cds {
cpaths[i] = p.Path
}
- help := opflag.BoolP("help", "h", false, tr.Value("args.help"))
- color := opflag.StringP("color", "c", conf.Colorscheme.Name, tr.Value("args.color"))
- opflag.IntVarP(&conf.GraphHorizontalScale, "graphscale", "S", conf.GraphHorizontalScale, tr.Value("args.scale"))
- version := opflag.BoolP("version", "v", false, tr.Value("args.version"))
- versioN := opflag.BoolP("", "V", false, tr.Value("args.version"))
- opflag.BoolVarP(&conf.PercpuLoad, "percpu", "p", conf.PercpuLoad, tr.Value("args.percpu"))
- opflag.BoolVar(&conf.NoPercpuLoad, "no-percpu", conf.NoPercpuLoad, tr.Value("args.no-percpu"))
- opflag.BoolVarP(&conf.AverageLoad, "averagecpu", "a", conf.AverageLoad, tr.Value("args.cpuavg"))
- opflag.BoolVar(&conf.NoAverageLoad, "no-averagecpu", conf.NoAverageLoad, tr.Value("args.no-cpuavg"))
- fahrenheit := opflag.BoolP("fahrenheit", "f", conf.TempScale == 'F', tr.Value("args.temp"))
- opflag.BoolVarP(&conf.Statusbar, "statusbar", "s", conf.Statusbar, tr.Value("args.statusbar"))
- opflag.BoolVar(&conf.NoStatusbar, "no-statusbar", conf.NoStatusbar, tr.Value("args.no-statusbar"))
- opflag.DurationVarP(&conf.UpdateInterval, "rate", "r", conf.UpdateInterval, tr.Value("args.rate"))
- opflag.StringVarP(&conf.Layout, "layout", "l", conf.Layout, tr.Value("args.layout"))
- opflag.StringVarP(&conf.NetInterface, "interface", "i", "all", tr.Value("args.net"))
- opflag.StringVarP(&conf.ExportPort, "export", "x", conf.ExportPort, tr.Value("args.export"))
- opflag.BoolVarP(&conf.Mbps, "mbps", "", conf.Mbps, tr.Value("args.mbps"))
- opflag.BoolVar(&conf.NoMbps, "no-mbps", conf.NoMbps, tr.Value("args.no-mbps"))
- opflag.BoolVar(&conf.Test, "test", conf.Test, tr.Value("args.test"))
- opflag.BoolVar(&conf.NoTest, "no-test", conf.NoTest, tr.Value("args.no-test"))
- opflag.StringP("", "C", "", tr.Value("args.conffile"))
- opflag.BoolVarP(&conf.Nvidia, "nvidia", "", conf.Nvidia, "Enable NVidia GPU support")
- opflag.BoolVarP(&conf.NoNvidia, "no-nvidia", "", conf.NoNvidia, "Disable NVidia GPU support")
- list := opflag.String("list", "", tr.Value("args.list"))
- wc := opflag.Bool("write-config", false, tr.Value("args.write"))
- opflag.SortFlags = false
- opflag.Usage = func() {
- fmt.Fprintf(os.Stderr, tr.Value("usage", os.Args[0]))
- opflag.PrintDefaults()
- fmt.Fprintf(os.Stderr, "Project home: https://github.com/xxxserxxx/gotop\n")
+ goopt.Summary = "A terminal based graphical activity monitor, inspired by gtop and vtop"
+ goopt.Version = Version
+ goopt.Description = func() string {
+ return description
+ }
+ color := goopt.String([]string{"--color", "-c"}, conf.Colorscheme.Name, tr.Value("args.color"))
+ graphhorizontalscale := goopt.Int([]string{"--graphscale", "-S"}, conf.GraphHorizontalScale, tr.Value("args.scale"))
+ version := goopt.Flag([]string{"-v", "-V", "--version"}, []string{}, tr.Value("args.version"), "")
+ percpuload := goopt.Flag([]string{"--percpu", "-p"}, []string{"--no-percpu"}, tr.Value("args.percpu"), tr.Value("args.no-percpu"))
+ averageload := goopt.Flag([]string{"--averagecpu", "-a"}, []string{"--no-averagecpu"}, tr.Value("args.cpuavg"), tr.Value("args.no-cpuavg"))
+ tempScale := goopt.Flag([]string{"--fahrenheit"}, []string{"--celsius"}, tr.Value("args.temp"), tr.Value("args.tempc"))
+ statusbar := goopt.Flag([]string{"--statusbar", "-s"}, []string{"--no-statusbar"}, tr.Value("args.statusbar"), tr.Value("args.no-statusbar"))
+ updateinterval := goopt.String([]string{"--rate", "-r"}, conf.UpdateInterval.String(), tr.Value("args.rate"))
+ layout := goopt.String([]string{"--layout", "-l"}, conf.Layout, tr.Value("args.layout"))
+ netinterface := goopt.String([]string{"--interface", "-i"}, "all", tr.Value("args.net"))
+ exportport := goopt.String([]string{"--export", "-x"}, conf.ExportPort, tr.Value("args.export"))
+ mbps := goopt.Flag([]string{"--mbps"}, []string{"--bytes"}, tr.Value("args.mbps"), tr.Value("args.no-mbps"))
+ test := goopt.Flag([]string{"--test"}, []string{"--no-test"}, tr.Value("args.test"), tr.Value("args.no-test"))
+ // This is so the flag package doesn't barf on an unrecognized flag; it's processed earlier
+ goopt.String([]string{"-C"}, "", tr.Value("args.conffile"))
+ nvidia := goopt.Flag([]string{"--nvidia"}, []string{"--no-nvidia"}, tr.Value("args.nvidia"), tr.Value("args.no-nvidia"))
+ list := goopt.String([]string{"--list"}, "", tr.Value("args.list"))
+ wc := goopt.Flag([]string{"--write-config"}, []string{}, tr.Value("args.write"), "")
+ goopt.Parse(nil)
+
+ conf.PercpuLoad = *percpuload
+ conf.GraphHorizontalScale = *graphhorizontalscale
+ conf.PercpuLoad = *percpuload
+ conf.AverageLoad = *averageload
+ conf.Statusbar = *statusbar
+ conf.Layout = *layout
+ conf.NetInterface = *netinterface
+ conf.ExportPort = *exportport
+ conf.Mbps = *mbps
+ conf.Nvidia = *nvidia
+ conf.AverageLoad = *averageload
+ conf.Test = *test
+ conf.Statusbar = *statusbar
+ conf.Mbps = *mbps
+ conf.Nvidia = *nvidia
+ if upInt, err := time.ParseDuration(*updateinterval); err == nil {
+ conf.UpdateInterval = upInt
+ } else {
+ fmt.Printf("Update interval must be a time interval such as '10s' or '1m'")
+ os.Exit(1)
}
- opflag.Parse()
- if *version || *versioN {
- fmt.Printf("gotop %s (%s)\n", Version, BuildDate)
- os.Exit(0)
+ if *tempScale {
+ conf.TempScale = 'F'
+ } else {
+ conf.TempScale = 'C'
}
- if *help {
- opflag.Usage()
+
+ if *version {
+ fmt.Printf("gotop %s (%s)\n", Version, BuildDate)
os.Exit(0)
}
if *color != "" {
@@ -108,11 +128,6 @@ func parseArgs() error {
}
conf.Colorscheme = cs
}
- if *fahrenheit {
- conf.TempScale = 'F'
- } else {
- conf.TempScale = 'C'
- }
if *list != "" {
switch *list {
case "layouts":
@@ -170,25 +185,6 @@ func parseArgs() error {
os.Exit(0)
}
- if conf.NoStatusbar {
- conf.Statusbar = false
- }
- if conf.NoPercpuLoad {
- conf.PercpuLoad = false
- }
- if conf.NoAverageLoad {
- conf.AverageLoad = false
- }
- if conf.NoMbps {
- conf.Mbps = false
- }
- if conf.NoTest {
- conf.Test = false
- }
- if conf.NoNvidia {
- conf.Nvidia = false
- }
-
return nil
}