diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 15:17:04 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-04 15:24:19 +0000 |
| commit | fd0c87c787d0626b3546fa571541c9c809711821 (patch) | |
| tree | 934f20d973127f380b807d2bd44b25c197cf349c /docs/how-to | |
| parent | 762cd8e815e797f173f541795de774fbbf978fc3 (diff) | |
add prometheus metrics
Diffstat (limited to 'docs/how-to')
| -rw-r--r-- | docs/how-to/prometheus-setup.md | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/docs/how-to/prometheus-setup.md b/docs/how-to/prometheus-setup.md new file mode 100644 index 0000000..741255b --- /dev/null +++ b/docs/how-to/prometheus-setup.md | |||
| @@ -0,0 +1,178 @@ | |||
| 1 | # Prometheus and Grafana Setup | ||
| 2 | |||
| 3 | This guide shows how to configure Prometheus and Grafana to monitor ngit-grasp. | ||
| 4 | |||
| 5 | ## Prerequisites | ||
| 6 | |||
| 7 | - ngit-grasp running with metrics enabled (default: `--metrics-enabled true`) | ||
| 8 | - Prometheus server | ||
| 9 | - Grafana (optional, for dashboards) | ||
| 10 | |||
| 11 | ## Verify Metrics Endpoint | ||
| 12 | |||
| 13 | First, verify that ngit-grasp is exposing metrics: | ||
| 14 | |||
| 15 | ```bash | ||
| 16 | curl http://localhost:8080/metrics | ||
| 17 | ``` | ||
| 18 | |||
| 19 | You should see Prometheus-formatted metrics like: | ||
| 20 | |||
| 21 | ``` | ||
| 22 | # HELP ngit_websocket_connections_active Current active WebSocket connections | ||
| 23 | # TYPE ngit_websocket_connections_active gauge | ||
| 24 | ngit_websocket_connections_active 5 | ||
| 25 | |||
| 26 | # HELP ngit_git_operations_total Git operations by type and status | ||
| 27 | # TYPE ngit_git_operations_total counter | ||
| 28 | ngit_git_operations_total{operation="clone",status="success"} 42 | ||
| 29 | ``` | ||
| 30 | |||
| 31 | ## NixOS Configuration | ||
| 32 | |||
| 33 | ### Prometheus | ||
| 34 | |||
| 35 | Add ngit-grasp as a scrape target: | ||
| 36 | |||
| 37 | ```nix | ||
| 38 | services.prometheus = { | ||
| 39 | enable = true; | ||
| 40 | scrapeConfigs = [ | ||
| 41 | { | ||
| 42 | job_name = "ngit-grasp"; | ||
| 43 | static_configs = [{ | ||
| 44 | targets = [ "localhost:8080" ]; # ngit-grasp bind address | ||
| 45 | }]; | ||
| 46 | scrape_interval = "15s"; | ||
| 47 | metrics_path = "/metrics"; | ||
| 48 | } | ||
| 49 | ]; | ||
| 50 | }; | ||
| 51 | ``` | ||
| 52 | |||
| 53 | ### Grafana with Prometheus Datasource | ||
| 54 | |||
| 55 | ```nix | ||
| 56 | services.grafana = { | ||
| 57 | enable = true; | ||
| 58 | settings.server.http_port = 3000; | ||
| 59 | |||
| 60 | provision.datasources.settings.datasources = [{ | ||
| 61 | name = "Prometheus"; | ||
| 62 | type = "prometheus"; | ||
| 63 | url = "http://localhost:9090"; | ||
| 64 | isDefault = true; | ||
| 65 | }]; | ||
| 66 | |||
| 67 | # Optional: provision the ngit-grasp dashboard | ||
| 68 | provision.dashboards.settings.providers = [{ | ||
| 69 | name = "ngit-grasp"; | ||
| 70 | options.path = "/path/to/ngit-grasp/docs/grafana"; | ||
| 71 | }]; | ||
| 72 | }; | ||
| 73 | ``` | ||
| 74 | |||
| 75 | ## Docker Compose Configuration | ||
| 76 | |||
| 77 | For non-NixOS deployments: | ||
| 78 | |||
| 79 | ```yaml | ||
| 80 | version: '3.8' | ||
| 81 | services: | ||
| 82 | prometheus: | ||
| 83 | image: prom/prometheus:latest | ||
| 84 | volumes: | ||
| 85 | - ./prometheus.yml:/etc/prometheus/prometheus.yml | ||
| 86 | ports: | ||
| 87 | - "9090:9090" | ||
| 88 | |||
| 89 | grafana: | ||
| 90 | image: grafana/grafana:latest | ||
| 91 | ports: | ||
| 92 | - "3000:3000" | ||
| 93 | volumes: | ||
| 94 | - ./docs/grafana:/var/lib/grafana/dashboards | ||
| 95 | environment: | ||
| 96 | - GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/var/lib/grafana/dashboards/ngit-grasp-dashboard.json | ||
| 97 | ``` | ||
| 98 | |||
| 99 | With `prometheus.yml`: | ||
| 100 | |||
| 101 | ```yaml | ||
| 102 | global: | ||
| 103 | scrape_interval: 15s | ||
| 104 | |||
| 105 | scrape_configs: | ||
| 106 | - job_name: 'ngit-grasp' | ||
| 107 | static_configs: | ||
| 108 | - targets: ['host.docker.internal:8080'] # or your ngit-grasp host | ||
| 109 | metrics_path: /metrics | ||
| 110 | ``` | ||
| 111 | |||
| 112 | ## Import Dashboard | ||
| 113 | |||
| 114 | 1. Open Grafana at `http://localhost:3000` | ||
| 115 | 2. Go to **Dashboards** → **Import** | ||
| 116 | 3. Upload `docs/grafana/ngit-grasp-dashboard.json` | ||
| 117 | 4. Select your Prometheus datasource | ||
| 118 | 5. Click **Import** | ||
| 119 | |||
| 120 | ## Key Metrics to Monitor | ||
| 121 | |||
| 122 | ### Connection Health | ||
| 123 | - `ngit_websocket_connections_active` - Current active connections | ||
| 124 | - `ngit_websocket_unique_ips` - Number of unique client IPs | ||
| 125 | - `ngit_websocket_flagged_abusers` - IPs exceeding connection threshold | ||
| 126 | |||
| 127 | ### Git Operations | ||
| 128 | - `ngit_git_operations_total` - Operations by type (clone/fetch/push) and status | ||
| 129 | - `ngit_git_bytes_total` - Bandwidth by direction (in/out) | ||
| 130 | - `ngit_git_top_repos_bytes` - Top N repositories by bandwidth | ||
| 131 | |||
| 132 | ### Nostr Events | ||
| 133 | - `ngit_events_received_total` - Events received by kind | ||
| 134 | - `ngit_events_stored_total` - Events successfully stored | ||
| 135 | - `ngit_events_rejected_total` - Events rejected by reason | ||
| 136 | |||
| 137 | ### System | ||
| 138 | - `ngit_uptime_seconds` - Server uptime | ||
| 139 | - `ngit_build_info` - Version and commit info | ||
| 140 | - `ngit_repositories_total` - Total hosted repositories | ||
| 141 | |||
| 142 | ## Example Alerts | ||
| 143 | |||
| 144 | Add to your Prometheus alerting rules: | ||
| 145 | |||
| 146 | ```yaml | ||
| 147 | groups: | ||
| 148 | - name: ngit-grasp | ||
| 149 | rules: | ||
| 150 | - alert: HighConnectionCount | ||
| 151 | expr: ngit_websocket_connections_active > 100 | ||
| 152 | for: 5m | ||
| 153 | labels: | ||
| 154 | severity: warning | ||
| 155 | annotations: | ||
| 156 | summary: "High number of WebSocket connections" | ||
| 157 | |||
| 158 | - alert: AbusiveIPs | ||
| 159 | expr: ngit_websocket_flagged_abusers > 0 | ||
| 160 | for: 1m | ||
| 161 | labels: | ||
| 162 | severity: warning | ||
| 163 | annotations: | ||
| 164 | summary: "{{ $value }} IPs flagged for excessive connections" | ||
| 165 | |||
| 166 | - alert: PushAuthorizationFailures | ||
| 167 | expr: rate(ngit_git_operations_total{operation="push",status="denied"}[5m]) > 0.1 | ||
| 168 | for: 5m | ||
| 169 | labels: | ||
| 170 | severity: info | ||
| 171 | annotations: | ||
| 172 | summary: "Elevated push authorization failures" | ||
| 173 | ``` | ||
| 174 | |||
| 175 | ## See Also | ||
| 176 | |||
| 177 | - [Monitoring Overview](../explanation/monitoring.md) - Architecture and design | ||
| 178 | - [Configuration Reference](../reference/configuration.md) - All config options \ No newline at end of file | ||