Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add prometheus and grafana support #523

Merged
merged 8 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading