mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Expose resource usage in process state
This commit is contained in:
63
docs/docs.go
63
docs/docs.go
@@ -3384,6 +3384,10 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3564,6 +3568,9 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"progress": {
|
"progress": {
|
||||||
"$ref": "#/definitions/api.Progress"
|
"$ref": "#/definitions/api.Progress"
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3604,6 +3611,9 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"progress": {
|
"progress": {
|
||||||
"$ref": "#/definitions/api.Progress"
|
"$ref": "#/definitions/api.Progress"
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3639,6 +3649,7 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cpu_usage": {
|
"cpu_usage": {
|
||||||
|
"description": "deprecated, use Resources.Memory.Current",
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"exec": {
|
"exec": {
|
||||||
@@ -3648,6 +3659,7 @@ const docTemplate = `{
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"memory_bytes": {
|
"memory_bytes": {
|
||||||
|
"description": "deprecated, use Resources.CPU.Current",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "uint64"
|
"format": "uint64"
|
||||||
},
|
},
|
||||||
@@ -3661,12 +3673,63 @@ const docTemplate = `{
|
|||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
},
|
},
|
||||||
|
"resources": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsage"
|
||||||
|
},
|
||||||
"runtime_seconds": {
|
"runtime_seconds": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"api.ProcessUsage": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cpu_usage": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsageCPU"
|
||||||
|
},
|
||||||
|
"memory_bytes": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsageMemory"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"api.ProcessUsageCPU": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"avg": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"cur": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"limit": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"api.ProcessUsageMemory": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"avg": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"cur": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint64"
|
||||||
|
},
|
||||||
|
"limit": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint64"
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"api.Progress": {
|
"api.Progress": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@@ -3377,6 +3377,10 @@
|
|||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"updated_at": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3557,6 +3561,9 @@
|
|||||||
},
|
},
|
||||||
"progress": {
|
"progress": {
|
||||||
"$ref": "#/definitions/api.Progress"
|
"$ref": "#/definitions/api.Progress"
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3597,6 +3604,9 @@
|
|||||||
},
|
},
|
||||||
"progress": {
|
"progress": {
|
||||||
"$ref": "#/definitions/api.Progress"
|
"$ref": "#/definitions/api.Progress"
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -3632,6 +3642,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cpu_usage": {
|
"cpu_usage": {
|
||||||
|
"description": "deprecated, use Resources.Memory.Current",
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"exec": {
|
"exec": {
|
||||||
@@ -3641,6 +3652,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"memory_bytes": {
|
"memory_bytes": {
|
||||||
|
"description": "deprecated, use Resources.CPU.Current",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "uint64"
|
"format": "uint64"
|
||||||
},
|
},
|
||||||
@@ -3654,12 +3666,63 @@
|
|||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
},
|
},
|
||||||
|
"resources": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsage"
|
||||||
|
},
|
||||||
"runtime_seconds": {
|
"runtime_seconds": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"api.ProcessUsage": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cpu_usage": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsageCPU"
|
||||||
|
},
|
||||||
|
"memory_bytes": {
|
||||||
|
"$ref": "#/definitions/api.ProcessUsageMemory"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"api.ProcessUsageCPU": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"avg": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"cur": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"limit": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"api.ProcessUsageMemory": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"avg": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"cur": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint64"
|
||||||
|
},
|
||||||
|
"limit": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint64"
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"api.Progress": {
|
"api.Progress": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@@ -755,6 +755,9 @@ definitions:
|
|||||||
$ref: '#/definitions/api.ProcessState'
|
$ref: '#/definitions/api.ProcessState'
|
||||||
type:
|
type:
|
||||||
type: string
|
type: string
|
||||||
|
updated_at:
|
||||||
|
format: int64
|
||||||
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
api.ProcessConfig:
|
api.ProcessConfig:
|
||||||
properties:
|
properties:
|
||||||
@@ -877,6 +880,8 @@ definitions:
|
|||||||
type: array
|
type: array
|
||||||
progress:
|
progress:
|
||||||
$ref: '#/definitions/api.Progress'
|
$ref: '#/definitions/api.Progress'
|
||||||
|
resources:
|
||||||
|
$ref: '#/definitions/api.ProcessUsage'
|
||||||
type: object
|
type: object
|
||||||
api.ProcessReportEntry:
|
api.ProcessReportEntry:
|
||||||
properties:
|
properties:
|
||||||
@@ -904,6 +909,8 @@ definitions:
|
|||||||
type: array
|
type: array
|
||||||
progress:
|
progress:
|
||||||
$ref: '#/definitions/api.Progress'
|
$ref: '#/definitions/api.Progress'
|
||||||
|
resources:
|
||||||
|
$ref: '#/definitions/api.ProcessUsage'
|
||||||
type: object
|
type: object
|
||||||
api.ProcessReportSearchResult:
|
api.ProcessReportSearchResult:
|
||||||
properties:
|
properties:
|
||||||
@@ -927,12 +934,14 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
type: array
|
type: array
|
||||||
cpu_usage:
|
cpu_usage:
|
||||||
|
description: deprecated, use Resources.Memory.Current
|
||||||
type: number
|
type: number
|
||||||
exec:
|
exec:
|
||||||
type: string
|
type: string
|
||||||
last_logline:
|
last_logline:
|
||||||
type: string
|
type: string
|
||||||
memory_bytes:
|
memory_bytes:
|
||||||
|
description: deprecated, use Resources.CPU.Current
|
||||||
format: uint64
|
format: uint64
|
||||||
type: integer
|
type: integer
|
||||||
order:
|
order:
|
||||||
@@ -942,10 +951,44 @@ definitions:
|
|||||||
reconnect_seconds:
|
reconnect_seconds:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
|
resources:
|
||||||
|
$ref: '#/definitions/api.ProcessUsage'
|
||||||
runtime_seconds:
|
runtime_seconds:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
api.ProcessUsage:
|
||||||
|
properties:
|
||||||
|
cpu_usage:
|
||||||
|
$ref: '#/definitions/api.ProcessUsageCPU'
|
||||||
|
memory_bytes:
|
||||||
|
$ref: '#/definitions/api.ProcessUsageMemory'
|
||||||
|
type: object
|
||||||
|
api.ProcessUsageCPU:
|
||||||
|
properties:
|
||||||
|
avg:
|
||||||
|
type: number
|
||||||
|
cur:
|
||||||
|
type: number
|
||||||
|
limit:
|
||||||
|
type: number
|
||||||
|
max:
|
||||||
|
type: number
|
||||||
|
type: object
|
||||||
|
api.ProcessUsageMemory:
|
||||||
|
properties:
|
||||||
|
avg:
|
||||||
|
type: number
|
||||||
|
cur:
|
||||||
|
format: uint64
|
||||||
|
type: integer
|
||||||
|
limit:
|
||||||
|
format: uint64
|
||||||
|
type: integer
|
||||||
|
max:
|
||||||
|
format: uint64
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
api.Progress:
|
api.Progress:
|
||||||
properties:
|
properties:
|
||||||
bitrate_kbit:
|
bitrate_kbit:
|
||||||
|
@@ -202,15 +202,16 @@ func (cfg *ProcessConfig) Unmarshal(c *app.Config) {
|
|||||||
|
|
||||||
// ProcessState represents the current state of an ffmpeg process
|
// ProcessState represents the current state of an ffmpeg process
|
||||||
type ProcessState struct {
|
type ProcessState struct {
|
||||||
Order string `json:"order" jsonschema:"enum=start,enum=stop"`
|
Order string `json:"order" jsonschema:"enum=start,enum=stop"`
|
||||||
State string `json:"exec" jsonschema:"enum=finished,enum=starting,enum=running,enum=finishing,enum=killed,enum=failed"`
|
State string `json:"exec" jsonschema:"enum=finished,enum=starting,enum=running,enum=finishing,enum=killed,enum=failed"`
|
||||||
Runtime int64 `json:"runtime_seconds" jsonschema:"minimum=0" format:"int64"`
|
Runtime int64 `json:"runtime_seconds" jsonschema:"minimum=0" format:"int64"`
|
||||||
Reconnect int64 `json:"reconnect_seconds" format:"int64"`
|
Reconnect int64 `json:"reconnect_seconds" format:"int64"`
|
||||||
LastLog string `json:"last_logline"`
|
LastLog string `json:"last_logline"`
|
||||||
Progress *Progress `json:"progress"`
|
Progress *Progress `json:"progress"`
|
||||||
Memory uint64 `json:"memory_bytes" format:"uint64"`
|
Memory uint64 `json:"memory_bytes" format:"uint64"` // deprecated, use Resources.CPU.Current
|
||||||
CPU json.Number `json:"cpu_usage" swaggertype:"number" jsonschema:"type=number"`
|
CPU json.Number `json:"cpu_usage" swaggertype:"number" jsonschema:"type=number"` // deprecated, use Resources.Memory.Current
|
||||||
Command []string `json:"command"`
|
Resources ProcessUsage `json:"resources"`
|
||||||
|
Command []string `json:"command"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal converts a restreamer ffmpeg process state to a state in API representation
|
// Unmarshal converts a restreamer ffmpeg process state to a state in API representation
|
||||||
@@ -227,19 +228,35 @@ func (s *ProcessState) Unmarshal(state *app.State) {
|
|||||||
s.Progress = &Progress{}
|
s.Progress = &Progress{}
|
||||||
s.Memory = state.Memory
|
s.Memory = state.Memory
|
||||||
s.CPU = toNumber(state.CPU)
|
s.CPU = toNumber(state.CPU)
|
||||||
|
s.Resources.CPU = ProcessUsageCPU{
|
||||||
|
Current: toNumber(state.Resources.CPU.Current),
|
||||||
|
Average: toNumber(state.Resources.CPU.Average),
|
||||||
|
Max: toNumber(state.Resources.CPU.Max),
|
||||||
|
Limit: toNumber(state.Resources.CPU.Limit),
|
||||||
|
}
|
||||||
|
s.Resources.Memory = ProcessUsageMemory{
|
||||||
|
Current: state.Resources.Memory.Current,
|
||||||
|
Average: toNumber(state.Resources.Memory.Average),
|
||||||
|
Max: state.Resources.Memory.Max,
|
||||||
|
Limit: state.Resources.Memory.Limit,
|
||||||
|
}
|
||||||
s.Command = state.Command
|
s.Command = state.Command
|
||||||
|
|
||||||
s.Progress.Unmarshal(&state.Progress)
|
s.Progress.Unmarshal(&state.Progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessUsageCPU struct {
|
type ProcessUsageCPU struct {
|
||||||
|
Current json.Number `json:"cur" swaggertype:"number" jsonschema:"type=number"`
|
||||||
Average json.Number `json:"avg" swaggertype:"number" jsonschema:"type=number"`
|
Average json.Number `json:"avg" swaggertype:"number" jsonschema:"type=number"`
|
||||||
Max json.Number `json:"max" swaggertype:"number" jsonschema:"type=number"`
|
Max json.Number `json:"max" swaggertype:"number" jsonschema:"type=number"`
|
||||||
|
Limit json.Number `json:"limit" swaggertype:"number" jsonschema:"type=number"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessUsageMemory struct {
|
type ProcessUsageMemory struct {
|
||||||
|
Current uint64 `json:"cur" format:"uint64"`
|
||||||
Average json.Number `json:"avg" swaggertype:"number" jsonschema:"type=number"`
|
Average json.Number `json:"avg" swaggertype:"number" jsonschema:"type=number"`
|
||||||
Max uint64 `json:"max" format:"uint64"`
|
Max uint64 `json:"max" format:"uint64"`
|
||||||
|
Limit uint64 `json:"limit" format:"uint64"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessUsage struct {
|
type ProcessUsage struct {
|
||||||
|
@@ -57,10 +57,12 @@ func (report *ProcessReport) Unmarshal(l *app.Log) {
|
|||||||
CPU: ProcessUsageCPU{
|
CPU: ProcessUsageCPU{
|
||||||
Average: toNumber(h.Usage.CPU.Average),
|
Average: toNumber(h.Usage.CPU.Average),
|
||||||
Max: toNumber(h.Usage.CPU.Max),
|
Max: toNumber(h.Usage.CPU.Max),
|
||||||
|
Limit: toNumber(h.Usage.CPU.Limit),
|
||||||
},
|
},
|
||||||
Memory: ProcessUsageMemory{
|
Memory: ProcessUsageMemory{
|
||||||
Average: toNumber(h.Usage.Memory.Average),
|
Average: toNumber(h.Usage.Memory.Average),
|
||||||
Max: h.Usage.Memory.Max,
|
Max: h.Usage.Memory.Max,
|
||||||
|
Limit: h.Usage.Memory.Limit,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -160,19 +160,22 @@ type State struct {
|
|||||||
Progress Progress // Progress data of the process
|
Progress Progress // Progress data of the process
|
||||||
Memory uint64 // Current memory consumption in bytes
|
Memory uint64 // Current memory consumption in bytes
|
||||||
CPU float64 // Current CPU consumption in percent
|
CPU float64 // Current CPU consumption in percent
|
||||||
|
Resources ProcessUsage // Current resource usage, include CPU and memory consumption
|
||||||
Command []string // ffmpeg command line parameters
|
Command []string // ffmpeg command line parameters
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessUsageCPU struct {
|
type ProcessUsageCPU struct {
|
||||||
Average float64
|
Current float64 // percent 0-100
|
||||||
Max float64
|
Average float64 // percent 0-100
|
||||||
Limit float64
|
Max float64 // percent 0-100
|
||||||
|
Limit float64 // percent 0-100
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessUsageMemory struct {
|
type ProcessUsageMemory struct {
|
||||||
Average float64
|
Current uint64 // bytes
|
||||||
Max uint64
|
Average float64 // bytes
|
||||||
Limit uint64
|
Max uint64 // bytes
|
||||||
|
Limit uint64 // bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessUsage struct {
|
type ProcessUsage struct {
|
||||||
|
@@ -1283,6 +1283,8 @@ func (r *restream) GetProcessState(id string) (*app.State, error) {
|
|||||||
state.Time = status.Time.Unix()
|
state.Time = status.Time.Unix()
|
||||||
state.Memory = status.Memory.Current
|
state.Memory = status.Memory.Current
|
||||||
state.CPU = status.CPU.Current
|
state.CPU = status.CPU.Current
|
||||||
|
state.Resources.CPU = status.CPU
|
||||||
|
state.Resources.Memory = status.Memory
|
||||||
state.Duration = status.Duration.Round(10 * time.Millisecond).Seconds()
|
state.Duration = status.Duration.Round(10 * time.Millisecond).Seconds()
|
||||||
state.Reconnect = -1
|
state.Reconnect = -1
|
||||||
state.Command = status.CommandArgs
|
state.Command = status.CommandArgs
|
||||||
|
Reference in New Issue
Block a user