> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kodostatus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ingest Metrics

> Push application metrics for automatic health detection and status updates

Kodo can automatically determine service health based on metrics you push. When error rates or response times exceed thresholds, Kodo updates your service status and optionally creates incidents.

## Request Body

<ParamField body="service_id" type="string" required>
  The service to associate metrics with
</ParamField>

<ParamField body="metrics" type="object" required>
  Metric values to report

  <Expandable title="Available Metrics">
    <ParamField body="error_rate" type="number">
      Error percentage (0-100). Thresholds: >50% = major\_outage, >10% = partial\_outage, >1% = degraded
    </ParamField>

    <ParamField body="response_time_ms" type="number">
      Average response time in milliseconds
    </ParamField>

    <ParamField body="cpu_percent" type="number">
      CPU utilization percentage (0-100)
    </ParamField>

    <ParamField body="memory_percent" type="number">
      Memory utilization percentage (0-100)
    </ParamField>

    <ParamField body="disk_percent" type="number">
      Disk utilization percentage (0-100)
    </ParamField>

    <ParamField body="request_count" type="number">
      Number of requests in the reporting period
    </ParamField>

    <ParamField body="error_count" type="number">
      Number of errors in the reporting period
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="timestamp" type="string">
  ISO 8601 timestamp for the metrics. Defaults to current time.
</ParamField>

## Response

Returns confirmation and any status changes triggered.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://kodostatus.com/api/metrics/ingest" \
    -H "X-API-Key: your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "service_id": "svc_abc123",
      "metrics": {
        "error_rate": 2.5,
        "response_time_ms": 245,
        "request_count": 10000,
        "error_count": 250
      }
    }'
  ```

  ```javascript Node.js theme={null}
  // Express middleware example
  app.use((req, res, next) => {
    const start = Date.now();

    res.on('finish', async () => {
      const duration = Date.now() - start;
      const isError = res.statusCode >= 500;

      // Aggregate and send periodically
      metricsBuffer.push({ duration, isError });

      if (metricsBuffer.length >= 100) {
        await fetch('https://kodostatus.com/api/metrics/ingest', {
          method: 'POST',
          headers: {
            'X-API-Key': process.env.KODO_API_KEY,
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({
            service_id: 'svc_abc123',
            metrics: {
              error_rate: calculateErrorRate(metricsBuffer),
              response_time_ms: calculateAvgResponseTime(metricsBuffer),
              request_count: metricsBuffer.length
            }
          })
        });
        metricsBuffer = [];
      }
    });

    next();
  });
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "success": true,
    "metrics_received": {
      "error_rate": 2.5,
      "response_time_ms": 245,
      "request_count": 10000
    },
    "status_change": {
      "previous": "operational",
      "current": "degraded",
      "reason": "Error rate exceeded 1% threshold"
    },
    "incident_created": null
  }
  ```
</ResponseExample>

## Default Thresholds

| Metric             | Degraded | Partial Outage | Major Outage |
| ------------------ | -------- | -------------- | ------------ |
| Error Rate         | > 1%     | > 10%          | > 50%        |
| Response Time (ms) | > 1000ms | > 3000ms       | > 10000ms    |
| CPU Percent        | > 70%    | > 85%          | > 95%        |
| Memory Percent     | > 70%    | > 85%          | > 95%        |

<Tip>
  Configure custom thresholds in your Dashboard under Service Settings → Auto-Status Thresholds.
</Tip>
