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