Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for native KVM driver VMs in the Qemu exporter #389

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ core_affinity = { version = "0.8.1"}
x86 = { version = "0.52.0" }

[features]
default = ["prometheus", "riemann", "warpten", "json", "containers", "prometheuspush"]
default = ["prometheus", "riemann", "warpten", "json", "containers", "prometheuspush", "qemu"]
prometheus = ["hyper", "tokio"]
riemann = ["riemann_client"]
json = ["serde", "serde_json"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ You can now run scaphandre to export the metrics with the exporter of your choic

scaphandre --vm prometheus

## How to expose metrics in PROXMOX Virtual Environment

Run scaphandre with the qemu exporter on your bare metal hypervisor machine:

scaphandre qemu

The Qemu exporter will expose virtual machine metrics in `/var/lib/libvirt/scaphandre/${VM_NAME}` with `VM_NAME` being the name of the virtual machine (VM).
Add the following line at the end of the `/etc/pve/qemu-server/${<VM_ID}.conf` file, with `VM_ID` being the ID that PROXMOX has assigned your VM.

args: -fsdev local,security_model=passthrough,id=fsdev0,path=/var/lib/libvirt/scaphandre/${VM_NAME} -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=${VM_NAME}

If you perform this file change with the VM running, you need to restart it for this modification to take effect.
In the guest (VM), mount the required directory in Read-Only mode:

mount -t 9p -o ro,trans=virtio,version=9p2000.L ${VM_NAME} /var/scaphandre

Still in the guest, run scaphandre in VM mode with the default sensor:

scaphandre --vm prometheus

Please refer to the [qemu exporter](../references/exporter-qemu.md) reference for more details.

**Note:** This how to is only suitable for a "manual" use case. For all automated systems like openstack or proxmox, some more work needs to be done to make the integration of those steps easier.
**Note:** This how to is only suitable for a "manual" use case. For automated systems like openstack, some more work needs to be done to make the integration of those steps easier.
22 changes: 22 additions & 0 deletions docs_src/references/exporter-qemu.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,25 @@ First create a tmpfs mount point to isolate metrics for that virtual machine:
scaphandre --vm prometheus

6. Collect your virtual machine specific power usage metrics. (requesting http://VM_IP:8080/metrics in this example, using the prometheus exporter)

## Usage (PROXMOX VIM)

1. Run scaphandre with the qemu exporter on your bare metal hypervisor machine:

scaphandre qemu # this is suitable for a test, please run it as a systemd service for a production setup

2. Default is to expose virtual machines metrics in `/var/lib/libvirt/scaphandre/${VM_NAME}` with `VM_NAME` being the name of the virtual machine (VM).
First, add the following line at the end of the `/etc/pve/qemu-server/${<VM_ID}.conf` file, with `VM_ID` being the ID that PROXMOX has assigned your VM.

args: -fsdev local,security_model=passthrough,id=fsdev0,path=/var/lib/libvirt/scaphandre/${VM_NAME} -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=${VM_NAME}

3. If you perform this file change with the VM running, you need to restart it for this modification to take effect.
4. In the guest (VM), mount the required directory in Read-Only mode:

mount -t 9p -o ro,trans=virtio,version=9p2000.L ${VM_NAME} /var/scaphandre

5. Still in the guest, run scaphandre in VM mode with the default sensor:

scaphandre --vm prometheus

6. Collect your virtual machine specific power usage metrics. (requesting http://${VM_IP}:8080/metrics in this example, using the prometheus exporter)
11 changes: 9 additions & 2 deletions src/exporters/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Exporter for QemuExporter {
let mut timer = time::Duration::from_secs(cleaner_step);
loop {
self.iterate(String::from(path));
let step = time::Duration::from_secs(5);
let step = time::Duration::from_secs(1);
thread::sleep(step);
if timer - step > time::Duration::from_millis(0) {
timer -= step;
Expand Down Expand Up @@ -101,6 +101,13 @@ impl QemuExporter {
/// Parses a cmdline String (as contained in procs::Process instances) and returns
/// the name of the qemu virtual machine if this process is a qemu/kvm guest process
fn get_vm_name_from_cmdline(cmdline: &[String]) -> String {
//If native KVM driver
for i in 0..cmdline.len() {
if cmdline[i].starts_with("-name") {
return String::from(cmdline[i+1].split(',').next().unwrap());
}
}
//If using qemu-system
for elmt in cmdline {
if elmt.starts_with("guest=") {
let mut splitted = elmt.split('=');
Expand Down Expand Up @@ -142,7 +149,7 @@ impl QemuExporter {
.process
.cmdline
.iter()
.find(|x| x.contains("qemu-system"))
.find(|x| x.contains("qemu-system") | x.contains("/usr/bin/kvm"))
{
debug!("Found a process with {}", res);
let mut tmp: Vec<ProcessRecord> = vec![];
Expand Down