Skip to content

Commit

Permalink
Add GPU resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ioppermann committed Oct 30, 2024
1 parent ed5357c commit 22a94e1
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 9 deletions.
47 changes: 47 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down Expand Up @@ -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"
}
Expand Down
47 changes: 47 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down Expand Up @@ -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"
}
Expand Down
36 changes: 36 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 20 additions & 9 deletions http/api/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions http/handler/api/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 22a94e1

Please sign in to comment.