|
| 1 | +# Getting Started with LitmusChaos Control Plane Metrics |
| 2 | + |
| 3 | +This guide explains how to set up Prometheus scraping and Grafana visualization for the LitmusChaos GraphQL server metrics. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- LitmusChaos installed on a Kubernetes cluster |
| 8 | +- [kube-prometheus-stack](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) installed via Helm (includes Prometheus and Grafana) |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## Step 1: Verify the Metrics Endpoint |
| 13 | + |
| 14 | +The GraphQL server exposes Prometheus metrics on port `8889` at `/metrics`. This port is configurable via the `METRICS_PORT` environment variable. |
| 15 | + |
| 16 | +Verify the metrics server is running: |
| 17 | + |
| 18 | +```bash |
| 19 | +kubectl port-forward -n litmus deployment/litmusportal-server 8889:8889 |
| 20 | +curl http://localhost:8889/metrics | grep litmus_ |
| 21 | +``` |
| 22 | + |
| 23 | +You should see metrics like `litmus_api_requests_total`, `litmus_experiment_runs_total`, and `litmus_experiment_status`. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Step 2: Create the Metrics Service |
| 28 | + |
| 29 | +Create a Kubernetes Service to expose the metrics port: |
| 30 | + |
| 31 | +```yaml |
| 32 | +apiVersion: v1 |
| 33 | +kind: Service |
| 34 | +metadata: |
| 35 | + name: litmus-server-metrics |
| 36 | + namespace: litmus |
| 37 | + labels: |
| 38 | + app: litmus-server-metrics |
| 39 | +spec: |
| 40 | + selector: |
| 41 | + component: litmusportal-server |
| 42 | + ports: |
| 43 | + - name: metrics |
| 44 | + port: 8889 |
| 45 | + targetPort: 8889 |
| 46 | + type: ClusterIP |
| 47 | +``` |
| 48 | +
|
| 49 | +Apply it: |
| 50 | +
|
| 51 | +```bash |
| 52 | +kubectl apply -f litmus-server-metrics-service.yaml |
| 53 | +``` |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## Step 3: Create a ServiceMonitor |
| 58 | + |
| 59 | +Create a `ServiceMonitor` so Prometheus automatically discovers and scrapes the metrics: |
| 60 | + |
| 61 | +```yaml |
| 62 | +apiVersion: monitoring.coreos.com/v1 |
| 63 | +kind: ServiceMonitor |
| 64 | +metadata: |
| 65 | + name: litmus-server-metrics |
| 66 | + namespace: litmus |
| 67 | + labels: |
| 68 | + release: prometheus |
| 69 | +spec: |
| 70 | + selector: |
| 71 | + matchLabels: |
| 72 | + app: litmus-server-metrics |
| 73 | + endpoints: |
| 74 | + - port: metrics |
| 75 | + path: /metrics |
| 76 | + interval: 30s |
| 77 | +``` |
| 78 | +
|
| 79 | +Apply it: |
| 80 | +
|
| 81 | +```bash |
| 82 | +kubectl apply -f litmus-server-metrics-monitor.yaml |
| 83 | +``` |
| 84 | + |
| 85 | +> **Note:** The `release: prometheus` label must match the label selector configured in your Prometheus operator. If you used a different Helm release name, update this label accordingly. |
| 86 | +
|
| 87 | +--- |
| 88 | + |
| 89 | +## Step 4: Verify Prometheus is Scraping |
| 90 | + |
| 91 | +Port-forward to Prometheus and verify the target is being scraped: |
| 92 | + |
| 93 | +```bash |
| 94 | +kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-prometheus 9090:9090 |
| 95 | +``` |
| 96 | + |
| 97 | +Open `http://localhost:9090/targets` and look for `litmus-server-metrics`. It should show as `UP`. |
| 98 | + |
| 99 | +You can also run a query in the Prometheus UI: |
| 100 | + |
| 101 | +``` |
| 102 | +litmus_api_requests_total |
| 103 | +``` |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Step 5: Import the Grafana Dashboard |
| 108 | + |
| 109 | +A pre-built Grafana dashboard is included at: |
| 110 | + |
| 111 | +``` |
| 112 | +chaoscenter/graphql/server/grafana/litmuschaos-metrics-dashboard.json |
| 113 | +``` |
| 114 | + |
| 115 | +To import it: |
| 116 | + |
| 117 | +1. Port-forward to Grafana: |
| 118 | +```bash |
| 119 | +kubectl port-forward -n monitoring deployment/prometheus-grafana 3000:3000 |
| 120 | +``` |
| 121 | + |
| 122 | +2. Open `http://localhost:3000` and log in. |
| 123 | + |
| 124 | +3. Go to **Dashboards → New → Import**. |
| 125 | + |
| 126 | +4. Upload `litmuschaos-metrics-dashboard.json`. |
| 127 | + |
| 128 | +5. Select **Prometheus** as the datasource and click **Import**. |
| 129 | + |
| 130 | +The dashboard includes panels for: |
| 131 | +- API request rate and response time |
| 132 | +- Experiment run counts and durations |
| 133 | +- Experiment status (active vs completed) |
| 134 | +- Infra agent counts |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## Available Metrics |
| 139 | + |
| 140 | +See [README.md](./README.md) for the full list of metrics, their labels, and descriptions. |
0 commit comments