dragonball: output balloon device metrics to runtime

Balloon device manager adds balloon device metrics to METRICS when a device is created and remove metrics when a device is dropped.

Fixes: #7248

Signed-off-by: Songqian Li <mail@lisongqian.cn>
This commit is contained in:
Songqian Li 2023-10-18 14:03:18 +08:00
parent 09d46450f1
commit 3819f0ee6f
2 changed files with 23 additions and 0 deletions

View File

@ -11,6 +11,7 @@ use crate::address_space_manager::GuestAddressSpaceImpl;
use crate::config_manager::{ConfigItem, DeviceConfigInfo, DeviceConfigInfos};
use crate::device_manager::DbsMmioV2Device;
use crate::device_manager::{DeviceManager, DeviceMgrError, DeviceOpContext};
use crate::metric::METRICS;
// The flag of whether to use the shared irq.
const USE_SHARED_IRQ: bool = true;
@ -175,6 +176,11 @@ impl BalloonDeviceMgr {
)
.map_err(BalloonDeviceError::CreateBalloonDevice)?,
);
METRICS
.write()
.unwrap()
.balloon
.insert(balloon_cfg.balloon_id.clone(), device.metrics());
let mmio_dev =
DeviceManager::create_mmio_virtio_device_with_device_change_notification(
@ -220,6 +226,11 @@ impl BalloonDeviceMgr {
},
)
.map_err(BalloonDeviceError::CreateBalloonDevice)?;
METRICS
.write()
.unwrap()
.balloon
.insert(info.config.balloon_id.clone(), device.metrics());
let mmio_dev =
DeviceManager::create_mmio_virtio_device_with_device_change_notification(
Box::new(device),
@ -275,6 +286,13 @@ impl Default for BalloonDeviceMgr {
}
}
impl Drop for BalloonDeviceMgr {
// todo: move METIRCS oprations to remove_device. issue #8207.
fn drop(&mut self) {
METRICS.write().unwrap().balloon.clear();
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -6,6 +6,7 @@ use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use dbs_utils::metric::SharedIncMetric;
use dbs_virtio_devices::balloon::BalloonDeviceMetrics;
use lazy_static::lazy_static;
use serde::Serialize;
@ -52,6 +53,8 @@ pub struct SignalMetrics {
}
/// Structure storing all metrics while enforcing serialization support on them.
/// The type of the device metrics is HashMap<DeviceId, Arc<DeviceMetrics>> and the type of
/// non-device metrics is XXMetrics.
#[derive(Default, Serialize)]
pub struct DragonballMetrics {
/// Metrics related to a vcpu's functioning.
@ -60,6 +63,8 @@ pub struct DragonballMetrics {
pub seccomp: SeccompMetrics,
/// Metrics related to signals.
pub signals: SignalMetrics,
/// Metrics related to balloon device.
pub balloon: HashMap<String, Arc<BalloonDeviceMetrics>>,
}
#[cfg(test)]