How srvariable/mongo-exporter works
Project Type and Purpose
• This is a Go-based “mongo-exporter” microservice whose sole responsibility is to collect various MongoDB metrics (CPU, RAM, connections, operation counters, collection stats) and expose them via HTTP endpoints. It’s designed for integration with Prometheus (scraping) and Grafana (visualization).
Core System Components
a. HTTP API Layer
• Built with Gin (router/router.go, router/*.go).
• Defines endpoints under /v1/.
• Controllers dispatch to the internal metric service.
b. Service Layer
• internal/metric/service: orchestrates fetching of data from repositories and mapping to DTOs.
c. Repository Layer
• internal/metric/repository: two implementations
• mongo driver (internal/metric/repository/mongo/*)
• in-memory mocks (for tests)
• Exposes a common interface (i_repository.go).
d. Domain Layer
• internal/metric/domain: value objects and entities representing CPU, RAM, connections, opcounters, collection metrics.
e. Database
• MongoDB container (docker/mongo/Dockerfile, docker-compose.yml).
f. Monitoring Stack
• Prometheus (prometheus/prometheus.yml) scrapes exposed metrics.
• Grafana (grafana/dashboards, grafana/datasources) visualizes time-series.
g. Infrastructure & Deployment
• Docker Compose orchestrates Go app, MongoDB, Prometheus, Grafana.
• Makefile for build and deployment.
• .env for runtime configuration (DB_HOST, ports, credentials).