chore: some updates

main v0.1.2
parent 10938c1d98
commit c85ec78793

@ -41,7 +41,7 @@ The protocol supports the following commands:
```go ```go
conn, _ := net.Dial("tcp", "<hostname>:12345") conn, _ := net.Dial("tcp", "<hostname>:12345")
conn.Write([]byte("cpu")) conn.Write([]byte("cpu\n"))
data, _ := io.RealAll(conn) data, _ := io.RealAll(conn)
log.Printf("data: %s", data) log.Printf("data: %s", data)
@ -70,4 +70,7 @@ $ ./stats-server setup
# trying out the new binary using netcat # trying out the new binary using netcat
$ time ( echo '<command>' | nc <node> 12345 ) $ 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() { var helpText = strings.TrimSpace(`
fmt.Println("usage: stats-server [setup|serve]") usage: stats-server [setup|serve]
fmt.Println(" setup: setup systemd service")
fmt.Println(" serve: start tcp server") 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) os.Exit(1)
} }
@ -163,17 +181,21 @@ func main() {
switch os.Args[1] { switch os.Args[1] {
case "setup": case "setup":
log.Println("starting setup")
if err := setupSystemdService(); err != nil { if err := setupSystemdService(); err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Println("setup complete") log.Println("setup completed")
case "serve": case "serve":
log.Println("starting server")
if err := startTCPServer(); err != nil { if err := startTCPServer(); err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Println("server exited") log.Println("server exited")
default: default:
showHelp() showHelp()
} }

Loading…
Cancel
Save