chore: some updates

main v0.1.2
Antonio De Lucreziis 6 months ago
parent 10938c1d98
commit c85ec78793

@ -41,7 +41,7 @@ The protocol supports the following commands:
```go
conn, _ := net.Dial("tcp", "<hostname>:12345")
conn.Write([]byte("cpu"))
conn.Write([]byte("cpu\n"))
data, _ := io.RealAll(conn)
log.Printf("data: %s", data)
@ -70,4 +70,7 @@ $ ./stats-server setup
# trying out the new binary using netcat
$ time ( echo '<command>' | nc <node> 12345 )
# stop and disable the systemd service on all nodes
$ parallel --nonall --slf nodes.txt 'systemctl disable --now stats-server.service'
```

@ -148,11 +148,29 @@ func startTCPServer() error {
}
}
func showHelp() {
fmt.Println("usage: stats-server [setup|serve]")
fmt.Println(" setup: setup systemd service")
fmt.Println(" serve: start tcp server")
var helpText = strings.TrimSpace(`
usage: stats-server [setup|serve]
This is a simple tcp server that returns system stats, it can be run as a
systemd service or as a standalone server.
protocol commands:
cpu returns cpu usage
memory returns memory usage
network returns network usage
storage returns storage usage
uptime returns uptime
subcommands:
setup auto-install and setup systemd service
serve start tcp server
config, environment variables:
HOST tcp host to bind to (default: :12345)
`)
func showHelp() {
fmt.Println(helpText)
os.Exit(1)
}
@ -163,17 +181,21 @@ func main() {
switch os.Args[1] {
case "setup":
log.Println("starting setup")
if err := setupSystemdService(); err != nil {
log.Fatal(err)
}
log.Println("setup complete")
log.Println("setup completed")
case "serve":
log.Println("starting server")
if err := startTCPServer(); err != nil {
log.Fatal(err)
}
log.Println("server exited")
default:
showHelp()
}

Loading…
Cancel
Save