Prometheus and Grafana

Every KiviDB Cloud database has a metrics endpoint in the Prometheus text format. It serves the same measurements the console graphs: memory, operations…

Every KiviDB Cloud database has a metrics endpoint in the Prometheus text format. It serves the same measurements the console graphs: memory, operations, clients, hit rate, keys, latency and network, from every node of the database. Point Prometheus, Grafana Agent, Datadog's OpenMetrics check or any other scraper that reads the text format at it.

GET https://api.kividb.io/instances/{database_id}/metrics/prometheus
Authorization: Bearer {api_key}

Every sample carries three labels of its own, beside the exporter's:

LabelValue
kividb_databasethe database's name
kividb_nodeprimary, replica-1, replica-2, ... (sharded: shard-0-primary, ...)
kividb_roleprimary or replica

Values are what each node reported in the last 90 seconds; a node that has not reported in that time is left out rather than repeated. A stopped database has no metrics, and the endpoint answers 503.

The key to scrape with

Create an API key under Settings → API keys with the Viewer role and limit it to the database. A Viewer key can read and change nothing, and a key limited to one database cannot reach any other, so a leaked scrape key exposes that database's metrics and settings, not its data.

Prometheus

scrape_configs:
  - job_name: kividb-orders
    scheme: https
    metrics_path: /instances/1c4a926e-0000-0000-0000-000000000000/metrics/prometheus
    authorization:
      type: Bearer
      credentials_file: /etc/prometheus/kividb-orders.key
    scrape_interval: 30s
    static_configs:
      - targets: ["api.kividb.io"]

Scraping more often than every 15 seconds returns the same values: nodes report every 15 seconds.

Grafana

Import this dashboard (Dashboards → New → Import) and choose your Prometheus data source. The database variable lists every database you scrape.

{
  "title": "KiviDB Cloud",
  "uid": "kividb-cloud",
  "schemaVersion": 39,
  "templating": {
    "list": [
      { "name": "datasource", "type": "datasource", "query": "prometheus" },
      {
        "name": "database",
        "type": "query",
        "datasource": { "uid": "${datasource}" },
        "query": "label_values(redis_up, kividb_database)",
        "refresh": 2
      }
    ]
  },
  "panels": [
    {
      "title": "Operations per second",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 },
      "datasource": { "uid": "${datasource}" },
      "targets": [{ "expr": "sum by (kividb_node) (rate(redis_commands_processed_total{kividb_database=\"$database\"}[1m]))", "legendFormat": "{{kividb_node}}" }]
    },
    {
      "title": "Memory used",
      "type": "timeseries",
      "fieldConfig": { "defaults": { "unit": "bytes" } },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 0 },
      "datasource": { "uid": "${datasource}" },
      "targets": [{ "expr": "redis_memory_used_bytes{kividb_database=\"$database\"}", "legendFormat": "{{kividb_node}}" }]
    },
    {
      "title": "Connected clients",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 8 },
      "datasource": { "uid": "${datasource}" },
      "targets": [{ "expr": "redis_connected_clients{kividb_database=\"$database\"}", "legendFormat": "{{kividb_node}}" }]
    },
    {
      "title": "Hit rate",
      "type": "timeseries",
      "fieldConfig": { "defaults": { "unit": "percentunit", "max": 1 } },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 8 },
      "datasource": { "uid": "${datasource}" },
      "targets": [{ "expr": "sum(rate(redis_keyspace_hits_total{kividb_database=\"$database\"}[5m])) / (sum(rate(redis_keyspace_hits_total{kividb_database=\"$database\"}[5m])) + sum(rate(redis_keyspace_misses_total{kividb_database=\"$database\"}[5m])))", "legendFormat": "hit rate" }]
    },
    {
      "title": "Command latency (p50, p99)",
      "type": "timeseries",
      "fieldConfig": { "defaults": { "unit": "µs" } },
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 16 },
      "datasource": { "uid": "${datasource}" },
      "targets": [
        { "expr": "histogram_quantile(0.5, sum by (le) (rate(redis_commands_latencies_usec_bucket{kividb_database=\"$database\"}[5m])))", "legendFormat": "p50" },
        { "expr": "histogram_quantile(0.99, sum by (le) (rate(redis_commands_latencies_usec_bucket{kividb_database=\"$database\"}[5m])))", "legendFormat": "p99" }
      ]
    },
    {
      "title": "Keys",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 16 },
      "datasource": { "uid": "${datasource}" },
      "targets": [{ "expr": "sum by (kividb_node) (redis_db_keys{kividb_database=\"$database\"})", "legendFormat": "{{kividb_node}}" }]
    }
  ]
}

Other tools

Anything that scrapes the Prometheus text format over HTTPS with a bearer token works the same way: Datadog's OpenMetrics check (openmetrics_endpoint with an Authorization header), New Relic's Prometheus integration, VictoriaMetrics and Grafana Alloy.