prog on doc entity

This commit is contained in:
mbecker20
2024-04-15 04:31:32 -07:00
parent 0bdb3ddfea
commit ccc7852576
7 changed files with 112 additions and 10 deletions

View File

@@ -23,6 +23,7 @@ use super::{
#[doc_index(doc! { "target.type": 1 })]
#[doc_index(doc! { "target.id": 1 })]
pub struct Alert {
/// The mongo id
#[serde(
default,
rename = "_id",
@@ -31,18 +32,28 @@ pub struct Alert {
)]
pub id: MongoId,
/// Unix timestamp in milliseconds the alert was opened
#[index]
pub ts: I64,
/// Whether the alert is already resolved
#[index]
pub resolved: bool,
/// The severity of the alert
#[index]
pub level: SeverityLevel,
/// The target of the alert
pub target: ResourceTarget,
/// The type of alert, eg ServerUnreachable, ServerMem, ContainerStateChange
pub variant: AlertDataVariant,
/// The data attached to the alert
pub data: AlertData,
/// The timestamp of alert resolution
pub resolved_ts: Option<I64>,
}
@@ -61,41 +72,67 @@ pub struct Alert {
#[serde(tag = "type", content = "data")]
pub enum AlertData {
ServerUnreachable {
/// The id of the server
id: String,
/// The name of the server
name: String,
/// The region of the server
region: Option<String>,
/// The error data
err: Option<_Serror>,
},
ServerCpu {
/// The id of the server
id: String,
/// The name of the server
name: String,
/// The region of the server
region: Option<String>,
/// The cpu usage percentage
percentage: f64,
},
ServerMem {
/// The id of the server
id: String,
/// The name of the server
name: String,
/// The region of the server
region: Option<String>,
/// The used memory
used_gb: f64,
/// The total memory
total_gb: f64,
},
ServerDisk {
/// The id of the server
id: String,
/// The name of the server
name: String,
/// The region of the server
region: Option<String>,
/// The mount path of the disk
path: PathBuf,
/// The used portion of the disk in GB
used_gb: f64,
/// The total size of the disk in GB
total_gb: f64,
},
ContainerStateChange {
/// The id of the deployment
id: String,
/// The name of the deployment
name: String,
/// The server id of server deployment is on
server_id: String,
/// The server name
server_name: String,
/// The previous container state
from: DockerContainerState,
/// The current container state
to: DockerContainerState,
},
AwsBuilderTerminationFailed {
/// The id of the aws instance which failed to terminate
instance_id: String,
},
None {},

View File

@@ -20,8 +20,11 @@ pub type AlerterListItem = ResourceListItem<AlerterListItemInfo>;
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AlerterListItemInfo {
/// Whether alerter is enabled for sending alerts
pub enabled: bool,
/// Whether the alerter is the default
pub is_default: bool,
/// The type of the alerter, eg. Slack, Custom
pub alerter_type: String,
}
@@ -123,8 +126,10 @@ impl AlerterConfig {
#[skip_serializing_none]
#[partial_from]
pub struct CustomAlerterConfig {
/// The http/s endpoint to send the POST to
#[partial_default(String::from("http://localhost:7000"))]
pub url: String,
/// Whether the alerter is enabled
#[serde(default)]
pub enabled: bool,
}
@@ -135,10 +140,12 @@ pub struct CustomAlerterConfig {
#[skip_serializing_none]
#[partial_from]
pub struct SlackAlerterConfig {
/// The slack app url
#[partial_default(String::from(
"https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
))]
pub url: String,
/// Whether the alerter is enabled
#[serde(default)]
pub enabled: bool,
}

View File

@@ -10,24 +10,24 @@ use super::I64;
Serialize, Deserialize, Debug, Clone, Default, MongoIndexed,
)]
pub struct ApiKey {
/// UNIQUE KEY ASSOCIATED WITH SECRET
/// Unique key associated with secret
#[unique_index]
pub key: String,
/// HASH OF THE SECRET
/// Hash of the secret
pub secret: String,
/// USER ASSOCIATED WITH THE API KEY
/// User associated with the api key
#[index]
pub user_id: String,
/// NAME ASSOCIATED WITH THE API KEY FOR MANAGEMENT
/// Name associated with the api key for management
pub name: String,
/// TIMESTAMP OF KEY CREATION
/// Timestamp of key creation
pub created_at: I64,
/// EXPIRY OF KEY, OR 0 IF NEVER EXPIRES
/// Expiry of key, or 0 if never expires
pub expires: I64,
}

View File

@@ -21,9 +21,13 @@ pub type BuildListItem = ResourceListItem<BuildListItemInfo>;
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct BuildListItemInfo {
/// Unix timestamp in milliseconds of last build
pub last_built_at: I64,
/// The current version of the build
pub version: Version,
/// The Github repo used as the source of the build
pub repo: String,
/// The branch of the repo
pub branch: String,
}
@@ -42,66 +46,85 @@ pub type _PartialBuildConfig = PartialBuildConfig;
#[skip_serializing_none]
#[partial_from]
pub struct BuildConfig {
/// Which builder is used to build the image.
#[serde(default, alias = "builder")]
#[partial_attr(serde(alias = "builder"))]
#[builder(default)]
pub builder_id: String,
/// Whether to skip secret interpolation in the build_args.
#[serde(default)]
#[builder(default)]
pub skip_secret_interp: bool,
/// The current version of the build.
#[serde(default)]
#[builder(default)]
pub version: Version,
/// The Github repo used as the source of the build.
#[serde(default)]
#[builder(default)]
pub repo: String,
/// The branch of the repo.
#[serde(default = "default_branch")]
#[builder(default = "default_branch()")]
#[partial_default(default_branch())]
pub branch: String,
/// The github account used to clone (used to access private repos).
/// Empty string is public clone (only public repos).
#[serde(default)]
#[builder(default)]
pub github_account: String,
/// The dockerhub account used to push the image to dockerhub.
/// Empty string means no dockerhub push (server local build).
#[serde(default)]
#[builder(default)]
pub docker_account: String,
/// The docker organization which the image should be pushed under.
/// Empty string means no organization.
#[serde(default)]
#[builder(default)]
pub docker_organization: String,
/// The optional command run after repo clone and before docker build.
#[serde(default)]
#[builder(default)]
pub pre_build: SystemCommand,
/// The path of the docker build context relative to the root of the repo.
/// Default: "." (the root of the repo).
#[serde(default = "default_build_path")]
#[builder(default = "default_build_path()")]
#[partial_default(default_build_path())]
pub build_path: String,
/// The path of the dockerfile relative to the build path.
#[serde(default = "default_dockerfile_path")]
#[builder(default = "default_dockerfile_path()")]
#[partial_default(default_dockerfile_path())]
pub dockerfile_path: String,
/// Docker build arguments
#[serde(default)]
#[builder(default)]
pub build_args: Vec<EnvironmentVar>,
/// Docker labels
#[serde(default)]
#[builder(default)]
pub labels: Vec<EnvironmentVar>,
/// Any extra docker cli arguments to be included in the build command
#[serde(default)]
#[builder(default)]
pub extra_args: Vec<String>,
/// Whether to use buildx to build (eg `docker buildx build ...`)
#[serde(default)]
#[builder(default)]
pub use_buildx: bool,

View File

@@ -7,6 +7,7 @@ use typeshare::typeshare;
use crate::entities::I64;
/// Summary of docker image cached on a server
#[typeshare]
#[derive(
Debug, Clone, Default, PartialEq, Serialize, Deserialize,

View File

@@ -8,14 +8,17 @@ use typeshare::typeshare;
Debug, Clone, Default, PartialEq, Serialize, Deserialize,
)]
pub struct DockerNetwork {
/// The name of the docker network
#[serde(rename = "Name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// The Id of the docker network
#[serde(rename = "Id")]
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// Timestamp network created
#[serde(rename = "Created")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(

View File

@@ -25,39 +25,57 @@ pub struct SystemInformation {
)]
#[collection_name(Stats)]
pub struct SystemStatsRecord {
/// Unix timestamp in milliseconds
#[index]
pub ts: I64,
/// Server id
#[index]
pub sid: String,
// basic stats
/// Cpu usage percentage
pub cpu_perc: f32,
/// Memory used in GB
pub mem_used_gb: f64,
/// Total memory in GB
pub mem_total_gb: f64,
/// Disk used in GB
pub disk_used_gb: f64,
/// Total disk size in GB
pub disk_total_gb: f64,
/// Breakdown of individual disks, ie their usages, sizes, and mount points
pub disks: Vec<SingleDiskUsage>,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct SystemStats {
/// Cpu usage percentage
pub cpu_perc: f32,
/// Memory used in GB
pub mem_used_gb: f64,
/// Total memory in GB
pub mem_total_gb: f64,
/// Breakdown of individual disks, ie their usages, sizes, and mount points
pub disks: Vec<SingleDiskUsage>,
// metadata
/// The rate the system stats are being polled from the system
pub polling_rate: Timelength,
/// Unix timestamp in milliseconds when stats were last polled
pub refresh_ts: I64,
/// Unix timestamp in milliseconds when disk list was last refreshed
pub refresh_list_ts: I64,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SingleDiskUsage {
/// The mount point of the disk
pub mount: PathBuf,
pub used_gb: f64, // in GB
pub total_gb: f64, // in GB
/// Used portion of the disk in GB
pub used_gb: f64,
/// Total size of the disk in GB
pub total_gb: f64,
}
pub fn sum_disk_usage(disks: &[SingleDiskUsage]) -> TotalDiskUsage {
@@ -73,23 +91,36 @@ pub fn sum_disk_usage(disks: &[SingleDiskUsage]) -> TotalDiskUsage {
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct TotalDiskUsage {
pub used_gb: f64, // in GB
pub total_gb: f64, // in GB
/// Used portion in GB
pub used_gb: f64,
/// Total size in GB
pub total_gb: f64,
}
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SystemProcess {
/// The process PID
pub pid: u32,
/// The process name
pub name: String,
/// The path to the process executable
#[serde(default)]
pub exe: String,
/// The command used to start the process
pub cmd: Vec<String>,
/// The time the process was started
#[serde(default)]
pub start_time: f64,
/// The cpu usage percentage of the process.
/// This is in core-percentage, eg 100% is 1 full core, and
/// an 8 core machine would max at 800%.
pub cpu_perc: f32,
/// The memory usage of the process in MB
pub mem_mb: f64,
/// Process disk read in KB/s
pub disk_read_kb: f64,
/// Process disk write in KB/s
pub disk_write_kb: f64,
}