A Go-based metrics monitoring template: an agent that collects runtime/system metrics and a server that receives, stores and exposes them over HTTP. Storage can be in-memory, file-based, or PostgreSQL (with SQL migrations). Includes Docker Compose setups for local development and integration testing.
Originally scaffolded from the Yandex Praktikum "Go in DevOps" course template, it can be used as a starting point for building your own metrics collection / monitoring pipeline in Go.
- Agent (
cmd/agent) — periodically collects runtime (gopsutil) and Go runtime metrics (gauges & counters) and pushes them to the server over HTTP. - Server (
cmd/server) — accepts metrics via HTTP API (built onchirouter), persists them, and exposes endpoints to read stored values. - Storage backends — in-memory, local file (
STORE_FILE), or PostgreSQL viaDATABASE_DSN, with schema migrations (migrations/,pressly/goose). - Config — via environment variables / flags (
ilyakaznacheev/cleanenv). - Tests — unit tests per component and an integration test suite (
integration-test/) run against a real Postgres instance via Docker Compose.
- Language: Go 1.18
- HTTP router:
go-chi/chi - HTTP client:
go-resty/resty - Database: PostgreSQL,
jackc/pgx,lib/pq,Masterminds/squirrel(query builder),georgysavva/scany(scanning) - Migrations:
pressly/goose - Config:
ilyakaznacheev/cleanenv - System metrics:
shirou/gopsutil - Logging:
rs/zerolog - Testing:
stretchr/testify,golang/mock,Eun/go-hit(integration HTTP testing) - Containerization: Docker, Docker Compose
- Go 1.18+
- Docker & Docker Compose (for the containerized workflow / PostgreSQL storage)
git clone https://github.com/costynus/devops-tpl.git
cd devops-tpl
go mod tidymake build # docker-compose build
make run # docker-compose up (starts postgres + app)The server listens on :8080, PostgreSQL is exposed on :5432.
make run-server # go run ./cmd/server/main.go
make run-agent # go run ./cmd/agent/main.gomake unit-test # unit tests for ./internal/...
make test # unit tests (integration TODO)
make compose-up-integration-test # integration tests via docker-compose.test.yamlcmd/
agent/ # entrypoint: metrics collector/reporter
server/ # entrypoint: HTTP server (metrics receiver/storage)
internal/
app/ # application bootstrap (agent & server wiring)
entity/ # domain models (metric types, etc.)
usecase/ # business logic (collecting, storing, reading metrics)
infrastructure/ # HTTP handlers/clients, storage adapters (memory/file/postgres)
migrations/ # SQL migrations (goose)
config/ # configuration structs/loading
pkg/ # shared reusable packages
docker/ # Dockerfiles (local, etc.)
integration-test/ # end-to-end tests against a running stack
docker-compose.yaml # local dev stack (app + postgres)
docker-compose.test.yaml # integration-test stack
Makefile # common dev/test/build/run tasks
Data flow: agent collects metrics → sends them via HTTP to server → server's infrastructure layer parses requests → usecase layer applies business logic → metrics persisted through the configured storage adapter (memory, file, or Postgres via entity/migrations).
Key environment variables:
| Variable | Used by | Description |
|---|---|---|
ADDRESS |
server | HTTP listen address (e.g. :8080) |
KEY |
both | Signing key for metric hash validation |
STORE_FILE |
server | Path to file-based storage (if not using DB) |
DATABASE_DSN |
server | PostgreSQL DSN, enables DB-backed storage |
To pull in updates to autotests and other template parts:
git remote add -m main template https://github.com/yandex-praktikum/go-musthave-devops-tpl.git
git fetch template && git checkout template/main .githubThen commit the resulting changes to your repository.