Skip to content

Commit

Permalink
feat: Add prometheus and grafana support (#523)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->


> [!IMPORTANT]
> Add Prometheus and Grafana support with FastAPI metrics and Docker
Compose configurations.
> 
>   - **Metrics Integration**:
> - Add `prometheus-fastapi-instrumentator` to `web.py` for FastAPI
metrics.
> - Update `pyproject.toml` to include
`prometheus-fastapi-instrumentator` dependency.
>   - **Docker Compose**:
> - Add `prometheus/docker-compose.yml` for Prometheus configuration.
>     - Add `grafana/docker-compose.yml` for Grafana configuration.
> - Update root `docker-compose.yml` to include Prometheus and Grafana
services.
>   - **Traefik Configuration**:
> - Update `traefik.yml.template` to route `/grafana` to Grafana
service.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral)<sup>
for 124ecc7. It will automatically
update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: Diwank Singh Tomer <[email protected]>
  • Loading branch information
whiterabbit1983 and creatorrr authored Oct 11, 2024
1 parent 1f340e7 commit 5ba7f44
Show file tree
Hide file tree
Showing 8 changed files with 880 additions and 637 deletions.
4 changes: 4 additions & 0 deletions agents-api/agents_api/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from litellm.exceptions import APIError
from prometheus_fastapi_instrumentator import Instrumentator
from pycozo.client import QueryException
from scalar_fastapi import get_scalar_api_reference
from temporalio.service import RPCError
Expand Down Expand Up @@ -100,6 +101,9 @@ def register_exceptions(app: FastAPI) -> None:
root_path=api_prefix,
)

# Enable metrics
Instrumentator().instrument(app).expose(app)

# Create a new router for the docs
scalar_router = APIRouter()

Expand Down
1,434 changes: 797 additions & 637 deletions agents-api/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions agents-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ scalar-fastapi = "^1.0.3"
sse-starlette = "^2.1.3"
anyio = "^4.4.0"
python-box = {extras = ["toml"], version = "^7.2.0"}
prometheus-fastapi-instrumentator = "^7.0.0"
[tool.poetry.group.dev.dependencies]
ipython = "^8.26.0"
ruff = "^0.5.5"
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ include:
- ./scheduler/docker-compose.yml
- ./llm-proxy/docker-compose.yml
- ./integrations-service/docker-compose.yml
- ./prometheus/docker-compose.yml
- ./grafana/docker-compose.yml

# TODO: Enable after testing
# - ./monitoring/docker-compose.yml
Expand Down
20 changes: 20 additions & 0 deletions grafana/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: grafana

services:
grafana:
image: grafana/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD}
- GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER}
container_name: grafana
ports:
- 3000:3000
volumes:
- grafana_data:/var/lib/grafana
- ./provisioning:/etc/grafana/provisioning
profiles:
- multi-tenant

volumes:
grafana_data:
external: true
9 changes: 9 additions & 0 deletions grafana/provisioning/datasources/datasource.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
datasources:
- access: 'proxy'
editable: true
is_default: true
name: 'agents-api'
org_id: 1
type: 'prometheus'
url: 'http://prometheus:9090'
version: 1
24 changes: 24 additions & 0 deletions prometheus/config/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
alerting:
alertmanagers:
- follow_redirects: true
enable_http2: true
scheme: http
timeout: 10s
api_version: v2
static_configs:
- targets: []
scrape_configs:
- job_name: agents-api
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
follow_redirects: true
static_configs:
- targets:
- agents-api-multi-tenant:8080
23 changes: 23 additions & 0 deletions prometheus/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: prometheus

services:
prometheus:
image: prom/prometheus
container_name: prometheus
profiles:
- multi-tenant

volumes:
- ./config/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus

depends_on:
agents-api-multi-tenant:
condition: service_started

command:
- '--config.file=/etc/prometheus/prometheus.yml'

volumes:
prometheus_data:
external: true

0 comments on commit 5ba7f44

Please sign in to comment.