Development Guide¶
Want to contribute? Here is how to build and test TinyMonitor.
Prerequisites¶
- Go 1.21+
- Make (optional but recommended)
Setup Environment¶
-
Clone the repository:
-
Build the project:
-
Run tests:
Project Structure¶
tinymonitor/
├── cmd/tinymonitor/
│ ├── main.go # Entry point
│ └── cmd/ # CLI commands (Cobra)
│ ├── root.go # Main monitoring command
│ ├── version.go # Version command
│ └── validate.go # Config validation command
├── internal/
│ ├── config/ # TOML configuration loading & validation
│ ├── monitor/ # Main monitoring loop
│ ├── metrics/ # Metric collectors (CPU, memory, disk, etc.)
│ ├── alerts/ # Alert providers (Ntfy, SMTP, etc.)
│ ├── models/ # Shared types
│ └── utils/ # Utility functions
├── configs/ # Example configurations
├── docs/ # Documentation
├── go.mod
└── Makefile
Commands¶
We use a Makefile to automate tasks:
| Command | Description |
|---|---|
make build |
Build the binary. |
make test |
Run unit tests. |
make vet |
Run static analysis. |
make release |
Build binaries for all platforms. |
make clean |
Remove build artifacts. |
CLI Commands¶
TinyMonitor uses Cobra for CLI management:
tinymonitor # Run the monitoring agent
tinymonitor version # Show version information
tinymonitor validate # Validate configuration file
tinymonitor -c config.toml # Run with specific config
Adding a New Metric¶
- Create a new file in
internal/metrics/(e.g.,network.go) - Implement the
Collectorinterface: - Register the collector in
internal/monitor/monitor.go
Adding a New Alert Provider¶
- Create a new file in
internal/alerts/(e.g.,slack.go) - Implement the
Providerinterface: - Register the provider in
internal/alerts/manager.go
Configuration Validation¶
When adding new configuration fields, update the validation in internal/config/config.go:
func (c *Config) Validate() ValidationErrors {
var errs ValidationErrors
// Add your validation logic here
return errs
}
CI/CD Pipeline¶
The project uses GitHub Actions for continuous integration:
- Tests: Runs on every push to
main. - Build: Runs on every Tag (
v*). Uses GoReleaser to build binaries for Linux (AMD64/ARM64) and macOS (Intel/Silicon). - Release: Automatically creates a GitHub Release with the binaries attached.