From 22a94e1089b7812396cf434b1510006eb15d062f Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Wed, 30 Oct 2024 15:16:10 +0100 Subject: [PATCH] Add GPU resources --- docs/docs.go | 47 +++++++++++++++++++++++++++++++++++++++ docs/swagger.json | 47 +++++++++++++++++++++++++++++++++++++++ docs/swagger.yaml | 36 ++++++++++++++++++++++++++++++ http/api/about.go | 29 ++++++++++++++++-------- http/handler/api/about.go | 14 ++++++++++++ 5 files changed, 164 insertions(+), 9 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 11b9c66e..2c69ea84 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -5208,6 +5208,39 @@ const docTemplate = `{ } } }, + "api.AboutGPUResources": { + "type": "object", + "properties": { + "memory_limit_bytes": { + "description": "Defined memory limit in bytes", + "type": "integer" + }, + "memory_total_bytes": { + "description": "Total available memory in bytes", + "type": "integer" + }, + "memory_used_bytes": { + "description": "Currently used memory in bytes", + "type": "integer" + }, + "usage_decoder": { + "description": "Current decoder usage, 0-100", + "type": "number" + }, + "usage_encoder": { + "description": "Current encoder usage, 0-100", + "type": "number" + }, + "usage_general": { + "description": "Current general usage, 0-100", + "type": "number" + }, + "usage_limit": { + "description": "Defined general usage limit, 0-100", + "type": "number" + } + } + }, "api.AboutResources": { "type": "object", "properties": { @@ -5223,6 +5256,13 @@ const docTemplate = `{ "description": "Current CPU load, 0-100*ncpu", "type": "number" }, + "gpu": { + "description": "GPU resources", + "type": "array", + "items": { + "$ref": "#/definitions/api.AboutGPUResources" + } + }, "is_throttling": { "description": "Whether this core is currently throttling", "type": "boolean" @@ -7082,26 +7122,33 @@ const docTemplate = `{ "type": "object", "properties": { "cpu_usage": { + "description": "percent 0-100*ncpu", "type": "number" }, "gpu_decoder": { + "description": "percent 0-100", "type": "number" }, "gpu_encoder": { + "description": "percent 0-100", "type": "number" }, "gpu_memory_mbytes": { + "description": "megabytes", "type": "integer", "format": "uint64" }, "gpu_usage": { + "description": "percent 0-100", "type": "number" }, "memory_mbytes": { + "description": "megabytes", "type": "integer", "format": "uint64" }, "waitfor_seconds": { + "description": "seconds", "type": "integer", "format": "uint64" } diff --git a/docs/swagger.json b/docs/swagger.json index ce21a8ea..400e5078 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -5201,6 +5201,39 @@ } } }, + "api.AboutGPUResources": { + "type": "object", + "properties": { + "memory_limit_bytes": { + "description": "Defined memory limit in bytes", + "type": "integer" + }, + "memory_total_bytes": { + "description": "Total available memory in bytes", + "type": "integer" + }, + "memory_used_bytes": { + "description": "Currently used memory in bytes", + "type": "integer" + }, + "usage_decoder": { + "description": "Current decoder usage, 0-100", + "type": "number" + }, + "usage_encoder": { + "description": "Current encoder usage, 0-100", + "type": "number" + }, + "usage_general": { + "description": "Current general usage, 0-100", + "type": "number" + }, + "usage_limit": { + "description": "Defined general usage limit, 0-100", + "type": "number" + } + } + }, "api.AboutResources": { "type": "object", "properties": { @@ -5216,6 +5249,13 @@ "description": "Current CPU load, 0-100*ncpu", "type": "number" }, + "gpu": { + "description": "GPU resources", + "type": "array", + "items": { + "$ref": "#/definitions/api.AboutGPUResources" + } + }, "is_throttling": { "description": "Whether this core is currently throttling", "type": "boolean" @@ -7075,26 +7115,33 @@ "type": "object", "properties": { "cpu_usage": { + "description": "percent 0-100*ncpu", "type": "number" }, "gpu_decoder": { + "description": "percent 0-100", "type": "number" }, "gpu_encoder": { + "description": "percent 0-100", "type": "number" }, "gpu_memory_mbytes": { + "description": "megabytes", "type": "integer", "format": "uint64" }, "gpu_usage": { + "description": "percent 0-100", "type": "number" }, "memory_mbytes": { + "description": "megabytes", "type": "integer", "format": "uint64" }, "waitfor_seconds": { + "description": "seconds", "type": "integer", "format": "uint64" } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9ad7331a..5e12a2a2 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -95,6 +95,30 @@ definitions: version: $ref: '#/definitions/api.AboutVersion' type: object + api.AboutGPUResources: + properties: + memory_limit_bytes: + description: Defined memory limit in bytes + type: integer + memory_total_bytes: + description: Total available memory in bytes + type: integer + memory_used_bytes: + description: Currently used memory in bytes + type: integer + usage_decoder: + description: Current decoder usage, 0-100 + type: number + usage_encoder: + description: Current encoder usage, 0-100 + type: number + usage_general: + description: Current general usage, 0-100 + type: number + usage_limit: + description: Defined general usage limit, 0-100 + type: number + type: object api.AboutResources: properties: cpu_core: @@ -106,6 +130,11 @@ definitions: cpu_used: description: Current CPU load, 0-100*ncpu type: number + gpu: + description: GPU resources + items: + $ref: '#/definitions/api.AboutGPUResources' + type: array is_throttling: description: Whether this core is currently throttling type: boolean @@ -1357,20 +1386,27 @@ definitions: api.ProcessConfigLimits: properties: cpu_usage: + description: percent 0-100*ncpu type: number gpu_decoder: + description: percent 0-100 type: number gpu_encoder: + description: percent 0-100 type: number gpu_memory_mbytes: + description: megabytes format: uint64 type: integer gpu_usage: + description: percent 0-100 type: number memory_mbytes: + description: megabytes format: uint64 type: integer waitfor_seconds: + description: seconds format: uint64 type: integer type: object diff --git a/http/api/about.go b/http/api/about.go index 332420a9..f660d6e5 100644 --- a/http/api/about.go +++ b/http/api/about.go @@ -24,15 +24,26 @@ type AboutVersion struct { // AboutResources holds information about the current resource usage type AboutResources struct { - IsThrottling bool `json:"is_throttling"` // Whether this core is currently throttling - NCPU float64 `json:"ncpu"` // Number of CPU on this node - CPU float64 `json:"cpu_used"` // Current CPU load, 0-100*ncpu - CPULimit float64 `json:"cpu_limit"` // Defined CPU load limit, 0-100*ncpu - CPUCore float64 `json:"cpu_core"` // Current CPU load of the core itself, 0-100*ncpu - Mem uint64 `json:"memory_used_bytes"` // Currently used memory in bytes - MemLimit uint64 `json:"memory_limit_bytes"` // Defined memory limit in bytes - MemTotal uint64 `json:"memory_total_bytes"` // Total available memory in bytes - MemCore uint64 `json:"memory_core_bytes"` // Current used memory of the core itself in bytes + IsThrottling bool `json:"is_throttling"` // Whether this core is currently throttling + NCPU float64 `json:"ncpu"` // Number of CPU on this node + CPU float64 `json:"cpu_used"` // Current CPU load, 0-100*ncpu + CPULimit float64 `json:"cpu_limit"` // Defined CPU load limit, 0-100*ncpu + CPUCore float64 `json:"cpu_core"` // Current CPU load of the core itself, 0-100*ncpu + Mem uint64 `json:"memory_used_bytes"` // Currently used memory in bytes + MemLimit uint64 `json:"memory_limit_bytes"` // Defined memory limit in bytes + MemTotal uint64 `json:"memory_total_bytes"` // Total available memory in bytes + MemCore uint64 `json:"memory_core_bytes"` // Current used memory of the core itself in bytes + GPU []AboutGPUResources `json:"gpu"` // GPU resources +} + +type AboutGPUResources struct { + Mem uint64 `json:"memory_used_bytes"` // Currently used memory in bytes + MemLimit uint64 `json:"memory_limit_bytes"` // Defined memory limit in bytes + MemTotal uint64 `json:"memory_total_bytes"` // Total available memory in bytes + Usage float64 `json:"usage_general"` // Current general usage, 0-100 + UsageLimit float64 `json:"usage_limit"` // Defined general usage limit, 0-100 + Encoder float64 `json:"usage_encoder"` // Current encoder usage, 0-100 + Decoder float64 `json:"usage_decoder"` // Current decoder usage, 0-100 } // MinimalAbout is the minimal information about the API diff --git a/http/handler/api/about.go b/http/handler/api/about.go index cba674dd..01b8d578 100644 --- a/http/handler/api/about.go +++ b/http/handler/api/about.go @@ -71,6 +71,7 @@ func (p *AboutHandler) About(c echo.Context) error { if p.resources != nil { res := p.resources.Info() + about.Resources.IsThrottling = res.CPU.Throttling about.Resources.NCPU = res.CPU.NCPU about.Resources.CPU = (100 - res.CPU.Idle) * res.CPU.NCPU @@ -80,6 +81,19 @@ func (p *AboutHandler) About(c echo.Context) error { about.Resources.MemLimit = res.Mem.Limit about.Resources.MemTotal = res.Mem.Total about.Resources.MemCore = res.Mem.Core + + about.Resources.GPU = make([]api.AboutGPUResources, len(res.GPU.GPU)) + for i, gpu := range res.GPU.GPU { + about.Resources.GPU[i] = api.AboutGPUResources{ + Mem: gpu.MemoryUsed, + MemLimit: gpu.MemoryLimit, + MemTotal: gpu.MemoryTotal, + Usage: gpu.Usage, + UsageLimit: gpu.UsageLimit, + Encoder: gpu.Encoder, + Decoder: gpu.Decoder, + } + } } return c.JSON(http.StatusOK, about)