Monitor: show Ollama's loaded models, their VRAM footprint, and busy state

The status snapshot now queries /api/ps (2s timeout so a wedged Ollama
cannot stall the channel) and the ollama line renders e.g.
'UP · llama3.1:8b (4.8 GiB VRAM) · busy'; comfy gets the busy marker
too while an image job runs.
This commit is contained in:
mram
2026-09-22 12:44:04 +02:00
parent e98331bb9e
commit d2c49e52fa
4 changed files with 112 additions and 25 deletions
+30 -9
View File
@@ -60,13 +60,21 @@ func (c *Client) Probe(ctx context.Context) error {
type psResponse struct {
Models []struct {
Name string `json:"name"`
Model string `json:"model"`
Name string `json:"name"`
Model string `json:"model"`
SizeVRAM int64 `json:"size_vram"` // bytes resident in VRAM (0 = RAM-only)
} `json:"models"`
}
// LoadedModels returns the names of models currently held in memory.
func (c *Client) LoadedModels(ctx context.Context) ([]string, error) {
// LoadedModel is one model currently held in memory.
type LoadedModel struct {
Name string
SizeVRAM int64 // bytes resident in VRAM; 0 when the model sits in RAM
}
// LoadedModelDetails returns the models currently held in memory with
// their VRAM footprint.
func (c *Client) LoadedModelDetails(ctx context.Context) ([]LoadedModel, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.base+"/api/ps", nil)
if err != nil {
return nil, err
@@ -84,13 +92,26 @@ func (c *Client) LoadedModels(ctx context.Context) ([]string, error) {
if err := json.NewDecoder(resp.Body).Decode(&ps); err != nil {
return nil, err
}
models := make([]string, 0, len(ps.Models))
models := make([]LoadedModel, 0, len(ps.Models))
for _, m := range ps.Models {
if m.Name != "" {
models = append(models, m.Name)
} else {
models = append(models, m.Model)
name := m.Name
if name == "" {
name = m.Model
}
models = append(models, LoadedModel{Name: name, SizeVRAM: m.SizeVRAM})
}
return models, nil
}
// LoadedModels returns the names of models currently held in memory.
func (c *Client) LoadedModels(ctx context.Context) ([]string, error) {
details, err := c.LoadedModelDetails(ctx)
if err != nil {
return nil, err
}
models := make([]string, 0, len(details))
for _, m := range details {
models = append(models, m.Name)
}
return models, nil
}