-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
534 additions
and
351 deletions.
There are no files selected for viewing
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 @@ | ||
pub mod os; |
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,39 @@ | ||
use crate::agent::Monitor; | ||
use crate::core::database::Document; | ||
use crate::core::layer::sysinfo::os::memory::MemoryData; | ||
use anyhow::Result; | ||
use sysinfo::{MemoryRefreshKind, RefreshKind, System}; | ||
use tracing::trace; | ||
|
||
pub struct MemoryMonitor { | ||
document: Document<MemoryData>, | ||
system: System, | ||
} | ||
|
||
impl MemoryMonitor { | ||
pub fn new(document: Document<MemoryData>) -> Self { | ||
Self { | ||
document, | ||
system: System::new_with_specifics( | ||
RefreshKind::nothing().with_memory(MemoryRefreshKind::everything()), | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl Monitor for MemoryMonitor { | ||
fn refresh(&mut self) -> Result<()> { | ||
self.system.refresh_memory(); | ||
self.document.mutate(|data| { | ||
data.total = self.system.total_memory(); | ||
data.free = self.system.free_memory(); | ||
data.swap_free = self.system.free_swap(); | ||
data.swap_total = self.system.total_swap(); | ||
|
||
trace!(data = ?data, "Polled memory info"); | ||
Ok(()) | ||
}); | ||
|
||
Ok(()) | ||
} | ||
} |
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,2 @@ | ||
pub mod memory; | ||
pub mod user; |
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,19 @@ | ||
use crate::agent::Monitor; | ||
use crate::core::database::{Collection, Oid}; | ||
use crate::core::layer::sysinfo::os::user::UserData; | ||
use anyhow::Result; | ||
use sysinfo::{User, Users}; | ||
|
||
impl Monitor for Collection<UserData> { | ||
fn refresh(&self) -> Result<()> { | ||
for user in Users::new_with_refreshed_list().list() { | ||
self.document(**user.id())?.mutate(|data| { | ||
data.uid = **user.id() as u64; | ||
data.gid = *user.group_id() as u64; | ||
data.username = Some(user.name().to_string()); | ||
Ok(()) | ||
}); | ||
} | ||
Ok(()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,69 +1,37 @@ | ||
pub struct Battery { | ||
/// Manufacturer's name | ||
pub manufacturer: Option<String>, | ||
/// Manufacturer's name | ||
pub manufacturer: Option<String>, | ||
|
||
/// The date the battery was manufactured UNIX Epoch | ||
pub manufacture_date: Option<u64>, | ||
/// The date the battery was manufactured UNIX Epoch | ||
pub manufacture_date: Option<u64>, | ||
|
||
/// Model number | ||
pub model: Option<String>, | ||
/// Model number | ||
pub model: Option<String>, | ||
|
||
/// Serial number | ||
pub serial_number: Option<String>, | ||
/// Serial number | ||
pub serial_number: Option<String>, | ||
|
||
/// Number of charge/discharge cycles | ||
pub cycle_count: Option<u64>, | ||
/// Number of charge/discharge cycles | ||
pub cycle_count: Option<u64>, | ||
|
||
/// Whether the battery is currently being changed by a power source | ||
pub charging: Option<bool>, | ||
/// Whether the battery is currently being changed by a power source | ||
pub charging: Option<bool>, | ||
|
||
/// Whether the battery is completely charged | ||
pub charged: Option<bool>, | ||
} | ||
/// Whether the battery is completely charged | ||
pub charged: Option<bool>, | ||
|
||
/// Maximum capacity specification in mAh | ||
pub specified_capacity: Option<u32>, | ||
|
||
/// Actual maximum capacity in mAh | ||
pub actual_capacity: Option<u32>, | ||
|
||
{ | ||
"collection": true, | ||
"attributes": [ | ||
{ | ||
"name": "charged", | ||
"type": "java.lang.Boolean", | ||
"description": "Whether the battery is completely charged", | ||
"osquery": "battery.charged" | ||
}, | ||
{ | ||
"name": "designed_capacity", | ||
"type": "java.lang.Integer", | ||
"description": "The battery's designed capacity in mAh", | ||
"osquery": "battery.designed_capacity" | ||
}, | ||
{ | ||
"name": "max_capacity", | ||
"type": "java.lang.Integer", | ||
"description": "The battery's actual capacity when it is fully charged in mAh", | ||
"osquery": "battery.max_capacity" | ||
}, | ||
{ | ||
"name": "current_capacity", | ||
"type": "java.lang.Integer", | ||
"description": "The battery's current charged capacity in mAh", | ||
"osquery": "battery.current_capacity" | ||
}, | ||
{ | ||
"name": "percent_remaining", | ||
"type": "java.lang.Integer", | ||
"description": "The percentage of battery remaining before it is drained", | ||
"osquery": "battery.percent_remaining" | ||
}, | ||
{ | ||
"name": "amperage", | ||
"type": "java.lang.Integer", | ||
"description": "The battery's current amperage in mA", | ||
"osquery": "battery.amperage" | ||
}, | ||
{ | ||
"name": "voltage", | ||
"type": "java.lang.Integer", | ||
"description": "The battery's current voltage in mV", | ||
"osquery": "battery.voltage" | ||
} | ||
]} | ||
/// Current capacity in mAh | ||
pub remaining_capacity: Option<u32>, | ||
|
||
/// Amperage in mA | ||
pub current: Option<u32>, | ||
|
||
/// Voltage in mV | ||
pub voltage: Option<u32>, | ||
} |
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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
/// null | ||
pub model: java.lang.String, | ||
/// null | ||
pub vendor: java.lang.String, | ||
/// The specified frequency in Hertz | ||
pub frequency_spec: java.lang.Integer, | ||
/// The size of the L1 cache in bytes | ||
pub l1_cache: java.lang.Integer, | ||
/// The size of the L2 cache in bytes | ||
pub l2_cache: java.lang.Integer, | ||
/// The size of the L3 cache in bytes | ||
pub l3_cache: java.lang.Integer, | ||
/// The size of the L4 cache in bytes | ||
pub l4_cache: java.lang.Integer, | ||
pub struct CpuData { | ||
/// null | ||
pub model: Option<String>, | ||
/// null | ||
pub vendor: Option<String>, | ||
/// The specified frequency in Hertz | ||
pub frequency_spec: u64, | ||
/// The size of the L1 cache in bytes | ||
pub l1_cache: u64, | ||
/// The size of the L2 cache in bytes | ||
pub l2_cache: u64, | ||
/// The size of the L3 cache in bytes | ||
pub l3_cache: u64, | ||
/// The size of the L4 cache in bytes | ||
pub l4_cache: u64, | ||
} | ||
|
||
pub struct Core { | ||
/// The core's usage between 0.0 and 1.0 | ||
pub usage: java.lang.Double, | ||
/// The core's temperature in Celsius | ||
pub temperature: java.lang.Double, | ||
pub struct CpuCoreData { | ||
/// The core's usage between 0.0 and 1.0 | ||
pub usage: Double, | ||
/// The core's temperature in Celsius | ||
pub temperature: Double, | ||
} |
Oops, something went wrong.