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

# Stats API

> Get statistics about async jobs

Get aggregate statistics about all async jobs.

## Response

<ResponseField name="total_jobs" type="integer" required>
  Total number of jobs ever submitted.
</ResponseField>

<ResponseField name="by_status" type="object" required>
  Breakdown of jobs by status.
</ResponseField>

<ResponseField name="by_status.queued" type="integer">
  Number of jobs currently queued.
</ResponseField>

<ResponseField name="by_status.running" type="integer">
  Number of jobs currently running.
</ResponseField>

<ResponseField name="by_status.succeeded" type="integer">
  Number of jobs that completed successfully.
</ResponseField>

<ResponseField name="by_status.failed" type="integer">
  Number of jobs that failed.
</ResponseField>

<ResponseField name="by_status.cancelled" type="integer">
  Number of jobs that were cancelled.
</ResponseField>

<RequestExample>
  ```bash cURL theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  curl http://127.0.0.1:8005/stats
  ```

  ```python Python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  import httpx

  response = httpx.get("http://127.0.0.1:8005/stats")
  stats = response.json()

  print(f"Total jobs: {stats['total_jobs']}")
  print(f"Running: {stats['by_status'].get('running', 0)}")
  print(f"Succeeded: {stats['by_status'].get('succeeded', 0)}")
  print(f"Failed: {stats['by_status'].get('failed', 0)}")
  ```

  ```bash CLI theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  curl http://127.0.0.1:8005/stats
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "total_jobs": 150,
    "by_status": {
      "queued": 5,
      "running": 3,
      "succeeded": 130,
      "failed": 10,
      "cancelled": 2
    }
  }
  ```
</ResponseExample>

## Usage

Use this endpoint for:

* Monitoring dashboards
* Capacity planning
* Alerting on failure rates

## Example: Monitor Failure Rate

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import httpx
import time

API_URL = "http://127.0.0.1:8005"
FAILURE_THRESHOLD = 0.1  # 10% failure rate

def check_failure_rate():
    stats = httpx.get(f"{API_URL}/stats").json()
    
    total = stats["total_jobs"]
    failed = stats["by_status"].get("failed", 0)
    
    if total > 0:
        failure_rate = failed / total
        if failure_rate > FAILURE_THRESHOLD:
            print(f"WARNING: High failure rate: {failure_rate:.1%}")
            return False
    
    print(f"OK: {total} jobs, {failed} failed ({failed/max(total,1):.1%})")
    return True

# Periodic monitoring
while True:
    check_failure_rate()
    time.sleep(60)
```

## See Also

* [Health Check](/docs/api/praisonai/async-jobs/health)
* [List Runs](/docs/api/praisonai/async-jobs/list-runs)
* [Async Jobs Overview](/docs/api/praisonai/async-jobs)
