-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: new start event * rename: boottime -> boot_time * chore: update gene * refactor: split start event in a module
- xtask-v0.5.4
- xtask-v0.5.3
- xtask-v0.5.2
- xtask-v0.5.1
- xtask-v0.5.0
- xlaunch-v0.5.4
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- kunai-v0.5.4
- kunai-v0.5.3
- kunai-v0.5.2
- kunai-v0.5.1
- kunai-v0.5.0
- kunai-macros-v0.5.4
- kunai-macros-v0.5.3
- kunai-macros-v0.5.2
- kunai-macros-v0.5.1
- kunai-macros-v0.5.0
- kunai-ebpf-v0.5.4
- kunai-ebpf-v0.5.3
- kunai-ebpf-v0.5.2
- kunai-ebpf-v0.5.1
- kunai-ebpf-v0.5.0
- kunai-common-v0.5.4
- kunai-common-v0.5.3
- kunai-common-v0.5.2
- kunai-common-v0.5.1
- kunai-common-v0.5.0
Showing
11 changed files
with
209 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use crate::bpf_events::Event; | ||
|
||
/// Event that must be used only in userland | ||
/// to encode status information | ||
pub type StatusEvent = Event<()>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use chrono::{DateTime, Utc}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::cache::Hashes; | ||
|
||
/// System related information | ||
#[derive(Default, Debug, Serialize, Deserialize)] | ||
pub struct SystemData { | ||
/// Uptime in seconds (read from /proc/uptime) | ||
pub uptime: Option<f64>, | ||
/// Boot time computed from uptime | ||
pub boot_time: Option<DateTime<Utc>>, | ||
/// Utsname information, except nodename | ||
/// which duplicates information in | ||
/// .info.host.name | ||
pub sysname: String, | ||
pub release: String, | ||
pub version: String, | ||
pub machine: String, | ||
pub domainname: String, | ||
} | ||
|
||
/// System related information | ||
#[derive(Default, Debug, Serialize, Deserialize)] | ||
pub struct ConfigData { | ||
pub sha256: String, | ||
} | ||
|
||
/// Encodes Kunai related data | ||
#[derive(Default, Debug, Serialize, Deserialize)] | ||
pub struct KunaiData { | ||
/// Version | ||
pub version: String, | ||
/// Information about executable | ||
pub exe: Hashes, | ||
/// Configuration related data | ||
pub config: ConfigData, | ||
} | ||
|
||
/// Structure holding information we want | ||
/// to display in start events | ||
#[derive(Default, Debug, Serialize, Deserialize)] | ||
pub struct StartData { | ||
pub system: SystemData, | ||
pub kunai: KunaiData, | ||
} | ||
|
||
impl StartData { | ||
pub fn new() -> Self { | ||
Default::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::{ | ||
fs, io, | ||
num::ParseFloatError, | ||
time::{Duration, TryFromFloatSecsError}, | ||
}; | ||
|
||
use chrono::{OutOfRangeError, Utc}; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("failed to read uptime")] | ||
Read, | ||
#[error("parse: {0}")] | ||
ParseFloat(#[from] ParseFloatError), | ||
#[error("io: {0}")] | ||
Io(#[from] io::Error), | ||
#[error("try_from: {0}")] | ||
TryFromFloatSecs(#[from] TryFromFloatSecsError), | ||
#[error("oor: {0}")] | ||
OutOfRange(#[from] OutOfRangeError), | ||
#[error("out of range date computation")] | ||
ComputeOutOfRange, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Uptime(f64, chrono::Duration); | ||
|
||
impl Uptime { | ||
#[inline] | ||
pub fn from_sys() -> Result<Self, Error> { | ||
// Read the content of /proc/uptime | ||
let uptime_content = fs::read_to_string("/proc/uptime")?; | ||
|
||
// Extract the uptime in seconds | ||
let uptime_seconds: f64 = uptime_content | ||
.split_whitespace() | ||
.next() | ||
.ok_or(Error::Read)? | ||
.parse()?; | ||
|
||
Ok(Self( | ||
uptime_seconds, | ||
chrono::Duration::from_std(Duration::try_from_secs_f64(uptime_seconds)?)?, | ||
)) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn as_secs(&self) -> f64 { | ||
self.0 | ||
} | ||
|
||
#[inline(always)] | ||
pub fn boot_time(&self) -> Result<chrono::DateTime<Utc>, Error> { | ||
Utc::now() | ||
.checked_sub_signed(self.1) | ||
.ok_or(Error::ComputeOutOfRange) | ||
} | ||
} |