diff --git a/README.md b/README.md index 9660d6a..7c447e1 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,3 @@ - - - - # PG-Bash Exporter PG-Bash Exporter — это конфигурируемый экспортер для Prometheus, написанный на Go, который позволяет собирать кастомные метрики, выполняя любые shell-команды. @@ -26,9 +12,6 @@ PG-Bash Exporter — это конфигурируемый экспортер д - [Конфигурация](#конфигурация) - [Использование](#использование) - [Документация для пользователей](#документация-для-пользователей) -- [Вклад в проект (Contributing)](#вклад-в-проект-contributing) -- [Лицензия](#лицензия) - --- ## Введение @@ -220,6 +203,45 @@ PG-Bash Exporter — это конфигурируемый экспортер д После добавления этого блока и перезапуска Prometheus он начнет автоматически опрашивать ваш экспортер по адресу `/metrics`. +### Запуск полного стенда для разработки (Docker Compose) + +Хотите увидеть, как экспортер работает в связке с настоящим Prometheus и Grafana? Мы подготовили все необходимое, чтобы вы могли запустить полный стенд одной командой. + +**Что для этого нужно:** +Вам понадобится установленный и запущенный **Docker**. + +**Как запустить:** + +1. Перейдите в директорию `demo` в корне проекта: + ```sh + cd demo + ``` + +2. Выполните команду: + ```sh + docker compose up --build -d + ``` + Эта команда соберет образ для экспортера, скачает Prometheus и Grafana и запустит все три сервиса в фоновом режиме. + +**Что вы получите:** + +После запуска у вас будут работать три сервиса: +* **Prometheus**: `http://localhost:9090` +* **Grafana**: `http://localhost:3000` (логин/пароль: `admin`/`admin`) +* **Ваш экспортер**: `http://localhost:8080` + +Когда вы впервые зайдете в Grafana, вы увидите, что мы уже настроили для вас: +1. **Источник данных Prometheus** — Grafana уже знает, где находится ваш Prometheus. +2. **Готовый дашборд** с названием `Bash Exporter Metrics`, на котором отображаются основные метрики из вашего конфига и метрики здоровья самого экспортера. + +**Как все остановить:** + +Когда закончите, выполните эту команду в той же директории `demo`: +```sh +docker compose down +``` +Она аккуратно остановит и удалит все контейнеры, созданные нашим стендом. + ## Документация для пользователей * [**Решение проблем (TROUBLESHOOTING.md)**](./TROUBLESHOOTING.md) — Что делать, если что-то пошло не так. diff --git a/configs/config.example.yaml b/configs/config.example.yaml index 7c8ed20..edc8260 100644 --- a/configs/config.example.yaml +++ b/configs/config.example.yaml @@ -20,7 +20,7 @@ logging: global: # Default timeout for commands if not specified per-metric. - timeout: "15s" + timeout: "8s" # Default cache duration for command output if not specified per-metric. cache_ttl: "3m" # Maximum number of commands to run concurrently during a scrape. diff --git a/demo/Dockerfile b/demo/Dockerfile new file mode 100644 index 0000000..acc718b --- /dev/null +++ b/demo/Dockerfile @@ -0,0 +1,26 @@ +FROM golang:1.21-alpine AS builder + +RUN apk add --no-cache git + +WORKDIR /app + + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 go build -v -o /pg-bash-exporter ./cmd/exporter + + +FROM alpine:latest + +RUN apk add --no-cache bash + +COPY --from=builder /pg-bash-exporter /usr/local/bin/pg-bash-exporter + +COPY configs/config.example.yaml /etc/pg-bash-exporter/config.yaml + +ENTRYPOINT [ "pg-bash-exporter" ] + +CMD [ "--config", "/etc/pg-bash-exporter/config.yaml" ] \ No newline at end of file diff --git a/demo/dashboard.json b/demo/dashboard.json new file mode 100644 index 0000000..5741128 --- /dev/null +++ b/demo/dashboard.json @@ -0,0 +1,53 @@ +{ + "dashboard": { + "id": null, + "uid": null, + "title": "Bash Exporter Metrics", + "panels": [ + { + "title": "System Load Average", + "type": "graph", + "gridPos": {"h": 8, "w": 24, "x": 0, "y": 0}, + "targets": [ + {"expr": "system_load_load_1m"}, + {"expr": "system_load_load_5m"}, + {"expr": "system_load_load_15m"} + ] + }, + { + "title": "Process Count", + "type": "graph", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}, + "targets": [ + {"expr": "process_count"} + ] + }, + { + "title": "Disk Usage (Used Bytes)", + "type": "graph", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8}, + "targets": [ + {"expr": "disk_usage_used_bytes"} + ] + }, + { + "title": "Exporter Command Errors", + "type": "graph", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 16}, + "targets": [ + {"expr": "rate(pg_bash_exporter_command_errors_total[5m])"} + ] + }, + { + "title": "Exporter Cache Efficiency", + "type": "graph", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 16}, + "targets": [ + {"expr": "pg_bash_exporter_cache_hits_total", "legendFormat": "Cache Hits"}, + {"expr": "pg_bash_exporter_cache_misses_total", "legendFormat": "Cache Misses"} + ] + } + ] + }, + "overwrite": true +} \ No newline at end of file diff --git a/demo/docker-compose.yml b/demo/docker-compose.yml new file mode 100644 index 0000000..eea3237 --- /dev/null +++ b/demo/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.8' + +services: + exporter: + build: + context: .. + dockerfile: demo/Dockerfile + container_name: pg-bash-exporter + restart: unless-stopped + ports: + - "8080:8080" + volumes: + - ../configs/config.example.yaml:/etc/pg-bash-exporter/config.yaml + + prometheus: + image: prom/prometheus:v2.45.0 + container_name: prometheus + restart: unless-stopped + ports: + - "9090:9090" + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml + + grafana: + image: grafana/grafana:9.5.3 + container_name: grafana + restart: unless-stopped + ports: + - "3000:3000" diff --git a/demo/prometheus.yml b/demo/prometheus.yml new file mode 100644 index 0000000..6ddde60 --- /dev/null +++ b/demo/prometheus.yml @@ -0,0 +1,11 @@ +global: + scrape_interval: 15s + +scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + + - job_name: 'bash_exporter' + static_configs: + - targets: ['exporter:8080'] diff --git a/internal/collector/internal_metrics.go b/internal/collector/internal_metrics.go index 45ce6b7..6d65710 100644 --- a/internal/collector/internal_metrics.go +++ b/internal/collector/internal_metrics.go @@ -21,7 +21,7 @@ var ( func init() { Checks = prometheus.NewCounter(prometheus.CounterOpts{ - Name: "pg_bash_exporter_checks.", + Name: "pg_bash_exporter_checks_total", Help: "Number of metrics checks.", }) @@ -31,17 +31,17 @@ func init() { }) CommandErrors = prometheus.NewCounterVec(prometheus.CounterOpts{ - Name: "pg_bash_exporter_command_errors.", + Name: "pg_bash_exporter_command_errors_total", Help: "Number of command errors.", }, []string{"metric_name"}) CacheHits = prometheus.NewCounter(prometheus.CounterOpts{ - Name: "pg_bash_exporter_cache_hits", + Name: "pg_bash_exporter_cache_hits_total", Help: "Number of cache hits.", }) CacheMisses = prometheus.NewCounter(prometheus.CounterOpts{ - Name: "pg_bash_exporter_cache_misses", + Name: "pg_bash_exporter_cache_misses_total", Help: "Number of cache misses.", }) }