Skip to content

Observability / Task

Query metrics

Updated · 4 min read

Query the CPU, network, or volume metrics of one resource over a time window with the GraphQL API, and choose the period and statistic.

On this page3 sections

Use the observability.metrics query to get a series of data points for one compute instance, volume, or network interface. You choose the metrics, the time window, the length of each period, and whether each data point is a per-second rate or a total increase.

Before you begin

Query the metrics

  1. Find the URN of the resource. Each command lists the resources of a project with their urn field:

    terminal
    origin compute list-instances --project-urn <project-urn>
    origin storage list-volumes --project-urn <project-urn>
    origin network list-network-interfaces --project-urn <project-urn>
  2. Pick the metric names for that resource type. An instance has oc_compute_instance_cpu_seconds_total; a volume and a network interface each have two metrics. See Metrics reference.

  3. Use a periodSeconds of at least 60. The platform collects a value every 30 seconds, and each data point needs two collected values inside its period; a shorter period often returns no data points.

  4. Keep the total number of data points, across all metrics in the query, at or below 11,000. For example, one metric over 7 days at a 300-second period is 2,017 data points.

  5. Make from a multiple of the period (for example, a full hour) so data points line up with clock times.

  6. Save the request as metrics-query.json. This example asks for the CPU use of an instance as a per-second rate, in 5-minute periods, over 15 minutes:

    JSON
    {
      "query": "query Metrics($input: MetricQueryInput!) { observability { metrics(input: $input) { metricName resourceUrn unit dataPoints { timestamp value } } } }",
      "variables": {
        "input": {
          "resourceUrn": "<instance-urn>",
          "metricNames": ["oc_compute_instance_cpu_seconds_total"],
          "from": "2026-10-03T10:00:00Z",
          "to": "2026-10-03T10:15:00Z",
          "periodSeconds": 300,
          "statistic": "RATE"
        }
      }
    }

    Formatted, the GraphQL query in the query field reads:

    GraphQL
    query Metrics($input: MetricQueryInput!) {
      observability {
        metrics(input: $input) {
          metricName
          resourceUrn
          unit
          dataPoints {
            timestamp
            value
          }
        }
      }
    }
  7. Send the request:

    terminal
    curl -s https://api.origincloud.eu/graphql \
      -H "$(origin id token --as-header --raw)" \
      -H "Content-Type: application/json" \
      --data @metrics-query.json
  8. Check the response. It contains one series per metric name you asked for, in the same order. For RATE on oc_compute_instance_cpu_seconds_total, a value of 0.5 means the instance used half a vCPU on average during that period. Example output (illustrative):

    JSON
    {
      "data": {
        "observability": {
          "metrics": [
            {
              "metricName": "oc_compute_instance_cpu_seconds_total",
              "resourceUrn": "<instance-urn>",
              "unit": "seconds",
              "dataPoints": [
                { "timestamp": "2026-10-03T10:00:00+00:00", "value": 0.12 },
                { "timestamp": "2026-10-03T10:05:00+00:00", "value": 0.48 },
                { "timestamp": "2026-10-03T10:10:00+00:00", "value": 1.73 },
                { "timestamp": "2026-10-03T10:15:00+00:00", "value": 0.51 }
              ]
            }
          ]
        }
      }
    }

    Each data point covers the period that ends at its timestamp. The unit is the unit of the counter, so a RATE of a seconds counter is seconds per second.

    Both ends of the window are included: data points fall on from, every periodSeconds after it, and to, which is why a 15-minute window at 300 seconds returns four points. The first point, at from, covers the period before from (here 09:55 to 10:00). To cover only the window itself, set from one period later.

A series with an empty dataPoints list means the platform has no values for that resource and metric in the window. Common reasons are an instance that was stopped, a volume or network interface that wasn’t attached to a running instance, a metric name that belongs to another resource type, or a window older than the 90 days the platform keeps metrics.

If the query returns an error, look up its extensions.code in Errors.