Browse Source

0.1.3

master 0.1.3
Ryan 1 year ago
parent
commit
9ab5afd99e
  1. 4
      Cargo.toml
  2. 3
      src/lib.rs
  3. 4
      src/metrics.rs
  4. 30
      src/s3.rs

4
Cargo.toml

@ -13,8 +13,6 @@ aws-sdk-kinesis = { version = "1.36", features = ["behavior-version-latest"] }
aws-sdk-ssm = "1.40" aws-sdk-ssm = "1.40"
aws-types="1.3" aws-types="1.3"
aws-credential-types = { version = "1.2", features = ["hardcoded-credentials"] } aws-credential-types = { version = "1.2", features = ["hardcoded-credentials"] }
rusoto_core = "0.48"
rusoto_s3 = "0.48"
deadpool-postgres = "0.14" deadpool-postgres = "0.14"
tokio-postgres = { version = "0.7", features = ["with-chrono-0_4"] } tokio-postgres = { version = "0.7", features = ["with-chrono-0_4"] }
tracing = "0.1" tracing = "0.1"
@ -24,7 +22,7 @@ tracing-appender = "0.2"
thiserror = "1.0" thiserror = "1.0"
tokio = { version = "1.39", features = ["full"] } tokio = { version = "1.39", features = ["full"] }
lapin = "2.5" lapin = "2.5"
sysinfo = "0.30" sysinfo = "0.31"
prometheus = "0.13" prometheus = "0.13"
dashmap = "6.0" dashmap = "6.0"
toml = "0.8" toml = "0.8"

3
src/lib.rs

@ -8,5 +8,4 @@ pub mod env;
pub mod orchestration; pub mod orchestration;
pub mod metrics; pub mod metrics;
pub mod parameter_store; pub mod parameter_store;
pub mod constants; pub mod constants;
mod s3;

4
src/metrics.rs

@ -1,6 +1,6 @@
use sysinfo::System; use sysinfo::System;
use prometheus::{register_gauge, Gauge}; use prometheus::{register_gauge, Gauge};
use std::sync::{Arc, OnceLock}; use std::sync::OnceLock;
pub fn get_cpu_usage() -> &'static Gauge { pub fn get_cpu_usage() -> &'static Gauge {
static GAUGE: OnceLock<Gauge> = OnceLock::new(); static GAUGE: OnceLock<Gauge> = OnceLock::new();
@ -33,7 +33,7 @@ pub fn get_memory_usage() -> &'static Gauge {
pub fn collect(system: &mut System) -> (f64, f64, f64, f64) { pub fn collect(system: &mut System) -> (f64, f64, f64, f64) {
system.refresh_all(); system.refresh_all();
let cpu_usage = system.global_cpu_info().cpu_usage() as f64; let cpu_usage = system.global_cpu_usage() as f64;
let memory_used = system.used_memory() as f64; let memory_used = system.used_memory() as f64;
let memory_total = system.total_memory() as f64; let memory_total = system.total_memory() as f64;
let memory_usage = memory_used / memory_total * 100.0; let memory_usage = memory_used / memory_total * 100.0;

30
src/s3.rs

@ -1,30 +0,0 @@
use std::sync::Arc;
use aws_credential_types::Credentials;
use aws_sdk_kinesis::{Client, Config};
use rusoto_core::{Region, HttpClient};
use rusoto_core::credential::{StaticProvider, ProvideAwsCredentials};
use rusoto_s3::{S3Client, S3, GetObjectRequest};
use tokio::io::AsyncReadExt;
use tokio::sync::OnceCell;
static AWS_S3_CLIENT: OnceCell<Arc<S3Client>> = OnceCell::const_new();
async fn initialize_data() -> Arc<S3Client> {
let config = crate::config::get_config()
.await;
let access_key_id = &config.kinesis_stream.node.access_key.clone();
let secret_access_key = &config.kinesis_stream.node.secret_key.clone();
let region = &config.kinesis_stream.node.region.clone();
let credentials_provider = StaticProvider::new_minimal(access_key_id.to_string(), secret_access_key.to_string());
let s3_client = S3Client::new_with(HttpClient::new().expect("failed to create request dispatcher"), credentials_provider, region.parse().unwrap());
Arc::new(s3_client)
}
async fn get_client() -> Arc<S3Client> {
AWS_S3_CLIENT.get_or_init(initialize_data)
.await
.clone()
}
Loading…
Cancel
Save