A Go application that collects and displays system statistics including CPU, Memory, Disk, and System information. It can also send these statistics to an API endpoint.
- Real-time system statistics collection
- CPU usage and information
- Memory usage and availability
- Disk space monitoring
- System information (hostname, OS, kernel, uptime)
- Running processes count
- Selective data retrieval with command-line flags
- API integration for sending statistics
- Modular and extensible design
.
├── cmd/
│ └── server/ # Application entry point
├── internal/
│ ├── collector/ # System stats collection
│ │ ├── collector.go # Collector interface
│ │ ├── cpu/ # CPU stats collector
│ │ ├── memory/ # Memory stats collector
│ │ ├── disk/ # Disk stats collector
│ │ └── system/ # System stats collector
│ ├── models/ # Data models
│ │ └── stats.go
│ └── utils/ # Utility functions
│ └── format.go
├── go.mod
├── Makefile
└── README.md
# Clone the repository
git clone https://github.com/kritarth1107/go-server-stats.git
cd go-server-stats
# Download dependencies
go mod download
# Build the application
go build -o server-stats cmd/server/main.go
# Build for specific platforms
# For Linux
GOOS=linux GOARCH=amd64 go build -o server-stats-linux cmd/server/main.go
# For Windows
GOOS=windows GOARCH=amd64 go build -o server-stats.exe cmd/server/main.go
# For macOS
GOOS=darwin GOARCH=amd64 go build -o server-stats-mac cmd/server/main.go
# Run directly with Go
go run cmd/server/main.go get --all
# Run the built binary
./server-stats get --all
# Run with output to a file
./server-stats get --all > system-stats.json
The application supports three main commands: get
, send
, and version
.
The get
command retrieves system statistics:
# Show all statistics
./server-stats get --all
# Show only system information
./server-stats get --system
# Show memory and CPU information
./server-stats get --memory --cpu
# Show only disk space information
./server-stats get --diskspace
# Show help
./server-stats get -h
Available flags for get
:
--all
: Show all statistics--system
: Show system information--memory
: Show memory information--cpu
: Show CPU information--diskspace
: Show disk space information
The send
command sends system statistics to an API endpoint:
# Send all statistics
./server-stats send http://api.example.com/stats --all
# Send only system information
./server-stats send http://api.example.com/stats --system
# Send memory and CPU information
./server-stats send http://api.example.com/stats --memory --cpu
# Send only disk space information
./server-stats send http://api.example.com/stats --diskspace
# Show help
./server-stats send -h
Available flags for send
:
--all
: Send all statistics--system
: Send system information--memory
: Send memory information--cpu
: Send CPU information--diskspace
: Send disk space information
The version
command displays the application version:
./server-stats version
To see available commands and options:
./server-stats -h
For convenience, you can use the provided Makefile:
# Build the application
make build
# Run the application
make run
# Build for multiple platforms
make build-all
# Save stats to a file
make save-stats
# Clean build artifacts
make clean
# Run tests
make test
# Show command examples
make help-examples
# Show help
make help
- github.com/shirou/gopsutil
- Other dependencies are listed in go.mod
MIT