mirror of
https://github.com/moghtech/komodo.git
synced 2026-03-11 17:44:19 -05:00
restructure and add more requests
This commit is contained in:
94
Cargo.lock
generated
94
Cargo.lock
generated
@@ -458,6 +458,72 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8"
|
||||
dependencies = [
|
||||
"derive_builder_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_core"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_macro"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e"
|
||||
dependencies = [
|
||||
"derive_builder_core",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diff-struct"
|
||||
version = "0.5.2"
|
||||
@@ -889,6 +955,12 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.4.0"
|
||||
@@ -1096,7 +1168,6 @@ dependencies = [
|
||||
"monitor_helpers",
|
||||
"monitor_types",
|
||||
"parse_csl",
|
||||
"periphery_api",
|
||||
"resolver_api",
|
||||
"run_command",
|
||||
"serde",
|
||||
@@ -1116,7 +1187,9 @@ dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"async_timing_util",
|
||||
"bollard",
|
||||
"bson",
|
||||
"derive_builder",
|
||||
"diff-struct",
|
||||
"resolver_api",
|
||||
"serde",
|
||||
@@ -1333,23 +1406,14 @@ version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
|
||||
|
||||
[[package]]
|
||||
name = "periphery_api"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"monitor_types",
|
||||
"resolver_api",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "periphery_client"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"log",
|
||||
"monitor_periphery",
|
||||
"monitor_types",
|
||||
"periphery_api",
|
||||
"reqwest",
|
||||
"resolver_api",
|
||||
"serde_json",
|
||||
@@ -1523,9 +1587,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "resolver_api"
|
||||
version = "0.1.1"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dddfc550f8f0ebd5def43ec007727b1df0007ab88371a21aca374652e5ee5f31"
|
||||
checksum = "41dc01bd37e0488eaacca0e2041f4d27d0649fe4a53a2d1ade76e66be1e9cddf"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@@ -1536,9 +1600,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "resolver_api_derive"
|
||||
version = "0.1.1"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7369ccba28667dc8de55a0e907029f0c8cfcbb1c6ebaa0b8b204a26f61438fa"
|
||||
checksum = "ff9f6ed2fc4da703f314710c2c703d6b14d57357d2a23828e4ca4e197590d66d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
||||
@@ -14,7 +14,7 @@ monitor_helpers = { path = "lib/helpers" }
|
||||
monitor_types = { path = "lib/types" }
|
||||
monitor_client = { path = "lib/rs_client" }
|
||||
periphery_client = { path = "lib/periphery_client" }
|
||||
periphery_api = { path = "lib/periphery_api" }
|
||||
monitor_periphery = { path = "periphery" }
|
||||
# external
|
||||
tokio = { version = "1.28", features = ["full"] }
|
||||
axum = { version = "0.6", features = ["ws", "json", "headers"] }
|
||||
@@ -33,6 +33,7 @@ simple_logger = "4.1"
|
||||
bson = "2.6.1"
|
||||
bollard = "0.14.0"
|
||||
diff-struct = "0.5"
|
||||
derive_builder = "0.12"
|
||||
typeshare = "1.0.1"
|
||||
strum = "0.24"
|
||||
strum_macros = "0.24"
|
||||
@@ -44,7 +45,7 @@ slack = { package = "slack_client_rs", version = "0.0.8" }
|
||||
merge_config_files = "0.1.3"
|
||||
termination_signal = "0.1.2"
|
||||
async_timing_util = "0.1.14"
|
||||
resolver_api = "0.1.1"
|
||||
resolver_api = "0.1.3"
|
||||
parse_csl = "0.1.0"
|
||||
mungos = "0.3.20"
|
||||
svi = "0.1.4"
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
[package]
|
||||
name = "periphery_api"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
monitor_types.workspace = true
|
||||
serde.workspace = true
|
||||
resolver_api.workspace = true
|
||||
@@ -1 +0,0 @@
|
||||
pub mod requests;
|
||||
@@ -1,91 +0,0 @@
|
||||
use resolver_api::derive::Response;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use monitor_types::entities::server::{
|
||||
AllSystemStats, BasicSystemStats, CpuUsage, DiskUsage, NetworkUsage, SystemComponent,
|
||||
SystemInformation, SystemProcess,
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(GetHealthResponse)]
|
||||
pub struct GetHealth {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GetHealthResponse {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(GetVersionResponse)]
|
||||
pub struct GetVersion {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GetVersionResponse {
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(SystemInformation)]
|
||||
pub struct GetSystemInformation {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(AllSystemStats)]
|
||||
pub struct GetAllSystemStats {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(BasicSystemStats)]
|
||||
pub struct GetBasicSystemStats {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(CpuUsage)]
|
||||
pub struct GetCpuUsage {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(DiskUsage)]
|
||||
pub struct GetDiskUsage {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(NetworkUsage)]
|
||||
pub struct GetNetworkUsage {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(Vec<SystemProcess>)]
|
||||
pub struct GetSystemProcesses {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(Vec<SystemComponent>)]
|
||||
pub struct GetSystemComponents {}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(GetAccountsResponse)]
|
||||
pub struct GetAccounts {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GetAccountsResponse {
|
||||
pub docker: Vec<String>,
|
||||
pub github: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Response)]
|
||||
#[response(Vec<String>)]
|
||||
pub struct GetSecrets {}
|
||||
@@ -9,7 +9,7 @@ license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
monitor_types.workspace = true
|
||||
periphery_api.workspace = true
|
||||
monitor_periphery.workspace = true
|
||||
reqwest.workspace = true
|
||||
anyhow.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
@@ -6,7 +6,7 @@ use reqwest::StatusCode;
|
||||
use resolver_api::HasResponse;
|
||||
use serde_json::json;
|
||||
|
||||
pub use periphery_api::requests;
|
||||
pub use monitor_periphery::requests;
|
||||
|
||||
pub struct PeripheryClient {
|
||||
reqwest: reqwest::Client,
|
||||
|
||||
@@ -18,4 +18,6 @@ async-trait.workspace = true
|
||||
anyhow.workspace = true
|
||||
bson.workspace = true
|
||||
async_timing_util.workspace = true
|
||||
resolver_api.workspace = true
|
||||
resolver_api.workspace = true
|
||||
derive_builder.workspace = true
|
||||
bollard.workspace = true
|
||||
@@ -1,12 +1,17 @@
|
||||
use anyhow::{Context, anyhow};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::{anyhow, Context};
|
||||
use diff::Diff;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::{Display, EnumString};
|
||||
use typeshare::typeshare;
|
||||
|
||||
pub mod deployment;
|
||||
pub mod server;
|
||||
pub mod update;
|
||||
pub mod deployment;
|
||||
|
||||
#[typeshare]
|
||||
pub type PermissionsMap = HashMap<String, PermissionLevel>;
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, Diff)]
|
||||
@@ -66,6 +71,17 @@ pub struct EnvironmentVar {
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Diff)]
|
||||
pub struct CloneArgs {
|
||||
pub name: String,
|
||||
pub repo: Option<String>,
|
||||
pub branch: Option<String>,
|
||||
pub on_clone: Option<SystemCommand>,
|
||||
pub on_pull: Option<SystemCommand>,
|
||||
pub github_account: Option<String>,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[derive(
|
||||
Serialize,
|
||||
|
||||
80
lib/types/src/entities/server/docker_image.rs
Normal file
80
lib/types/src/entities/server/docker_image.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{de::DeserializeOwned, Deserialize, Deserializer, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ImageSummary {
|
||||
/// ID is the content-addressable ID of an image. This identifier is a content-addressable digest calculated from the image's configuration (which includes the digests of layers used by the image). Note that this digest differs from the `RepoDigests` below, which holds digests of image manifests that reference the image.
|
||||
#[serde(rename = "Id")]
|
||||
pub id: String,
|
||||
|
||||
/// ID of the parent image. Depending on how the image was created, this field may be empty and is only set for images that were built/created locally. This field is empty if the image was pulled from an image registry.
|
||||
#[serde(rename = "ParentId")]
|
||||
pub parent_id: String,
|
||||
|
||||
/// List of image names/tags in the local image cache that reference this image. Multiple image tags can refer to the same image, and this list may be empty if no tags reference the image, in which case the image is \"untagged\", in which case it can still be referenced by its ID.
|
||||
#[serde(rename = "RepoTags")]
|
||||
#[serde(deserialize_with = "deserialize_nonoptional_vec")]
|
||||
pub repo_tags: Vec<String>,
|
||||
|
||||
/// List of content-addressable digests of locally available image manifests that the image is referenced from. Multiple manifests can refer to the same image. These digests are usually only available if the image was either pulled from a registry, or if the image was pushed to a registry, which is when the manifest is generated and its digest calculated.
|
||||
#[serde(rename = "RepoDigests")]
|
||||
#[serde(deserialize_with = "deserialize_nonoptional_vec")]
|
||||
pub repo_digests: Vec<String>,
|
||||
|
||||
/// Date and time at which the image was created as a Unix timestamp (number of seconds sinds EPOCH).
|
||||
#[serde(rename = "Created")]
|
||||
pub created: i64,
|
||||
|
||||
/// Total size of the image including all layers it is composed of.
|
||||
#[serde(rename = "Size")]
|
||||
pub size: i64,
|
||||
|
||||
/// Total size of image layers that are shared between this image and other images. This size is not calculated by default. `-1` indicates that the value has not been set / calculated.
|
||||
#[serde(rename = "SharedSize")]
|
||||
pub shared_size: i64,
|
||||
|
||||
/// Total size of the image including all layers it is composed of. In versions of Docker before v1.10, this field was calculated from the image itself and all of its parent images. Docker v1.10 and up store images self-contained, and no longer use a parent-chain, making this field an equivalent of the Size field. This field is kept for backward compatibility, but may be removed in a future version of the API.
|
||||
#[serde(rename = "VirtualSize")]
|
||||
pub virtual_size: i64,
|
||||
|
||||
/// User-defined key/value metadata.
|
||||
#[serde(rename = "Labels")]
|
||||
#[serde(deserialize_with = "deserialize_nonoptional_map")]
|
||||
pub labels: HashMap<String, String>,
|
||||
|
||||
/// Number of containers using this image. Includes both stopped and running containers. This size is not calculated by default, and depends on which API endpoint is used. `-1` indicates that the value has not been set / calculated.
|
||||
#[serde(rename = "Containers")]
|
||||
pub containers: i64,
|
||||
}
|
||||
|
||||
fn deserialize_nonoptional_vec<'de, D: Deserializer<'de>, T: DeserializeOwned>(
|
||||
d: D,
|
||||
) -> Result<Vec<T>, D::Error> {
|
||||
serde::Deserialize::deserialize(d).map(|x: Option<_>| x.unwrap_or(Vec::new()))
|
||||
}
|
||||
|
||||
fn deserialize_nonoptional_map<'de, D: Deserializer<'de>, T: DeserializeOwned>(
|
||||
d: D,
|
||||
) -> Result<HashMap<String, T>, D::Error> {
|
||||
serde::Deserialize::deserialize(d).map(|x: Option<_>| x.unwrap_or(HashMap::new()))
|
||||
}
|
||||
|
||||
impl From<bollard::service::ImageSummary> for ImageSummary {
|
||||
fn from(value: bollard::service::ImageSummary) -> Self {
|
||||
Self {
|
||||
id: value.id,
|
||||
parent_id: value.parent_id,
|
||||
repo_tags: value.repo_tags,
|
||||
repo_digests: value.repo_digests,
|
||||
created: value.created,
|
||||
size: value.size,
|
||||
shared_size: value.shared_size,
|
||||
virtual_size: value.virtual_size,
|
||||
labels: value.labels,
|
||||
containers: value.containers,
|
||||
}
|
||||
}
|
||||
}
|
||||
196
lib/types/src/entities/server/docker_network.rs
Normal file
196
lib/types/src/entities/server/docker_network.rs
Normal file
@@ -0,0 +1,196 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use typeshare::typeshare;
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct DockerNetwork {
|
||||
#[serde(rename = "Name")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
|
||||
#[serde(rename = "Id")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<String>,
|
||||
|
||||
#[serde(rename = "Created")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_timestamp",
|
||||
serialize_with = "serialize_timestamp"
|
||||
)]
|
||||
pub created: Option<String>,
|
||||
|
||||
#[serde(rename = "Scope")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub scope: Option<String>,
|
||||
|
||||
#[serde(rename = "Driver")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub driver: Option<String>,
|
||||
|
||||
#[serde(rename = "EnableIPv6")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enable_ipv6: Option<bool>,
|
||||
|
||||
#[serde(rename = "IPAM")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ipam: Option<Ipam>,
|
||||
|
||||
#[serde(rename = "Internal")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub internal: Option<bool>,
|
||||
|
||||
#[serde(rename = "Attachable")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub attachable: Option<bool>,
|
||||
|
||||
#[serde(rename = "Ingress")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ingress: Option<bool>,
|
||||
|
||||
#[serde(rename = "Containers")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub containers: Option<HashMap<String, NetworkContainer>>,
|
||||
|
||||
#[serde(rename = "Options")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub options: Option<HashMap<String, String>>,
|
||||
|
||||
#[serde(rename = "Labels")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub labels: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
fn deserialize_timestamp<'de, D: Deserializer<'de>>(d: D) -> Result<Option<String>, D::Error> {
|
||||
serde::Deserialize::deserialize(d)
|
||||
}
|
||||
|
||||
fn serialize_timestamp<S: Serializer>(date: &Option<String>, s: S) -> Result<S::Ok, S::Error> {
|
||||
match date {
|
||||
Some(inner) => s.serialize_some(inner),
|
||||
None => s.serialize_none(),
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bollard::service::Network> for DockerNetwork {
|
||||
fn from(value: bollard::service::Network) -> Self {
|
||||
Self {
|
||||
name: value.name,
|
||||
id: value.id,
|
||||
created: value.created,
|
||||
scope: value.scope,
|
||||
driver: value.driver,
|
||||
enable_ipv6: value.enable_ipv6,
|
||||
ipam: value.ipam.map(|ipam| ipam.into()),
|
||||
internal: value.internal,
|
||||
attachable: value.attachable,
|
||||
ingress: value.ingress,
|
||||
containers: value
|
||||
.containers
|
||||
.map(|containers| containers.into_iter().map(|(k, v)| (k, v.into())).collect()),
|
||||
options: value.options,
|
||||
labels: value.labels,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Ipam {
|
||||
/// Name of the IPAM driver to use.
|
||||
#[serde(rename = "Driver")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub driver: Option<String>,
|
||||
|
||||
/// List of IPAM configuration options, specified as a map: ``` {\"Subnet\": <CIDR>, \"IPRange\": <CIDR>, \"Gateway\": <IP address>, \"AuxAddress\": <device_name:IP address>} ```
|
||||
#[serde(rename = "Config")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub config: Option<Vec<IpamConfig>>,
|
||||
|
||||
/// Driver-specific options, specified as a map.
|
||||
#[serde(rename = "Options")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub options: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
impl From<bollard::service::Ipam> for Ipam {
|
||||
fn from(value: bollard::service::Ipam) -> Self {
|
||||
Self {
|
||||
driver: value.driver,
|
||||
config: value
|
||||
.config
|
||||
.map(|config| config.into_iter().map(|c| c.into()).collect()),
|
||||
options: value.options,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct IpamConfig {
|
||||
#[serde(rename = "Subnet")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub subnet: Option<String>,
|
||||
|
||||
#[serde(rename = "IPRange")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ip_range: Option<String>,
|
||||
|
||||
#[serde(rename = "Gateway")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub gateway: Option<String>,
|
||||
|
||||
#[serde(rename = "AuxiliaryAddresses")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auxiliary_addresses: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
impl From<bollard::service::IpamConfig> for IpamConfig {
|
||||
fn from(value: bollard::service::IpamConfig) -> Self {
|
||||
Self {
|
||||
subnet: value.subnet,
|
||||
ip_range: value.ip_range,
|
||||
gateway: value.gateway,
|
||||
auxiliary_addresses: value.auxiliary_addresses,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct NetworkContainer {
|
||||
#[serde(rename = "Name")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
|
||||
#[serde(rename = "EndpointID")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub endpoint_id: Option<String>,
|
||||
|
||||
#[serde(rename = "MacAddress")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mac_address: Option<String>,
|
||||
|
||||
#[serde(rename = "IPv4Address")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ipv4_address: Option<String>,
|
||||
|
||||
#[serde(rename = "IPv6Address")]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ipv6_address: Option<String>,
|
||||
}
|
||||
|
||||
impl From<bollard::service::NetworkContainer> for NetworkContainer {
|
||||
fn from(value: bollard::service::NetworkContainer) -> Self {
|
||||
Self {
|
||||
name: value.name,
|
||||
endpoint_id: value.endpoint_id,
|
||||
mac_address: value.mac_address,
|
||||
ipv4_address: value.ipv4_address,
|
||||
ipv6_address: value.ipv6_address,
|
||||
}
|
||||
}
|
||||
}
|
||||
49
lib/types/src/entities/server/mod.rs
Normal file
49
lib/types/src/entities/server/mod.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use bson::serde_helpers::hex_string_as_object_id;
|
||||
use derive_builder::Builder;
|
||||
use diff::Diff;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
use super::PermissionsMap;
|
||||
|
||||
pub mod docker_network;
|
||||
pub mod docker_image;
|
||||
pub mod stats;
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, Diff, Builder)]
|
||||
#[diff(attr(#[derive(Debug, Serialize)]))]
|
||||
pub struct Server {
|
||||
#[serde(
|
||||
default,
|
||||
rename = "_id",
|
||||
skip_serializing_if = "String::is_empty",
|
||||
with = "hex_string_as_object_id"
|
||||
)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
#[builder(setter(skip))]
|
||||
pub id: String,
|
||||
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub name: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
#[diff(attr(#[serde(skip_serializing_if = "Option::is_none")]))]
|
||||
pub description: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[diff(attr(#[serde(skip_serializing)]))]
|
||||
#[builder(setter(skip))]
|
||||
pub permissions: PermissionsMap,
|
||||
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
#[diff(attr(#[serde(skip)]))]
|
||||
#[builder(setter(skip))]
|
||||
pub created_at: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[diff(attr(#[serde(skip)]))]
|
||||
#[builder(setter(skip))]
|
||||
pub updated_at: String,
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
use crate::I64;
|
||||
|
||||
use super::Timelength;
|
||||
use crate::{entities::Timelength, I64};
|
||||
|
||||
#[typeshare]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
@@ -121,4 +119,4 @@ pub struct SystemComponent {
|
||||
pub max: f32,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub critical: Option<f32>,
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@ edition.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[lib]
|
||||
name = "monitor_periphery"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "periphery"
|
||||
path = "src/main.rs"
|
||||
@@ -15,7 +19,6 @@ path = "src/main.rs"
|
||||
# local
|
||||
monitor_types.workspace = true
|
||||
monitor_helpers.workspace = true
|
||||
periphery_api.workspace = true
|
||||
# external
|
||||
tokio.workspace = true
|
||||
axum.workspace = true
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use anyhow::anyhow;
|
||||
use bollard::{container::ListContainersOptions, Docker};
|
||||
use monitor_types::entities::deployment::BasicContainerInfo;
|
||||
use monitor_types::entities::{
|
||||
deployment::BasicContainerInfo,
|
||||
server::{docker_image::ImageSummary, docker_network::DockerNetwork},
|
||||
};
|
||||
|
||||
pub struct DockerClient {
|
||||
docker: Docker,
|
||||
@@ -42,13 +45,25 @@ impl DockerClient {
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
// pub async fn list_networks(&self) -> anyhow::Result<Vec<Network>> {
|
||||
// let networks = self.docker.list_networks::<String>(None).await?;
|
||||
// Ok(networks)
|
||||
// }
|
||||
pub async fn list_networks(&self) -> anyhow::Result<Vec<DockerNetwork>> {
|
||||
let networks = self
|
||||
.docker
|
||||
.list_networks::<String>(None)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|network| network.into())
|
||||
.collect();
|
||||
Ok(networks)
|
||||
}
|
||||
|
||||
// pub async fn list_images(&self) -> anyhow::Result<Vec<ImageSummary>> {
|
||||
// let images = self.docker.list_images::<String>(None).await?;
|
||||
// Ok(images)
|
||||
// }
|
||||
pub async fn list_images(&self) -> anyhow::Result<Vec<ImageSummary>> {
|
||||
let images = self
|
||||
.docker
|
||||
.list_images::<String>(None)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect();
|
||||
Ok(images)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,45 @@
|
||||
use anyhow::{Context, anyhow};
|
||||
use monitor_helpers::to_monitor_name;
|
||||
use monitor_types::entities::{
|
||||
deployment::{Conversion, RestartMode, TerminationSignal},
|
||||
deployment::{Conversion, RestartMode, TerminationSignal, DockerContainerStats},
|
||||
update::Log,
|
||||
EnvironmentVar,
|
||||
};
|
||||
use run_command::async_run_command;
|
||||
|
||||
use crate::helpers::run_monitor_command;
|
||||
|
||||
pub async fn container_log(container_name: &str, tail: Option<u64>) -> Log {
|
||||
let command = format!(
|
||||
"docker logs {container_name} --tail {}",
|
||||
tail.unwrap_or(1000)
|
||||
);
|
||||
pub async fn container_log(container_name: &str, tail: u64) -> Log {
|
||||
let command = format!("docker logs {container_name} --tail {tail}");
|
||||
run_monitor_command("get container log", command).await
|
||||
}
|
||||
|
||||
// pub async fn container_stats(
|
||||
// container_name: Option<String>,
|
||||
// ) -> anyhow::Result<Vec<DockerContainerStats>> {
|
||||
// let format = "--format \"{{ json . }}\"";
|
||||
// let container_name = match container_name {
|
||||
// Some(name) => format!(" {name}"),
|
||||
// None => "".to_string(),
|
||||
// };
|
||||
// let command = format!("docker stats{container_name} --no-stream {format}");
|
||||
// let output = async_run_command(&command).await;
|
||||
// if output.success() {
|
||||
// let res = output
|
||||
// .stdout
|
||||
// .split('\n')
|
||||
// .filter(|e| !e.is_empty())
|
||||
// .map(|e| {
|
||||
// let parsed =
|
||||
// serde_json::from_str(e).context(format!("failed at parsing entry {e}"))?;
|
||||
// Ok(parsed)
|
||||
// })
|
||||
// .collect::<anyhow::Result<Vec<DockerContainerStats>>>()?;
|
||||
// Ok(res)
|
||||
// } else {
|
||||
// Err(anyhow!("{}", output.stderr.replace('\n', "")))
|
||||
// }
|
||||
// }
|
||||
pub async fn container_stats(
|
||||
container_name: Option<String>,
|
||||
) -> anyhow::Result<Vec<DockerContainerStats>> {
|
||||
let format = "--format \"{{ json . }}\"";
|
||||
let container_name = match container_name {
|
||||
Some(name) => format!(" {name}"),
|
||||
None => "".to_string(),
|
||||
};
|
||||
let command = format!("docker stats{container_name} --no-stream {format}");
|
||||
let output = async_run_command(&command).await;
|
||||
if output.success() {
|
||||
let res = output
|
||||
.stdout
|
||||
.split('\n')
|
||||
.filter(|e| !e.is_empty())
|
||||
.map(|e| {
|
||||
let parsed =
|
||||
serde_json::from_str(e).context(format!("failed at parsing entry {e}"))?;
|
||||
Ok(parsed)
|
||||
})
|
||||
.collect::<anyhow::Result<Vec<DockerContainerStats>>>()?;
|
||||
Ok(res)
|
||||
} else {
|
||||
Err(anyhow!("{}", output.stderr.replace('\n', "")))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn prune_containers() -> Log {
|
||||
let command = String::from("docker container prune -f");
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use async_timing_util::unix_timestamp_ms;
|
||||
use monitor_types::entities::{update::Log, SystemCommand};
|
||||
use monitor_helpers::to_monitor_name;
|
||||
use monitor_types::entities::{update::Log, SystemCommand, CloneArgs};
|
||||
use run_command::async_run_command;
|
||||
|
||||
use super::run_monitor_command;
|
||||
@@ -35,49 +37,49 @@ pub async fn pull(
|
||||
logs
|
||||
}
|
||||
|
||||
// pub async fn clone_repo(
|
||||
// clone_args: impl Into<CloneArgs>,
|
||||
// mut repo_dir: PathBuf,
|
||||
// access_token: Option<String>,
|
||||
// ) -> anyhow::Result<Vec<Log>> {
|
||||
// let CloneArgs {
|
||||
// name,
|
||||
// repo,
|
||||
// branch,
|
||||
// on_clone,
|
||||
// on_pull,
|
||||
// ..
|
||||
// } = clone_args.into();
|
||||
// let repo = repo.as_ref().ok_or(anyhow!("build has no repo attached"))?;
|
||||
// let name = to_monitor_name(&name);
|
||||
// repo_dir.push(name);
|
||||
// let destination = repo_dir.display().to_string();
|
||||
// let clone_log = clone(repo, &destination, &branch, access_token).await;
|
||||
// let mut logs = vec![clone_log];
|
||||
// if let Some(command) = on_clone {
|
||||
// if !command.path.is_empty() && !command.command.is_empty() {
|
||||
// let on_clone_path = repo_dir.join(&command.path);
|
||||
// let on_clone_log = run_monitor_command(
|
||||
// "on clone",
|
||||
// format!("cd {} && {}", on_clone_path.display(), command.command),
|
||||
// )
|
||||
// .await;
|
||||
// logs.push(on_clone_log);
|
||||
// }
|
||||
// }
|
||||
// if let Some(command) = on_pull {
|
||||
// if !command.path.is_empty() && !command.command.is_empty() {
|
||||
// let on_pull_path = repo_dir.join(&command.path);
|
||||
// let on_pull_log = run_monitor_command(
|
||||
// "on pull",
|
||||
// format!("cd {} && {}", on_pull_path.display(), command.command),
|
||||
// )
|
||||
// .await;
|
||||
// logs.push(on_pull_log);
|
||||
// }
|
||||
// }
|
||||
// Ok(logs)
|
||||
// }
|
||||
pub async fn clone_repo(
|
||||
clone_args: impl Into<CloneArgs>,
|
||||
mut repo_dir: PathBuf,
|
||||
access_token: Option<String>,
|
||||
) -> anyhow::Result<Vec<Log>> {
|
||||
let CloneArgs {
|
||||
name,
|
||||
repo,
|
||||
branch,
|
||||
on_clone,
|
||||
on_pull,
|
||||
..
|
||||
} = clone_args.into();
|
||||
let repo = repo.as_ref().ok_or(anyhow!("build has no repo attached"))?;
|
||||
let name = to_monitor_name(&name);
|
||||
repo_dir.push(name);
|
||||
let destination = repo_dir.display().to_string();
|
||||
let clone_log = clone(repo, &destination, &branch, access_token).await;
|
||||
let mut logs = vec![clone_log];
|
||||
if let Some(command) = on_clone {
|
||||
if !command.path.is_empty() && !command.command.is_empty() {
|
||||
let on_clone_path = repo_dir.join(&command.path);
|
||||
let on_clone_log = run_monitor_command(
|
||||
"on clone",
|
||||
format!("cd {} && {}", on_clone_path.display(), command.command),
|
||||
)
|
||||
.await;
|
||||
logs.push(on_clone_log);
|
||||
}
|
||||
}
|
||||
if let Some(command) = on_pull {
|
||||
if !command.path.is_empty() && !command.command.is_empty() {
|
||||
let on_pull_path = repo_dir.join(&command.path);
|
||||
let on_pull_log = run_monitor_command(
|
||||
"on pull",
|
||||
format!("cd {} && {}", on_pull_path.display(), command.command),
|
||||
)
|
||||
.await;
|
||||
logs.push(on_pull_log);
|
||||
}
|
||||
}
|
||||
Ok(logs)
|
||||
}
|
||||
|
||||
async fn clone(
|
||||
repo: &str,
|
||||
|
||||
@@ -3,39 +3,41 @@ use async_timing_util::unix_timestamp_ms;
|
||||
use monitor_types::entities::update::Log;
|
||||
use run_command::{async_run_command, CommandOutput};
|
||||
|
||||
use crate::config::PeripheryConfig;
|
||||
use crate::{config::PeripheryConfig, state::State};
|
||||
|
||||
pub mod stats;
|
||||
pub mod git;
|
||||
pub mod docker;
|
||||
pub mod git;
|
||||
pub mod stats;
|
||||
|
||||
pub fn get_github_token(
|
||||
github_account: &Option<String>,
|
||||
config: &PeripheryConfig,
|
||||
) -> anyhow::Result<Option<String>> {
|
||||
match github_account {
|
||||
Some(account) => match config.github_accounts.get(account) {
|
||||
Some(token) => Ok(Some(token.to_owned())),
|
||||
None => Err(anyhow!(
|
||||
"did not find token in config for github account {account} "
|
||||
)),
|
||||
},
|
||||
None => Ok(None),
|
||||
impl State {
|
||||
pub fn get_github_token(
|
||||
&self,
|
||||
github_account: &Option<String>,
|
||||
) -> anyhow::Result<Option<String>> {
|
||||
match github_account {
|
||||
Some(account) => match self.config.github_accounts.get(account) {
|
||||
Some(token) => Ok(Some(token.to_owned())),
|
||||
None => Err(anyhow!(
|
||||
"did not find token in config for github account {account} "
|
||||
)),
|
||||
},
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_docker_token(
|
||||
docker_account: &Option<String>,
|
||||
config: &PeripheryConfig,
|
||||
) -> anyhow::Result<Option<String>> {
|
||||
match docker_account {
|
||||
Some(account) => match config.docker_accounts.get(account) {
|
||||
Some(token) => Ok(Some(token.to_owned())),
|
||||
None => Err(anyhow!(
|
||||
"did not find token in config for docker account {account} "
|
||||
)),
|
||||
},
|
||||
None => Ok(None),
|
||||
pub fn get_docker_token(
|
||||
&self,
|
||||
docker_account: &Option<String>,
|
||||
) -> anyhow::Result<Option<String>> {
|
||||
match docker_account {
|
||||
Some(account) => match self.config.docker_accounts.get(account) {
|
||||
Some(token) => Ok(Some(token.to_owned())),
|
||||
None => Err(anyhow!(
|
||||
"did not find token in config for docker account {account} "
|
||||
)),
|
||||
},
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,12 +47,7 @@ pub async fn run_monitor_command(stage: &str, command: String) -> Log {
|
||||
output_into_log(stage, command, start_ts, output)
|
||||
}
|
||||
|
||||
pub fn output_into_log(
|
||||
stage: &str,
|
||||
command: String,
|
||||
start_ts: i64,
|
||||
output: CommandOutput,
|
||||
) -> Log {
|
||||
pub fn output_into_log(stage: &str, command: String, start_ts: i64, output: CommandOutput) -> Log {
|
||||
let success = output.success();
|
||||
Log {
|
||||
stage: stage.to_string(),
|
||||
@@ -61,4 +58,4 @@ pub fn output_into_log(
|
||||
start_ts,
|
||||
end_ts: unix_timestamp_ms() as i64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::{cmp::Ordering, sync::Arc};
|
||||
|
||||
use async_timing_util::wait_until_timelength;
|
||||
use monitor_types::entities::{
|
||||
server::{
|
||||
server::stats::{
|
||||
AllSystemStats, BasicSystemStats, CpuUsage, DiskUsage, NetworkUsage, SingleCpuUsage,
|
||||
SingleDiskUsage, SystemComponent, SystemInformation, SystemNetwork, SystemProcess,
|
||||
},
|
||||
|
||||
8
periphery/src/lib.rs
Normal file
8
periphery/src/lib.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
pub mod config;
|
||||
pub mod guard;
|
||||
pub mod helpers;
|
||||
pub mod requests;
|
||||
pub mod state;
|
||||
@@ -7,21 +7,24 @@ use axum::{
|
||||
headers::ContentType, http::StatusCode, middleware, routing::post, Extension, Json, Router,
|
||||
TypedHeader,
|
||||
};
|
||||
use state::State;
|
||||
|
||||
use termination_signal::tokio::immediate_term_handle;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::resolvers::PeripheryRequest;
|
||||
|
||||
mod config;
|
||||
mod guard;
|
||||
mod helpers;
|
||||
mod resolvers;
|
||||
mod requests;
|
||||
mod state;
|
||||
|
||||
use requests::PeripheryRequest;
|
||||
use state::State;
|
||||
|
||||
async fn app() -> anyhow::Result<()> {
|
||||
let state = State::load().await?;
|
||||
|
||||
info!("version: v{}", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
let socket_addr = state.socket_addr()?;
|
||||
|
||||
let app = Router::new()
|
||||
|
||||
192
periphery/src/requests/container.rs
Normal file
192
periphery/src/requests/container.rs
Normal file
@@ -0,0 +1,192 @@
|
||||
use anyhow::anyhow;
|
||||
use monitor_types::entities::{
|
||||
deployment::{BasicContainerInfo, DockerContainerStats, TerminationSignal},
|
||||
server::{docker_image::ImageSummary, docker_network::DockerNetwork},
|
||||
update::Log,
|
||||
};
|
||||
use resolver_api::{derive::Request, Resolve};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{helpers::docker, state::State};
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<BasicContainerInfo>)]
|
||||
pub struct GetContainerList {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetContainerList> for State {
|
||||
async fn resolve(&self, _: GetContainerList) -> anyhow::Result<Vec<BasicContainerInfo>> {
|
||||
self.docker.list_containers().await
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct GetContainerLog {
|
||||
pub name: String,
|
||||
#[serde(default = "default_tail")]
|
||||
pub tail: u64,
|
||||
}
|
||||
|
||||
fn default_tail() -> u64 {
|
||||
50
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetContainerLog> for State {
|
||||
async fn resolve(&self, req: GetContainerLog) -> anyhow::Result<Log> {
|
||||
Ok(docker::container_log(&req.name, req.tail).await)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(DockerContainerStats)]
|
||||
pub struct GetContainerStats {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetContainerStats> for State {
|
||||
async fn resolve(&self, req: GetContainerStats) -> anyhow::Result<DockerContainerStats> {
|
||||
let error = anyhow!("no stats matching {}", req.name);
|
||||
let mut stats = docker::container_stats(Some(req.name)).await?;
|
||||
let stats = stats.pop().ok_or(error)?;
|
||||
Ok(stats)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<DockerContainerStats>)]
|
||||
pub struct GetContainerStatsList {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetContainerStatsList> for State {
|
||||
async fn resolve(&self, _: GetContainerStatsList) -> anyhow::Result<Vec<DockerContainerStats>> {
|
||||
docker::container_stats(None).await
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<DockerNetwork>)]
|
||||
pub struct GetNetworkList {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetNetworkList> for State {
|
||||
async fn resolve(&self, _: GetNetworkList) -> anyhow::Result<Vec<DockerNetwork>> {
|
||||
self.docker.list_networks().await
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<ImageSummary>)]
|
||||
pub struct GetImageList {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetImageList> for State {
|
||||
async fn resolve(&self, _: GetImageList) -> anyhow::Result<Vec<ImageSummary>> {
|
||||
self.docker.list_images().await
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct StartContainer {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<StartContainer> for State {
|
||||
async fn resolve(&self, req: StartContainer) -> anyhow::Result<Log> {
|
||||
Ok(docker::start_container(&req.name).await)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct StopContainer {
|
||||
pub name: String,
|
||||
pub signal: Option<TerminationSignal>,
|
||||
pub time: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<StopContainer> for State {
|
||||
async fn resolve(&self, req: StopContainer) -> anyhow::Result<Log> {
|
||||
Ok(docker::stop_container(&req.name, req.signal, req.time).await)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct RemoveContainer {
|
||||
pub name: String,
|
||||
pub signal: Option<TerminationSignal>,
|
||||
pub time: Option<i32>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<RemoveContainer> for State {
|
||||
async fn resolve(&self, req: RemoveContainer) -> anyhow::Result<Log> {
|
||||
Ok(docker::stop_and_remove_container(&req.name, req.signal, req.time).await)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct RenameContainer {
|
||||
pub curr_name: String,
|
||||
pub new_name: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<RenameContainer> for State {
|
||||
async fn resolve(&self, req: RenameContainer) -> anyhow::Result<Log> {
|
||||
Ok(docker::rename_container(&req.curr_name, &req.new_name).await)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct PruneContainers {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<PruneContainers> for State {
|
||||
async fn resolve(&self, _: PruneContainers) -> anyhow::Result<Log> {
|
||||
Ok(docker::prune_containers().await)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct Deploy {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<Deploy> for State {
|
||||
async fn resolve(&self, _: Deploy) -> anyhow::Result<Log> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
66
periphery/src/requests/git.rs
Normal file
66
periphery/src/requests/git.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use monitor_helpers::to_monitor_name;
|
||||
use monitor_types::entities::{update::Log, CloneArgs, SystemCommand};
|
||||
use resolver_api::{derive::Request, Resolve};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{helpers::git, state::State};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<Log>)]
|
||||
pub struct CloneRepo {
|
||||
pub args: CloneArgs,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<CloneRepo> for State {
|
||||
async fn resolve(&self, CloneRepo { args }: CloneRepo) -> anyhow::Result<Vec<Log>> {
|
||||
let access_token = self.get_github_token(&args.github_account)?;
|
||||
git::clone_repo(args, self.config.repo_dir.clone(), access_token).await
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<Log>)]
|
||||
pub struct PullRepo {
|
||||
pub name: String,
|
||||
pub branch: Option<String>,
|
||||
pub on_pull: Option<SystemCommand>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<PullRepo> for State {
|
||||
async fn resolve(
|
||||
&self,
|
||||
PullRepo {
|
||||
name,
|
||||
branch,
|
||||
on_pull,
|
||||
}: PullRepo,
|
||||
) -> anyhow::Result<Vec<Log>> {
|
||||
let name = to_monitor_name(&name);
|
||||
Ok(git::pull(self.config.repo_dir.join(name), &branch, &on_pull).await)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct DeleteRepo {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<DeleteRepo> for State {
|
||||
async fn resolve(&self, DeleteRepo { name }: DeleteRepo) -> anyhow::Result<Log> {
|
||||
let name = to_monitor_name(&name);
|
||||
let deleted = std::fs::remove_dir_all(self.config.repo_dir.join(&name));
|
||||
let msg = match deleted {
|
||||
Ok(_) => format!("deleted repo {name}"),
|
||||
Err(_) => format!("no repo at {name} to delete"),
|
||||
};
|
||||
Ok(Log::simple("delete repo", msg))
|
||||
}
|
||||
}
|
||||
161
periphery/src/requests/mod.rs
Normal file
161
periphery/src/requests/mod.rs
Normal file
@@ -0,0 +1,161 @@
|
||||
use anyhow::Context;
|
||||
use monitor_types::entities::{update::Log, SystemCommand};
|
||||
use resolver_api::{
|
||||
derive::{Request, Resolver},
|
||||
Resolve, ResolveToString,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{state::State, helpers::run_monitor_command};
|
||||
|
||||
mod stats;
|
||||
pub use stats::*;
|
||||
|
||||
mod container;
|
||||
pub use container::*;
|
||||
|
||||
mod git;
|
||||
pub use git::*;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Resolver)]
|
||||
#[serde(tag = "type", content = "params")]
|
||||
#[resolver_target(State)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub enum PeripheryRequest {
|
||||
// GET
|
||||
GetVersion(GetVersion),
|
||||
#[to_string_resolver]
|
||||
GetHealth(GetHealth),
|
||||
#[to_string_resolver]
|
||||
GetSystemInformation(GetSystemInformation),
|
||||
#[to_string_resolver]
|
||||
GetAllSystemStats(GetAllSystemStats),
|
||||
#[to_string_resolver]
|
||||
GetBasicSystemStats(GetBasicSystemStats),
|
||||
#[to_string_resolver]
|
||||
GetCpuUsage(GetCpuUsage),
|
||||
#[to_string_resolver]
|
||||
GetDiskUsage(GetDiskUsage),
|
||||
#[to_string_resolver]
|
||||
GetNetworkUsage(GetNetworkUsage),
|
||||
#[to_string_resolver]
|
||||
GetSystemProcesses(GetSystemProcesses),
|
||||
#[to_string_resolver]
|
||||
GetSystemComponents(GetSystemComponents),
|
||||
#[to_string_resolver]
|
||||
GetAccounts(GetAccounts),
|
||||
#[to_string_resolver]
|
||||
GetSecrets(GetSecrets),
|
||||
GetContainerList(GetContainerList),
|
||||
GetContainerLog(GetContainerLog),
|
||||
GetContainerStats(GetContainerStats),
|
||||
GetContainerStatsList(GetContainerStatsList),
|
||||
GetNetworkList(GetNetworkList),
|
||||
// ACTIONS
|
||||
RunCommand(RunCommand),
|
||||
CloneRepo(CloneRepo),
|
||||
PullRepo(PullRepo),
|
||||
DeleteRepo(DeleteRepo),
|
||||
// Build {},
|
||||
Deploy(Deploy),
|
||||
StartContainer(StartContainer),
|
||||
StopContainer(StopContainer),
|
||||
RemoveContainer(RemoveContainer),
|
||||
RenameContainer(RenameContainer),
|
||||
PruneContainers(PruneContainers),
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(GetHealthResponse)]
|
||||
pub struct GetHealth {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GetHealthResponse {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetHealth> for State {
|
||||
async fn resolve_to_string(&self, _: GetHealth) -> anyhow::Result<String> {
|
||||
Ok(String::from("{}"))
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(GetVersionResponse)]
|
||||
pub struct GetVersion {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GetVersionResponse {
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetVersion> for State {
|
||||
async fn resolve(&self, _: GetVersion) -> anyhow::Result<GetVersionResponse> {
|
||||
Ok(GetVersionResponse {
|
||||
version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(GetAccountsResponse)]
|
||||
pub struct GetAccounts {}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GetAccountsResponse {
|
||||
pub docker: Vec<String>,
|
||||
pub github: Vec<String>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetAccounts> for State {
|
||||
async fn resolve_to_string(&self, _: GetAccounts) -> anyhow::Result<String> {
|
||||
Ok(self.accounts_response.clone())
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<String>)]
|
||||
pub struct GetSecrets {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetSecrets> for State {
|
||||
async fn resolve_to_string(&self, _: GetSecrets) -> anyhow::Result<String> {
|
||||
Ok(self.secrets_response.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Log)]
|
||||
pub struct RunCommand {
|
||||
pub command: SystemCommand,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<RunCommand> for State {
|
||||
async fn resolve(
|
||||
&self,
|
||||
RunCommand {
|
||||
command: SystemCommand { path, command },
|
||||
}: RunCommand,
|
||||
) -> anyhow::Result<Log> {
|
||||
tokio::spawn(async move {
|
||||
let command = if path.is_empty() {
|
||||
command
|
||||
} else {
|
||||
format!("cd {path} && {command}")
|
||||
};
|
||||
run_monitor_command("run command", command).await
|
||||
})
|
||||
.await
|
||||
.context("failure in spawned task")
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,17 @@
|
||||
use anyhow::Context;
|
||||
use periphery_api::requests::{
|
||||
GetAllSystemStats, GetBasicSystemStats, GetCpuUsage, GetDiskUsage, GetNetworkUsage,
|
||||
GetSystemComponents, GetSystemInformation, GetSystemProcesses,
|
||||
use monitor_types::entities::server::stats::{
|
||||
AllSystemStats, BasicSystemStats, CpuUsage, DiskUsage, NetworkUsage, SystemComponent,
|
||||
SystemInformation, SystemProcess,
|
||||
};
|
||||
use resolver_api::ResolveToString;
|
||||
use resolver_api::{derive::Request, ResolveToString};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(SystemInformation)]
|
||||
pub struct GetSystemInformation {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetSystemInformation> for State {
|
||||
async fn resolve_to_string(&self, _: GetSystemInformation) -> anyhow::Result<String> {
|
||||
@@ -15,6 +20,12 @@ impl ResolveToString<GetSystemInformation> for State {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(AllSystemStats)]
|
||||
pub struct GetAllSystemStats {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetAllSystemStats> for State {
|
||||
async fn resolve_to_string(&self, _: GetAllSystemStats) -> anyhow::Result<String> {
|
||||
@@ -23,6 +34,12 @@ impl ResolveToString<GetAllSystemStats> for State {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(BasicSystemStats)]
|
||||
pub struct GetBasicSystemStats {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetBasicSystemStats> for State {
|
||||
async fn resolve_to_string(&self, _: GetBasicSystemStats) -> anyhow::Result<String> {
|
||||
@@ -31,6 +48,12 @@ impl ResolveToString<GetBasicSystemStats> for State {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(CpuUsage)]
|
||||
pub struct GetCpuUsage {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetCpuUsage> for State {
|
||||
async fn resolve_to_string(&self, _: GetCpuUsage) -> anyhow::Result<String> {
|
||||
@@ -39,6 +62,12 @@ impl ResolveToString<GetCpuUsage> for State {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(DiskUsage)]
|
||||
pub struct GetDiskUsage {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetDiskUsage> for State {
|
||||
async fn resolve_to_string(&self, _: GetDiskUsage) -> anyhow::Result<String> {
|
||||
@@ -47,6 +76,12 @@ impl ResolveToString<GetDiskUsage> for State {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(NetworkUsage)]
|
||||
pub struct GetNetworkUsage {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetNetworkUsage> for State {
|
||||
async fn resolve_to_string(&self, _: GetNetworkUsage) -> anyhow::Result<String> {
|
||||
@@ -55,6 +90,12 @@ impl ResolveToString<GetNetworkUsage> for State {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<SystemProcess>)]
|
||||
pub struct GetSystemProcesses {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetSystemProcesses> for State {
|
||||
async fn resolve_to_string(&self, _: GetSystemProcesses) -> anyhow::Result<String> {
|
||||
@@ -63,6 +104,12 @@ impl ResolveToString<GetSystemProcesses> for State {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Request)]
|
||||
#[response(Vec<SystemComponent>)]
|
||||
pub struct GetSystemComponents {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetSystemComponents> for State {
|
||||
async fn resolve_to_string(&self, _: GetSystemComponents) -> anyhow::Result<String> {
|
||||
@@ -1,90 +0,0 @@
|
||||
use periphery_api::requests::{
|
||||
GetAccounts, GetAllSystemStats, GetBasicSystemStats, GetCpuUsage, GetDiskUsage, GetHealth,
|
||||
GetNetworkUsage, GetSecrets, GetSystemComponents, GetSystemInformation, GetSystemProcesses,
|
||||
GetVersion, GetVersionResponse,
|
||||
};
|
||||
use resolver_api::{derive::Resolver, Resolve, ResolveToString};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
mod system_stats;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Resolver)]
|
||||
#[serde(tag = "type", content = "params")]
|
||||
#[resolver_target(State)]
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub enum PeripheryRequest {
|
||||
// GET
|
||||
#[to_string_resolver]
|
||||
GetHealth(GetHealth),
|
||||
GetVersion(GetVersion),
|
||||
#[to_string_resolver]
|
||||
GetSystemInformation(GetSystemInformation),
|
||||
#[to_string_resolver]
|
||||
GetAllSystemStats(GetAllSystemStats),
|
||||
#[to_string_resolver]
|
||||
GetBasicSystemStats(GetBasicSystemStats),
|
||||
#[to_string_resolver]
|
||||
GetCpuUsage(GetCpuUsage),
|
||||
#[to_string_resolver]
|
||||
GetDiskUsage(GetDiskUsage),
|
||||
#[to_string_resolver]
|
||||
GetNetworkUsage(GetNetworkUsage),
|
||||
#[to_string_resolver]
|
||||
GetSystemProcesses(GetSystemProcesses),
|
||||
#[to_string_resolver]
|
||||
GetSystemComponents(GetSystemComponents),
|
||||
#[to_string_resolver]
|
||||
GetAccounts(GetAccounts),
|
||||
#[to_string_resolver]
|
||||
GetSecrets(GetSecrets),
|
||||
// GetContainerList {},
|
||||
// GetContainerLog {},
|
||||
// GetContainerStats {},
|
||||
// GetContainerStatsList {},
|
||||
// GetNetworkList {},
|
||||
|
||||
// ACTIONS
|
||||
// RunCommand(SystemCommand),
|
||||
// CloneRepo {},
|
||||
// PullRepo {},
|
||||
// DeleteRepo {},
|
||||
// Build {},
|
||||
// Deploy {},
|
||||
// StartContainer {},
|
||||
// StopContainer {},
|
||||
// RemoveContainer {},
|
||||
// RenameContainer {},
|
||||
// PruneContainers {},
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetHealth> for State {
|
||||
async fn resolve_to_string(&self, _: GetHealth) -> anyhow::Result<String> {
|
||||
Ok(String::from("{}"))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetVersion> for State {
|
||||
async fn resolve(&self, _: GetVersion) -> anyhow::Result<GetVersionResponse> {
|
||||
Ok(GetVersionResponse {
|
||||
version: env!("CARGO_PKG_VERSION").to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetAccounts> for State {
|
||||
async fn resolve_to_string(&self, _: GetAccounts) -> anyhow::Result<String> {
|
||||
Ok(self.accounts_response.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ResolveToString<GetSecrets> for State {
|
||||
async fn resolve_to_string(&self, _: GetSecrets) -> anyhow::Result<String> {
|
||||
Ok(self.secrets_response.clone())
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,6 @@ impl State {
|
||||
.with_utc_timestamps()
|
||||
.init()
|
||||
.context("failed to configure logger")?;
|
||||
info!("version: {}", env!("CARGO_PKG_VERSION"));
|
||||
let config = PeripheryConfig::load(&env, &args)?;
|
||||
let state = State {
|
||||
docker: DockerClient::new(),
|
||||
|
||||
@@ -4,23 +4,46 @@ use periphery_client::{requests, PeripheryClient};
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let periphery = PeripheryClient::new("http://localhost:9001", "monitor_passkey");
|
||||
|
||||
let version = periphery.request(requests::GetVersion {}).await?;
|
||||
println!("{version:?}");
|
||||
// let version = periphery.request(requests::GetVersion {}).await?;
|
||||
// println!("{version:?}");
|
||||
|
||||
let system_info = periphery.request(requests::GetSystemInformation {}).await?;
|
||||
println!("{system_info:#?}");
|
||||
// let system_info = periphery.request(requests::GetSystemInformation {}).await?;
|
||||
// println!("{system_info:#?}");
|
||||
|
||||
let processes = periphery.request(requests::GetSystemProcesses {}).await?;
|
||||
// println!("{system_stats:#?}");
|
||||
// let processes = periphery.request(requests::GetSystemProcesses {}).await?;
|
||||
// // println!("{system_stats:#?}");
|
||||
|
||||
let periphery_process = processes.into_iter().find(|p| p.name.contains("periphery"));
|
||||
println!("{periphery_process:#?}");
|
||||
// let periphery_process = processes.into_iter().find(|p| p.name.contains("periphery"));
|
||||
// println!("{periphery_process:#?}");
|
||||
|
||||
let accounts = periphery.request(requests::GetAccounts {}).await?;
|
||||
println!("{accounts:#?}");
|
||||
// let accounts = periphery.request(requests::GetAccounts {}).await?;
|
||||
// println!("{accounts:#?}");
|
||||
|
||||
let secrets = periphery.request(requests::GetSecrets {}).await?;
|
||||
println!("{secrets:#?}");
|
||||
// let secrets = periphery.request(requests::GetSecrets {}).await?;
|
||||
// println!("{secrets:#?}");
|
||||
|
||||
// let container_stats = periphery
|
||||
// .request(requests::GetContainerStatsList {})
|
||||
// .await?;
|
||||
// println!("{container_stats:#?}");
|
||||
|
||||
// let res = periphery.request(requests::GetNetworkList {}).await?;
|
||||
// println!("{res:#?}");
|
||||
|
||||
// let res = periphery
|
||||
// .request(requests::GetContainerStats {
|
||||
// name: "monitor-mongo".into(),
|
||||
// })
|
||||
// .await?;
|
||||
// println!("{res:#?}");
|
||||
|
||||
let res = periphery
|
||||
.request(requests::GetContainerLog {
|
||||
name: "monitor-mongo".into(),
|
||||
tail: 50,
|
||||
})
|
||||
.await?;
|
||||
println!("{res:#?}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user