Skip to content

Commit

Permalink
Add system resource statistics #4
Browse files Browse the repository at this point in the history
  • Loading branch information
circlesabound committed Oct 21, 2024
1 parent 7187146 commit a9ba7ea
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 17 deletions.
142 changes: 132 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ reqwest = { version = "0.12.8", features = [ "json" ] }
rocksdb = "0.22"
rocket = { version = "0.5.1", features = [ "json" ] }
serde = { version = "1.0.210", features = [ "derive" ] }
serde_json = "1.0.128"
serde_json = "1.0.132"
serenity = { version = "0.12.2", default-features = false, features = [ "client", "gateway", "rustls_backend", "model", "cache" ] }
stream-cancel = "0.8.2"
strum = "0.26.3"
strum_macros = "0.26.4"
sysinfo = "0.32.0"
tar = "0.4.42"
tokio = { version = "1.40.0", features = [ "full" ] }
tokio-stream = { version = "0.1.16", features = [ "sync" ] }
Expand All @@ -43,7 +44,7 @@ toml = "0.8.19"
unicode-xid = "0.2.6"
url = "2.5.2"
urlencoding = "2.1.3"
uuid = { version = "1.10.0", features = [ "serde", "v4" ] }
uuid = { version = "1.11.0", features = [ "serde", "v4" ] }
xz2 = "0.1.7"

[build-dependencies]
Expand All @@ -53,7 +54,7 @@ vergen-gitcl = { version = "1.0", features = [ "build" ] }
serial_test = "3.1.1"

[target.'cfg(not(windows))'.dependencies]
openssl-sys = { version = "0.9.103", features = [ "vendored" ] }
openssl-sys = { version = "0.9.104", features = [ "vendored" ] }

[[bin]]
name = "agent"
Expand Down
32 changes: 32 additions & 0 deletions openapi/mgmt-server-rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,16 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/MetricsPaginationObject'
/system/monitor:
get:
summary: Get system resource utilisation stats
responses:
'200':
description: System resource utilisation stats
content:
application/json:
schema:
$ref: '#/components/schemas/SystemResources'
/buildinfo:
get:
summary: Gets build information for all components
Expand Down Expand Up @@ -1046,6 +1056,28 @@ components:
type: array
items:
$ref: '#/components/schemas/MetricsDataPoint'
SystemResources:
type: object
required:
- cpu_total
- cpus
- mem_total_bytes
- mem_used_bytes
properties:
cpu_total:
type: number
cpus:
type: array
items:
type: number
mem_total_bytes:
type: integer
minimum: 0
format: int64
mem_used_bytes:
type: integer
minimum: 0
format: int64
BuildInfoObject:
properties:
agent:
Expand Down
1 change: 1 addition & 0 deletions src/agent/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum Error {

// Generic
Aggregate(Vec<Error>),
Timeout,

// Generic wrappers around external error types
FactorioDatFileSerde(factorio_file_parser::Error),
Expand Down
21 changes: 21 additions & 0 deletions src/agent/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ impl AgentController {
self.build_version(operation_id).await;
}

// *****************
// System monitoring
// *****************
AgentRequest::SystemResources => {
self.system_resources(operation_id).await;
}

// ***********************
// Installation management
// ***********************
Expand Down Expand Up @@ -541,6 +548,20 @@ impl AgentController {
.await;
}

async fn system_resources(&self, operation_id: OperationId) {
match self.proc_manager.system_resources().await {
Ok(system_resources) => {
self.reply_success(AgentOutMessage::SystemResources(system_resources), operation_id).await;
},
Err(e) => {
self.reply_failed(
AgentOutMessage::Error(format!("Failed to fetch system resource statistics: {:?}", e)),
operation_id
).await;
},
}
}

async fn version_install(
&self,
version_to_install: FactorioVersion,
Expand Down
Loading

0 comments on commit a9ba7ea

Please sign in to comment.