{"openapi":"3.1.0","info":{"title":"AI Factory Monitoring Service","description":"Prometheus-based metrics collection via SLURM","version":"1.0.0"},"paths":{"/":{"get":{"summary":"Root","description":"Root endpoint with service information.","operationId":"root__get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/health":{"get":{"summary":"Health","description":"Health check endpoint.","operationId":"health_health_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/api/v1/sessions":{"get":{"summary":"List all monitoring sessions","description":"List all monitoring sessions (active and historical).\n\nSessions are sorted by creation time (newest first).\n\n**Returns:**\n- List of all session objects with their metadata","operationId":"list_sessions_api_v1_sessions_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}},"post":{"summary":"Create and start a new monitoring session","description":"Create and start a new monitoring session.\n\n**SINGLE-SESSION MODE**: Only one session can be active (RUNNING) at a time.\nIf there's already an active session, you must stop it before creating a new one.\n\nA monitoring session tracks metrics collection for a specific benchmark run.\nThe session is created and immediately activated (Prometheus config is updated\nand reloaded).\n\n**Request Body:**\n- `run_id` (optional): Custom session identifier (auto-generated if not provided)\n- `scrape_interval` (optional): How often Prometheus scrapes metrics (default: \"15s\")\n- `labels` (optional): Additional labels to attach to this session's metrics\n\n**Returns:**\n- Session ID, Prometheus URL, status (RUNNING), workdir, and targets_count\n\n**Example:**\n```json\n{\n \"run_id\": \"benchmark-001\",\n \"scrape_interval\": \"15s\",\n \"labels\": {\n \"environment\": \"production\",\n \"cluster\": \"meluxina\"\n }\n}\n```\n\n**Note:** The session is immediately active. You can now register targets\nand they will be scraped automatically.\n\n**Error 409:** Another session is already RUNNING - stop it first","operationId":"create_session_api_v1_sessions_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionCreateRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionCreateResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/sessions/{session_id}/status":{"get":{"summary":"Get monitoring session status","description":"Get the current status of a monitoring session.\n\n**Path Parameters:**\n- `session_id`: The monitoring session identifier\n\n**Returns:**\n- Session status, Prometheus health, targets count, and timestamps","operationId":"get_session_status_api_v1_sessions__session_id__status_get","parameters":[{"name":"session_id","in":"path","required":true,"schema":{"type":"string","title":"Session Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionStatusResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/sessions/{session_id}/stop":{"post":{"summary":"Stop a monitoring session","description":"Stop a monitoring session.\n\nMarks the session as stopped. In local deployment, Prometheus continues\nrunning for other sessions.\n\n**Path Parameters:**\n- `session_id`: The monitoring session identifier\n\n**Returns:**\n- Success status and message","operationId":"stop_session_api_v1_sessions__session_id__stop_post","parameters":[{"name":"session_id","in":"path","required":true,"schema":{"type":"string","title":"Session Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionStopResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/sessions/{session_id}":{"delete":{"summary":"Delete a monitoring session","description":"Delete a monitoring session (state only, collected data is preserved).\n\n**Path Parameters:**\n- `session_id`: The monitoring session identifier\n\n**Returns:**\n- Success status and message","operationId":"delete_session_api_v1_sessions__session_id__delete","parameters":[{"name":"session_id","in":"path","required":true,"schema":{"type":"string","title":"Session Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionDeleteResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/clients":{"post":{"summary":"Register a client for monitoring","description":"Register a client with its exporters for monitoring.\n\nClients are benchmarking processes that expose metrics via exporters (e.g., \nnode_exporter, dcgm_exporter). Registering a client adds its exporters to\nthe Prometheus scrape configuration.\n\n**Request Body:**\n- `session_id`: Monitoring session to register with\n- `client_id`: Unique identifier for this client\n- `node`: Node name where the client runs\n- `exporters`: Dictionary mapping exporter types to endpoints\n- `preferences`: Dictionary indicating which exporters to enable\n\n**Example:**\n```json\n{\n \"session_id\": \"mon-abc123\",\n \"client_id\": \"client-001\",\n \"node\": \"node-001\",\n \"exporters\": {\n \"node\": \"node-001:9100\",\n \"dcgm\": \"node-001:9400\"\n },\n \"preferences\": {\n \"enable_node\": true,\n \"enable_dcgm\": true\n }\n}\n```","operationId":"register_client_api_v1_clients_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClientRegistrationRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClientRegistrationResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/services":{"post":{"summary":"Register a service for monitoring","description":"Register a service endpoint for monitoring.\n\nServices are AI workloads (e.g., vLLM, Qdrant) that expose their own\nmetrics endpoints. Registering a service adds it to the Prometheus scrape \nconfiguration.\n\n**Request Body:**\n- `session_id`: Monitoring session to register with\n- `client_id`: Associated client identifier\n- `name`: Service name (e.g., \"vllm\", \"qdrant\")\n- `endpoint`: HTTP endpoint for metrics (e.g., \"http://node-001:8000/metrics\")\n- `labels` (optional): Additional labels to attach to metrics\n\n**Example:**\n```json\n{\n \"session_id\": \"mon-abc123\",\n \"client_id\": \"client-001\",\n \"name\": \"vllm\",\n \"endpoint\": \"http://node-001:8000/metrics\",\n \"labels\": {\n \"model\": \"gpt2\",\n \"gpu\": \"a100\"\n }\n}\n```","operationId":"register_service_api_v1_services_post","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ServiceRegistrationRequest"}}},"required":true},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ServiceRegistrationResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/sessions/{session_id}/collect":{"post":{"summary":"Collect metrics for a time window","description":"Collect metrics for a specific time window and save to disk.\n\nThis queries Prometheus for all metrics within the specified time window,\naggregates them, and saves the results to the specified output directory.\n\n**Path Parameters:**\n- `session_id`: The monitoring session identifier\n\n**Request Body:**\n- `window_start`: Start time as ISO 8601 string (e.g., \"2025-11-04T10:00:00Z\")\n- `window_end`: End time as ISO 8601 string\n- `out_dir`: Directory path where collected metrics will be saved\n- `run_id`: Identifier for this collection run (default: \"run\")\n\n**Returns:**\n- Dictionary of artifact file paths created during collection\n\n**Example:**\n```json\n{\n \"window_start\": \"2025-11-04T10:00:00Z\",\n \"window_end\": \"2025-11-04T11:00:00Z\",\n \"out_dir\": \"/data/metrics\",\n \"run_id\": \"benchmark_001\"\n}\n```","operationId":"collect_metrics_api_v1_sessions__session_id__collect_post","parameters":[{"name":"session_id","in":"path","required":true,"schema":{"type":"string","title":"Session Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CollectionRequest"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CollectionResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"ClientRegistrationRequest":{"properties":{"session_id":{"type":"string","title":"Session Id","description":"Monitoring session ID"},"client_id":{"type":"string","title":"Client Id","description":"Unique client identifier"},"node":{"type":"string","title":"Node","description":"Node name where client runs"},"exporters":{"additionalProperties":{"type":"string"},"type":"object","title":"Exporters","description":"Dict of exporter types to endpoints"},"preferences":{"additionalProperties":{"type":"boolean"},"type":"object","title":"Preferences","description":"Dict of enabled exporters"}},"type":"object","required":["session_id","client_id","node","exporters","preferences"],"title":"ClientRegistrationRequest","description":"Request to register a client for monitoring."},"ClientRegistrationResponse":{"properties":{"ok":{"type":"boolean","title":"Ok"},"client_id":{"type":"string","title":"Client Id"}},"type":"object","required":["ok","client_id"],"title":"ClientRegistrationResponse","description":"Response for client registration."},"CollectionRequest":{"properties":{"window_start":{"type":"string","title":"Window Start","description":"Start time as ISO string"},"window_end":{"type":"string","title":"Window End","description":"End time as ISO string"},"out_dir":{"type":"string","title":"Out Dir","description":"Output directory for collected metrics"},"run_id":{"type":"string","title":"Run Id","description":"Run identifier for the collection","default":"run"}},"type":"object","required":["window_start","window_end","out_dir"],"title":"CollectionRequest","description":"Request to collect metrics."},"CollectionResponse":{"properties":{"artifacts":{"additionalProperties":{"type":"string"},"type":"object","title":"Artifacts"}},"type":"object","required":["artifacts"],"title":"CollectionResponse","description":"Response for metrics collection."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ServiceRegistrationRequest":{"properties":{"session_id":{"type":"string","title":"Session Id","description":"Monitoring session ID"},"service_id":{"type":"string","title":"Service Id","description":"Server API service ID (also used as Prometheus job label)"},"labels":{"anyOf":[{"additionalProperties":{"type":"string"},"type":"object"},{"type":"null"}],"title":"Labels","description":"Prometheus labels for filtering/grouping (e.g., {'environment': 'prod', 'team': 'ml'})"}},"type":"object","required":["session_id","service_id"],"title":"ServiceRegistrationRequest","description":"Request to register a service for monitoring.\n\nProvide the service_id from the Server API, and the Monitoring service will\nautomatically resolve the metrics endpoint using /api/v1/services/{service_id}/metrics.\nThe service_id is used as the Prometheus job label name."},"ServiceRegistrationResponse":{"properties":{"ok":{"type":"boolean","title":"Ok"},"service_id":{"type":"string","title":"Service Id"},"endpoint":{"type":"string","title":"Endpoint"}},"type":"object","required":["ok","service_id","endpoint"],"title":"ServiceRegistrationResponse","description":"Response for service registration."},"SessionCreateRequest":{"properties":{"run_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Run Id","description":"Optional session identifier (auto-generated if not provided)"},"scrape_interval":{"type":"string","title":"Scrape Interval","description":"Prometheus scrape interval (e.g., '15s', '1m')","default":"15s"},"labels":{"anyOf":[{"additionalProperties":{"type":"string"},"type":"object"},{"type":"null"}],"title":"Labels","description":"Additional labels for this session"}},"type":"object","title":"SessionCreateRequest","description":"Request to create a new monitoring session."},"SessionCreateResponse":{"properties":{"session_id":{"type":"string","title":"Session Id"},"prometheus_url":{"type":"string","title":"Prometheus Url"},"status":{"type":"string","title":"Status"},"workdir":{"type":"string","title":"Workdir"},"targets_count":{"type":"integer","title":"Targets Count"}},"type":"object","required":["session_id","prometheus_url","status","workdir","targets_count"],"title":"SessionCreateResponse","description":"Response for session creation."},"SessionDeleteResponse":{"properties":{"success":{"type":"boolean","title":"Success"},"message":{"type":"string","title":"Message"}},"type":"object","required":["success","message"],"title":"SessionDeleteResponse","description":"Response for session deletion."},"SessionStatusResponse":{"properties":{"session_id":{"type":"string","title":"Session Id"},"status":{"type":"string","title":"Status"},"prometheus":{"type":"object","title":"Prometheus"},"targets_count":{"type":"integer","title":"Targets Count"},"created_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Created At"},"started_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Started At"}},"type":"object","required":["session_id","status","prometheus","targets_count"],"title":"SessionStatusResponse","description":"Response for session status."},"SessionStopResponse":{"properties":{"success":{"type":"boolean","title":"Success"},"message":{"type":"string","title":"Message"}},"type":"object","required":["success","message"],"title":"SessionStopResponse","description":"Response for session stop."},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}}}