🎉 Init

This commit is contained in:
andreas.dinauer 2025-11-16 13:14:35 +01:00
commit d4b014fbcd
9 changed files with 1703 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
/.env

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/node-monitoring.iml" filepath="$PROJECT_DIR$/.idea/node-monitoring.iml" />
</modules>
</component>
</project>

11
.idea/node-monitoring.iml generated Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

1606
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "node-monitoring"
version = "0.1.0"
edition = "2024"
[dependencies]
rocket = "0.5.1"
libc = "0.2"

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
# Stage 1: Build
FROM rust:1.91.1-slim AS builder
# Create app directory
WORKDIR /usr/src/app
# Copy source code
COPY . .
# Build the actual app
RUN cargo build --release
# Stage 2: Runtime
FROM debian:stable-slim
# Copy the compiled binary from the builder stage
COPY --from=builder /usr/src/app/target/release/node-monitoring /usr/local/bin/node-monitoring
CMD ["/usr/local/bin/node-monitoring"]

35
src/main.rs Normal file
View File

@ -0,0 +1,35 @@
use std::{env, ffi::CString};
use libc::{statvfs};
use rocket::http::Status;
#[macro_use] extern crate rocket;
#[get("/")]
fn index() -> Result<String, Status> {
let host_path = env::var("HOST_PATH").unwrap_or_else(|_| "/".to_string());
let path = CString::new(host_path.clone()).map_err(|_| Status::InternalServerError)?;
let mut stat: statvfs = unsafe { std::mem::zeroed() };
let result = unsafe { statvfs(path.as_ptr(), &mut stat) };
if result == 0 {
let block_size = stat.f_frsize as u64;
let total = stat.f_blocks as u64 * block_size;
let free = stat.f_bfree as u64 * block_size;
let used = total - free;
let percentage_used = ((used as f64 / total as f64) * 100.0) as u64;
return Ok(format!("path:{}\ntotal-space:{}\nused-space:{}\npercentage_used:{}", host_path,total, used, percentage_used))
}
Err(Status::InternalServerError)
}
#[launch]
fn rocket() -> _ {
println!("____ __ __ __ ___ _ __ _ ");
println!("__/ |/ /__ ___/ /__ / |/ /__ ___ (_) /____ ____(_)__ ___ _");
println!("_/ / _ \\/ _ / -_) /|_/ / _ \\/ _ \\/ / __/ _ \\/ __/ / _ \\/ _ `/");
println!("/_/|_/\\___/\\_,_/\\__/_/ /_/\\___/_//_/_/\\__/\\___/_/ /_/_//_/\\_, / ");
println!(" /___/ ");
rocket::custom(rocket::Config { address: "0.0.0.0".parse().unwrap(), port: 8080, ..Default::default() }).mount("/", routes![index])
}