Skip to content
Open
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
21 changes: 14 additions & 7 deletions core/http/endpoints/localai/backend_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@ import (
// BackendMonitorEndpoint returns the status of the specified backend
// @Summary Backend monitor endpoint
// @Tags monitoring
// @Param request body schema.BackendMonitorRequest true "Backend statistics request"
// @Param model query string true "Name of the model to monitor"
// @Success 200 {object} proto.StatusResponse "Response"
// @Router /backend/monitor [get]
func BackendMonitorEndpoint(bm *monitoring.BackendMonitorService) echo.HandlerFunc {
return func(c echo.Context) error {

input := new(schema.BackendMonitorRequest)
// Get input data from the request body
if err := c.Bind(input); err != nil {
return err
model := c.QueryParam("model")
// Fall back to binding the request body so pre-existing clients that
// sent `{"model": "..."}` with GET keep working.
if model == "" {
input := new(schema.BackendMonitorRequest)
if err := c.Bind(input); err != nil {
return err
}
model = input.Model
}
if model == "" {
return echo.NewHTTPError(400, "model query parameter is required")
}

resp, err := bm.CheckAndSample(input.Model)
resp, err := bm.CheckAndSample(model)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions docs/content/features/backend-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ LocalAI provides endpoints to monitor and manage running backends. The `/backend

### Request

The request body is JSON:
The model to monitor is passed as a query parameter:

| Parameter | Type | Required | Description |
|-----------|----------|----------|--------------------------------|
| `model` | `string` | Yes | Name of the model to monitor |
| Parameter | Type | Required | Location | Description |
|-----------|----------|----------|----------|--------------------------------|
| `model` | `string` | Yes | query | Name of the model to monitor |

For backwards compatibility, a JSON body with the same field is still accepted when the `model` query parameter is not set, but new clients should use the query parameter.

### Response

Expand All @@ -42,9 +44,7 @@ If the gRPC status call fails, the endpoint falls back to local process metrics:
### Usage

```bash
curl http://localhost:8080/backend/monitor \
-H "Content-Type: application/json" \
-d '{"model": "my-model"}'
curl "http://localhost:8080/backend/monitor?model=my-model"
```

### Example response
Expand Down
12 changes: 5 additions & 7 deletions swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,13 +985,11 @@ const docTemplate = `{
"summary": "Backend monitor endpoint",
"parameters": [
{
"description": "Backend statistics request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/schema.BackendMonitorRequest"
}
"type": "string",
"description": "Name of the model to monitor",
"name": "model",
"in": "query",
"required": true
}
],
"responses": {
Expand Down
12 changes: 5 additions & 7 deletions swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -982,13 +982,11 @@
"summary": "Backend monitor endpoint",
"parameters": [
{
"description": "Backend statistics request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/schema.BackendMonitorRequest"
}
"type": "string",
"description": "Name of the model to monitor",
"name": "model",
"in": "query",
"required": true
}
],
"responses": {
Expand Down
9 changes: 4 additions & 5 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2363,12 +2363,11 @@ paths:
/backend/monitor:
get:
parameters:
- description: Backend statistics request
in: body
name: request
- description: Name of the model to monitor
in: query
name: model
required: true
schema:
$ref: '#/definitions/schema.BackendMonitorRequest'
type: string
responses:
"200":
description: Response
Expand Down