docs/en/guides/11-grafana-prometheus.md
This document provides a complete end-to-end guide from scratch:
/metrics is accessibleIf you can already access http://<host>:<port>/metrics, you can skip ahead to the "Start Prometheus" section of this document.
OpenViking does not directly provide a Grafana page. The standard pipeline is:
OpenViking -> /metrics -> Prometheus -> Grafana
Where:
/metricsBefore starting, please confirm:
http://localhost:30300/metricsOpenViking must have metrics enabled first. Minimal configuration reference:
{
"server": {
"observability": {
"metrics": {
"enabled": true
}
}
}
}
After writing the configuration to ~/.openviking/ov.conf, restart OpenViking Server.
If you have not started the service yet, you can refer to:
openviking-server doctor
openviking-server --port 30300
Then verify:
curl http://localhost:30300/metrics
If the response includes text with the openviking_ prefix, metrics are enabled. For example:
# HELP openviking_http_requests_total Total number of HTTP requests
# TYPE openviking_http_requests_total counter
openviking_http_requests_total{method="GET",route="/api/v1/system/status",status="200"} 12
If the response returns Prometheus metrics are disabled., the configuration has not taken effect or the service has not been restarted.
The repository already provides a set of ready-to-run observability examples, located at:
examples/grafana/docker-compose.ymlexamples/grafana/prometheus.ymlexamples/grafana/grafana/provisioning/datasources/prometheus.ymlexamples/grafana/grafana/provisioning/dashboards/openviking.ymlIn addition, for the scenario where OpenViking continues to listen on 127.0.0.1 / localhost on Linux, the repository also provides a localhost-specific set of examples:
examples/grafana/docker-compose.localhost.ymlexamples/grafana/prometheus.localhost.ymlexamples/grafana/grafana/provisioning-localhost/datasources/prometheus.ymlexamples/grafana/grafana/provisioning-localhost/dashboards/openviking.ymlThe difference between the two approaches is:
docker-compose.yml: the general-purpose approach, where Prometheus accesses the host from the container network, suitable when OpenViking listens on 0.0.0.0docker-compose.localhost.yml: the Linux localhost approach, where Prometheus and Grafana directly use the host network, suitable when OpenViking continues to listen on 127.0.0.1If you do not currently want to expose OpenViking on 0.0.0.0, it is recommended to use docker-compose.localhost.yml first.
By default, this configuration does several things:
3090913000http://127.0.0.1:30909OpenViking - Feedback Baseline, making it easy to directly view the baseline metrics for openviking_feedback_* and openviking_feedback_channel_*Run directly:
docker compose -f examples/grafana/docker-compose.yml up -d
After startup completes, you can access:
Prometheus: http://localhost:30909
Grafana: http://localhost:13000
In this example, the default Grafana credentials are fixed as:
adminadminIf your OpenViking continues to listen on 127.0.0.1:30300, and you do not want to change OpenViking to 0.0.0.0 just for Prometheus scraping, use the following compose setup:
docker compose -f examples/grafana/docker-compose.localhost.yml up -d
The characteristics of this approach are:
127.0.0.1:30300/metricshttp://127.0.0.1:309090.0.0.0root_api_key"The access addresses are still:
Prometheus: http://localhost:30909
Grafana: http://localhost:13000
If 30909 or 13000 on the host is already occupied:
--web.listen-address=0.0.0.0:30909 in examples/grafana/docker-compose.localhost.ymlGF_SERVER_HTTP_PORT=13000 in examples/grafana/docker-compose.localhost.ymlhttp://127.0.0.1:30909 in examples/grafana/grafana/provisioning-localhost/datasources/prometheus.yml to the new portIf you only want a quick deployment, once you reach this point you can jump ahead to "How to Verify the Entire Pipeline Is Working".
The contents of examples/grafana/prometheus.yml used in the compose example are as follows:
global:
scrape_interval: 15s
scrape_configs:
- job_name: openviking
metrics_path: /metrics
static_configs:
- targets: ["host.docker.internal:30300"]
Explanation:
targets as host.docker.internal:30300localhost:30300host.docker.internal is not available in your Linux Docker environment, change it to the actual host IP, for example 192.168.1.10:30300If your OpenViking is not listening on 30300, change the target address in this file to your actual port, then re-run:
docker compose -f examples/grafana/docker-compose.yml up -d
If you are using the Linux localhost approach, the corresponding file to modify is:
examples/grafana/prometheus.localhost.ymlFor example, if OpenViking is actually listening on 127.0.0.1:1933, change it to:
targets: ["127.0.0.1:1933"]
Then re-run:
docker compose -f examples/grafana/docker-compose.localhost.yml up -d
If you are using the compose files above, you do not need to perform this step manually, because Compose automatically creates the default network.
Only when you insist on using docker run to start Prometheus and Grafana separately do you need to create an independent network first:
docker network create openviking-observability
If it reports that the network already exists, you can ignore it.
If you have already used docker compose -f examples/grafana/docker-compose.yml up -d, you can skip this section.
On many machines, 9090 is already occupied by another service. To reduce conflicts, it is recommended here to map the host port to 30909:
docker run -d \
--name prometheus \
--network openviking-observability \
-p 30909:9090 \
-v "$PWD/prometheus.yml:/etc/prometheus/prometheus.yml:ro" \
prom/prometheus
After startup, open in your browser:
http://localhost:30909
Once in the Prometheus UI, enter the following in the query box:
openviking_http_requests_total
Or:
openviking_service_readiness
If you can find time series, it means Prometheus has successfully scraped OpenViking metrics.
Common cause: the host port is occupied, for example:
Bind for 0.0.0.0:9090 failed: port is already allocated
How to handle:
30909:90909090http://localhost:30909If you have already used docker compose -f examples/grafana/docker-compose.yml up -d, you can skip this section.
Similarly, 3000 on many machines is also often occupied. It is recommended to map Grafana to host port 13000:
docker run -d \
--name grafana \
--network openviking-observability \
-p 13000:3000 \
grafana/grafana
After startup, open:
http://localhost:13000
The default initial Grafana credentials are usually:
adminadminIf your environment has changed the default credentials, use the actual values.
If you are using the repository's built-in compose files, you can usually skip this step as well, because the data source is automatically provisioned.
In the Grafana UI:
Connections or Data sources in the left sidebarAdd data sourcePrometheusURL field, enter: http://prometheus:9090Save & testThe reason for entering http://prometheus:9090 here is:
openviking-observabilityIf Save & test fails, first run:
docker ps
Confirm that both the prometheus and grafana containers are running.
After adding the data source, do not rush to import a dashboard. It is recommended to first verify basic queries in Explore.
It is recommended to try these queries first:
Request volume:
rate(openviking_http_requests_total[5m])
View request volume and status codes by route:
sum by (route, status) (rate(openviking_http_requests_total[5m]))
P95 latency:
histogram_quantile(0.95, sum by (le, route) (rate(openviking_http_request_duration_seconds_bucket[5m])))
Queue backlog:
openviking_queue_pending
Model call volume:
rate(openviking_model_calls_total[5m])
Token usage:
rate(openviking_operation_tokens_total[5m])
If you are not yet sure which metric names exist, you can first query:
{__name__=~"openviking_.*"}
If you are using the repository's built-in compose files, these two dashboards will be automatically loaded into the OpenViking folder after Grafana starts.
If you want to import them manually, just follow the steps below.
The repository already provides Grafana dashboards that can be imported directly:
examples/grafana/openviking_demo_dashboard.jsonexamples/grafana/openviking_token_demo_dashboard.jsonImport steps:
Dashboards in the left sidebar of GrafanaNew or Import in the top right cornerexamples/grafana/openviking_demo_dashboard.jsonImportNotes:
openviking_demo_dashboard.json is suitable as a basic overview dashboardopenviking_token_demo_dashboard.json depends on the tim012432-calendarheatmap-panel plugin; before it is installed, some panels may not display properlyYou can verify in the following order:
curl http://localhost:30300/metrics returns metric texthttp://localhost:30909 and you can find openviking_http_requests_total in Prometheushttp://localhost:13000 and see that the Prometheus data source already exists, or that a manual Save & test succeedsrate(openviking_http_requests_total[5m]) in Grafana Explore produces a graphAs long as all five steps pass, the entire pipeline is working.
/metrics is accessible, but Prometheus cannot find any dataFirst check:
targets in prometheus.yml is written correctly30300 on the hostIf you are using the repository's built-in compose files, first check:
docker compose -f examples/grafana/docker-compose.yml logs prometheus
If you suspect a container-to-host access issue, you can change host.docker.internal to the actual host IP.
Example error:
Bind for 0.0.0.0:9090 failed: port is already allocated
How to handle: change to a different host port, for example:
-p 30909:9090
How to handle: change to a different host port, for example:
-p 13000:3000
First check:
openviking_* metrics already exist in PrometheusIf you are using the compose auto-import approach, you can also first confirm whether the dashboard has been loaded:
Dashboards in the left sidebarOpenViking folder existsThis is usually not because the dashboard file is corrupted, but because:
It is recommended to first go back to Explore and manually run PromQL to confirm that the basic queries do have data.