Git Product home page Git Product logo

go-stats-server's Introduction

Go Stats Server

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.

Commands

The protocol supports the following commands:

  • cpu — returns the CPU usage percentage
  • memory — returns the memory usage in MB
  • network — returns the network usage in bytes
  • storage — returns the storage usage in GB
  • uptime — returns the system uptime in seconds
  • temperature — returns the CPU temperature of Big and Little cores in Celsius

[TODO: check if the command docs are correct]

Usage

  1. Build the Server:

    $ CGO_ENABLED=0 GOARCH=<arch> go build -a -ldflags '-s -w' -o ./out/stats-server main.go
  2. Run the 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" or "uptime".

    Example using nc:

    $ time ( echo "cpu" | nc <hostname> 12345 )

    or directly using golang:

    conn, _ := net.Dial("tcp", "<hostname>:12345")
    conn.Write([]byte("cpu\n"))
    
    data, _ := io.RealAll(conn)
    log.Printf("data: %s", data)

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 GitHub release, and uploads the compiled binary as an artifact.

Self-Installing Binary

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.

$ 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 'chmod -v +x ./cluster/stats-server'

# setup systemd services on all nodes
$ parallel --nonall --slf nodes.txt './cluster/stats-server setup'

# setup systemd service on a single node
$ ssh root@<node>
$ cd cluster
$ ./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'

Credits

go-stats-server's People

Contributors

aziis98 avatar

Stargazers

Luca Lombardo avatar Francesco Minnocci avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.