chore: updated readme

main
parent c488d41ac0
commit 631af1cda6

@ -1,65 +1,67 @@
# Go Stats Server # Go Stats Server
This Go project implements a simple TCP server that responds to custom commands over the network. The server performs various system-related tasks and provides This Go project implements a simple TCP server that responds to custom commands over an internal network. The server performs various system-related tasks and provides information such as CPU usage, memory status, network statistics, storage details, and system uptime.
information such as CPU usage, memory status, network statistics, storage details, and system uptime.
## Commands
The protocol supports the following commands:
- `cpu`: Returns the CPU usage as a percentage.
- `memory`: Returns the memory usage as a percentage.
- `network`: Returns the network statistics as a JSON object.
- `storage`: Returns the storage details as a JSON object.
- `uptime`: Returns the system uptime as a string.
## Usage ## Usage
1. **Build the Server:** 1. **Build the Server:**
```bash ```bash shell
CGO_ENABLED=0 GOARCH=<arch> go build -a -ldflags '-s -w' -o ./out/stats-server main.go $ CGO_ENABLED=0 GOARCH=<arch> go build -a -ldflags '-s -w' -o ./out/stats-server main.go
``` ```
2. **Run the Server:** 2. **Run the Server:**
```bash ```bash shell
./out/stats-server $ ./out/stats-server serve
``` ```
3. **Connect to the Server:** Use a TCP client to connect to the server on port 12345. You can send commands like "cpu," "memory," "network," "storage," 3. **Connect to the Server:** Use a TCP client to connect to the server on port 12345. You can send commands like "cpu", "memory", "network", "storage" or
"uptime," and "exit." "uptime".
Example using `nc`: Example using `nc`:
```bash ```bash shell
echo "cpu" | nc localhost 12345 $ time ( echo "cpu" | nc <hostname> 12345 )
``` ```
or using golang or directly using golang:
```go ```go
import "net" conn, _ := net.Dial("tcp", "<hostname>:12345")
func main() {
conn, err := net.Dial("tcp", "localhost:12345")
if err != nil {
// handle error
}
defer conn.Close()
conn.Write([]byte("cpu")) conn.Write([]byte("cpu"))
}
data, _ := io.RealAll(conn)
log.Printf("data: %s", data)
``` ```
## GitHub Actions Workflow ## GitHub Actions Workflow
The included GitHub Actions workflow automates the build and release process. On each push to the main branch, the workflow builds the Go program, creates a The included GitHub Actions workflow automates the build and release process. On each push to the main branch, the workflow builds the Go program, creates a GitHub release, and uploads the compiled binary as an artifact.
GitHub release, and uploads the compiled binary as an artifact.
## Self-Installing Binary ## Self-Installing Binary
Assuming you have a cluster of machines, you can use the following commands to download and install the latest version of the binary on all nodes. You must have root access to all nodes. Assuming you have a cluster of machines, you can use the following commands to download, install and setup systemd services for the latest version of the binary on all nodes. You must have root access to all nodes.
```bash ```bash
$ parallel --nonall --slf nodes.txt 'mkdir -p cluster' $ parallel --nonall --slf nodes.txt 'mkdir -p cluster'
$ parallel --nonall --slf nodes.txt 'wget -qO- https://github.com/aziis98/go-stats-server/releases/latest/download/stats-server > ./cluster/stats-server' $ parallel --nonall --slf nodes.txt 'wget -qO- https://github.com/aziis98/go-stats-server/releases/latest/download/stats-server > ./cluster/stats-server'
$ parallel --nonall --slf nodes.txt 'chmod -v +x ./cluster/stats-server' $ parallel --nonall --slf nodes.txt 'chmod -v +x ./cluster/stats-server'
# to setup on all nodes # setup systemd services on all nodes
$ parallel --nonall --slf nodes.txt './cluster/stats-server setup' $ parallel --nonall --slf nodes.txt './cluster/stats-server setup'
# to setup on a single node # setup systemd service on a single node
$ ssh root@<node> $ ssh root@<node>
$ cd cluster $ cd cluster
$ ./stats-server setup $ ./stats-server setup
@ -67,4 +69,3 @@ $ ./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 )
``` ```

Loading…
Cancel
Save