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

WIP: proper handling of windows service lifecycle #342

Merged
merged 35 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b48d0e7
ci: fixing output name of exe file from workflow
bpetit Aug 15, 2023
60eabe4
ci: fixing output name of exe file from workflow
bpetit Aug 15, 2023
d3829eb
ci: fixing output name of exe file from workflow
bpetit Aug 15, 2023
8b3ea5a
ci: fixing output name of exe file from workflow
bpetit Aug 15, 2023
4da908d
feat: enabling to stop the windows service
bpetit Aug 16, 2023
cb1b5f2
feat: enabling to stop the windows service
bpetit Aug 16, 2023
3f96f3f
feat: enabling to stop the windows service
bpetit Aug 16, 2023
f115604
feat: enabling to stop the windows service
bpetit Aug 16, 2023
d3ab6eb
feat: enabling to stop the windows service
bpetit Aug 17, 2023
55b15a4
test: testing package with new driver version
bpetit Aug 31, 2023
84d4c36
test: testing package with new driver version
bpetit Aug 31, 2023
a3ca569
test: testing package with new driver version
bpetit Aug 31, 2023
e6acf6c
test: testing package with new driver version
bpetit Aug 31, 2023
9d2651f
test: testing package with new driver version
bpetit Aug 31, 2023
b2fd1b0
test: testing package with new driver version
bpetit Aug 31, 2023
53dcb33
test: testing package with new driver version
bpetit Aug 31, 2023
b19e43e
build: fixed is script for local dev
bpetit Aug 31, 2023
e7b91a7
feat: enabled manually setting number of cpu sockets for windows/msrr…
bpetit Aug 31, 2023
33d4dd6
feat: early verboe version with multi-socket fixed
bpetit Sep 4, 2023
8a2149e
feat: added rapl core+uncore+domains to topology
bpetit Sep 7, 2023
197c84f
chore: loop to get informations about cores and sockets
bpetit Oct 6, 2023
9f8381e
fix: getting core - socket mapping from apic_id
bpetit Nov 14, 2023
746fa16
style: cleaning code
bpetit Nov 22, 2023
7f5e721
chore: improved domains support and lowered verbosity of debug messages
bpetit Dec 6, 2023
1103155
feat: enabled psys for windows
bpetit Jan 4, 2024
4fec833
style: clippy and fmt
bpetit Jan 5, 2024
759ab4c
style: clippy and fmt
bpetit Jan 5, 2024
839d660
style: clippy
bpetit Jan 5, 2024
402fdac
feat: adding dram to sum of sockets PKG in host total power, when psy…
bpetit Jan 5, 2024
94115c6
chore: lowering log level for fail cases, as it might happen on first…
bpetit Jan 12, 2024
585f198
Merge branch 'dev' into 336-proper-handling-of-windows-service-manage…
bpetit Jan 26, 2024
7739309
fix: removed useless check fails in CI + style
bpetit Jan 27, 2024
f37cd7a
Merge branch '336-proper-handling-of-windows-service-management' of h…
bpetit Jan 30, 2024
fd4244e
ci: disabling tests that can't run on a GH virtual machine
bpetit Jan 30, 2024
75b1de6
ci: fix
bpetit Feb 9, 2024
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
6 changes: 4 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'CITATION'
- 'book.toml'
- 'CONTRIBUTING.md'
- '.github/workflows/exe-release-prometheuspush.yml'
pull_request:
branches: [ main, dev ]
paths-ignore:
Expand All @@ -18,6 +19,7 @@ on:
- 'CHANGELOG.md'
- 'CITATION'
- 'book.toml'
- '.github/workflows/exe-release-prometheuspush.yml'

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -171,7 +173,7 @@ jobs:
rustup toolchain install stable-x86_64-pc-windows-msvc
- name: Tests
run: |
cargo test --no-default-features --features "prometheus json riemann"
cargo test --no-default-features --features "prometheus prometheuspush json riemann" exporters
- name: Build (debug mode)
run: |
cargo build --no-default-features --features "prometheus json riemann"
cargo build --no-default-features --features "prometheus prometheuspush json riemann"
23 changes: 7 additions & 16 deletions .github/workflows/exe-release-prometheuspush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
- 'book.toml'
- 'CONTRIBUTING.md'
tags: [ 'v*.*.*', 'dev*.*.*' ]
branches: [ '311-github-workflow-to-build-and-publish-a-exemsi-file-including-signed-rapl-driver-at-each-tagrelease' ]
branches: [ '336-proper-handling-of-windows-service-management' ]

env:
WRD_VERSION: v0.0.2
WRD_VERSION: v0.0.4
WRD_BASE_URL: https://github.com/hubblo-org/windows-rapl-driver/releases/download

jobs:
Expand All @@ -31,6 +31,7 @@ jobs:
& "D:\a\scaphandre\scaphandre\$dest" /verysilent /suppressmsgbox
ls "C:\Program Files (x86)\Inno Setup 6\"
- name: Get windows-rapl-driver
shell: pwsh
run: |
$dest = "DriverLoader.exe"
$url = "${{ env.WRD_BASE_URL }}/${{ env.WRD_VERSION }}/DriverLoader.exe"
Expand All @@ -44,16 +45,6 @@ jobs:
$dest = "ScaphandreDrv.inf"
$url = "${{ env.WRD_BASE_URL }}/${{ env.WRD_VERSION }}/ScaphandreDrv.inf"
Invoke-WebRequest -Uri ($url -replace '"', "") -OutFile $dest
$dest = "ScaphandreDrvTest.cer"
$url = "${{ env.WRD_BASE_URL }}/${{ env.WRD_VERSION }}/ScaphandreDrvTest.cer"
Invoke-WebRequest -Uri ($url -replace '"', "") -OutFile $dest
$dest = "devcon.exe"
$url = "${{ env.WRD_BASE_URL }}/${{ env.WRD_VERSION }}/devcon.exe"
Invoke-WebRequest -Uri ($url -replace '"', "") -OutFile $dest
$dest = "certmgr.exe"
$url = "${{ env.WRD_BASE_URL }}/${{ env.WRD_VERSION }}/certmgr.exe"
Invoke-WebRequest -Uri ($url -replace '"', "") -OutFile $dest
ls
- name: Install Rustup
uses: crazy-max/ghaction-chocolatey@v2
with:
Expand All @@ -70,14 +61,14 @@ jobs:
- name: Upload artifact #Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
run: |
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module -Confirm:$False -Name AWS.Tools.Installer
Install-Module -Confirm:$False -Name AWS.Tools.Installer
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Import-Module AWS.Tools.Installer
Install-AWSToolsModule AWS.Tools.EC2,AWS.Tools.S3 -CleanUp -Confirm:$False
Install-AWSToolsModule AWS.Tools.EC2,AWS.Tools.S3 -CleanUp -Confirm:$False -AllowClobber
Set-AWSCredential -AccessKey ${{ secrets.S3_ACCESS_KEY_ID }} -SecretKey ${{ secrets.S3_SECRET_ACCESS_KEY }} -StoreAs default
mv packaging/windows/Output/scaphandre_installer.exe scaphandre_${GITHUB_REF_NAME}_installer.exe
mv packaging/windows/Output/scaphandre_installer.exe scaphandre_${{ github.ref_name }}_installer.exe
$clientconfig=@{
SignatureVersion="s3v4"
ServiceUrl="https://s3.fr-par.scw.cloud"
}
Write-S3Object -EndpointUrl "https://s3.fr-par.scw.cloud" -Region "fr-par" -BucketName "scaphandre" -File scaphandre_${GITHUB_REF_NAME}_installer.exe -key "x86_64/scaphandre_${GITHUB_REF_NAME}_installer.exe" -PublicReadOnly -ClientConfig $clientconfig
Write-S3Object -EndpointUrl "https://s3.fr-par.scw.cloud" -Region "fr-par" -BucketName "scaphandre" -File scaphandre_${{ github.ref_name }}_installer.exe -key "x86_64/scaphandre_${{ github.ref_name }}_installer.exe" -PublicReadOnly -ClientConfig $clientconfig
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ isahc = { version = "1.7.2", optional = true }
procfs = { version = "0.15.0" }

[target.'cfg(target_os="windows")'.dependencies]
windows = { version = "0.27.0", features = ["alloc","Win32_Storage_FileSystem","Win32_Foundation","Win32_Security","Win32_System_IO","Win32_System_Ioctl"]}
windows = { version = "0.27.0", features = ["alloc","Win32_Storage_FileSystem","Win32_Foundation","Win32_Security","Win32_System_IO","Win32_System_Ioctl","Win32_System_Threading", "Win32_System_SystemInformation"]}
windows-service = { version = "0.6.0" }
raw-cpuid = { version = "10.5.0" }
core_affinity = { version = "0.8.1"}
x86 = { version = "0.52.0" }

[features]
default = ["prometheus", "riemann", "warpten", "json", "containers", "prometheuspush"]
Expand Down
14 changes: 7 additions & 7 deletions packaging/windows/dev_installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ Name: "english"; MessagesFile: "compiler:Default.isl"
[Files]
Source: "{#MyAppSourceFolder}\target\release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#RaplDriverSourceFolder}\x64\Release\DriverLoader.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#RaplDriverSourceFolder}\ScaphandreDrv\ScaphandreDrv.inf"; DestDir: "{app}"; Flags: ignoreversion
; Source: "{#RaplDriverSourceFolder}\ScaphandreDrv\ScaphandreDrv.sys"; DestDir: "{#SystemFolder}";
; Source: "{#RaplDriverSourceFolder}\ScaphandreDrv\ScaphandreDrv.sys"; DestDir: "{#System64Folder}";
Source: "{#RaplDriverSourceFolder}\ScaphandreDrv\ScaphandreDrv.sys"; DestDir: "{app}";
Source: "{#RaplDriverSourceFolder}\ScaphandreDrv\ScaphandreDrv.cat"; DestDir: "{app}";
; Source: "{#RaplDriverSourceFolder}\ScaphandreDrv\ScaphandreDrv.cat"; DestDir: "{#SystemFolder}";
; Source: "{#RaplDriverSourceFolder}\ScaphandreDrv\ScaphandreDrv.cat"; DestDir: "{#System64Folder}";
Source: "{#RaplDriverSourceFolder}\x64\Release\ScaphandreDrv\ScaphandreDrv.inf"; DestDir: "{app}"; Flags: ignoreversion
; Source: "{#RaplDriverSourceFolder}\x64\Release\ScaphandreDrv\ScaphandreDrv.sys"; DestDir: "{#SystemFolder}";
; Source: "{#RaplDriverSourceFolder}\x64\Release\ScaphandreDrv\ScaphandreDrv.sys"; DestDir: "{#System64Folder}";
Source: "{#RaplDriverSourceFolder}\x64\Release\ScaphandreDrv\ScaphandreDrv.sys"; DestDir: "{app}";
Source: "{#RaplDriverSourceFolder}\x64\Release\ScaphandreDrv\ScaphandreDrv.cat"; DestDir: "{app}";
; Source: "{#RaplDriverSourceFolder}\x64\Release\ScaphandreDrv\ScaphandreDrv.cat"; DestDir: "{#SystemFolder}";
; Source: "{#RaplDriverSourceFolder}\x64\Release\ScaphandreDrv\ScaphandreDrv.cat"; DestDir: "{#System64Folder}";
Source: "C:\Program Files (x86)\Windows Kits\10\Tools\10.0.22621.0\x64\devcon.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\certmgr.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSourceFolder}\README.md"; DestDir: "{app}"; Flags: ignoreversion
Expand Down
5 changes: 2 additions & 3 deletions packaging/windows/installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ Source: "../../ScaphandreDrv.sys"; DestDir: "{app}";
Source: "../../ScaphandreDrv.cat"; DestDir: "{app}";
; Source: "../../ScaphandreDrv.cat"; DestDir: "{#SystemFolder}";
; Source: "../../ScaphandreDrv.cat"; DestDir: "{#System64Folder}";
Source: "../../devcon.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../certmgr.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Program Files (x86)\Windows Kits\10\Tools\10.0.22621.0\x64\devcon.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64\certmgr.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../README.md"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../CHANGELOG.md"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../ScaphandreDrvTest.cer"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Expand Down
40 changes: 40 additions & 0 deletions packaging/windows/register_log_source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# https://github.com/dansmith
#
$source = "scaphandre"


$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp=new-object System.Security.Principal.WindowsPrincipal($wid)
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin=$prp.IsInRole($adm)

if($IsAdmin -eq $false)
{
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show(“Please run this as an Administrator”,
“Not Administrator”,
[Windows.Forms.MessageBoxButtons]::OK,
[Windows.Forms.MessageBoxIcon]::Information)
exit
}


if ([System.Diagnostics.EventLog]::SourceExists($source) -eq $false)
{
[System.Diagnostics.EventLog]::CreateEventSource($source, "Application")

[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show(“Event log created successfully”,
“Complete”,
[Windows.Forms.MessageBoxButtons]::OK,
[Windows.Forms.MessageBoxIcon]::Information)
}
else
{
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show(“Event log already exists”,
“Complete”,
[Windows.Forms.MessageBoxButtons]::OK,
[Windows.Forms.MessageBoxIcon]::Information)

}
21 changes: 2 additions & 19 deletions src/exporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,23 +630,6 @@ impl MetricGenerator {
description: String::from("Total swap space on the host, in bytes."),
metric_value: MetricValueType::Text(metric_value.value),
});

if let Some(psys) = self.topology.get_rapl_psys_energy_microjoules() {
self.data.push(Metric {
name: String::from("scaph_host_rapl_psys_microjoules"),
metric_type: String::from("counter"),
ttl: 60.0,
timestamp: psys.timestamp,
hostname: self.hostname.clone(),
state: String::from("ok"),
tags: vec!["scaphandre".to_string()],
attributes: HashMap::new(),
description: String::from(
"Raw extract of RAPL PSYS domain energy value, in microjoules",
),
metric_value: MetricValueType::Text(psys.value),
})
}
}

/// Generate socket metrics.
Expand Down Expand Up @@ -887,7 +870,7 @@ impl MetricGenerator {

/// Generate process metrics.
fn gen_process_metrics(&mut self) {
debug!("In gen_process_metrics.");
trace!("In gen_process_metrics.");
#[cfg(feature = "containers")]
if self.watch_containers {
let now = current_system_time_since_epoch().as_secs().to_string();
Expand Down Expand Up @@ -1029,7 +1012,7 @@ impl MetricGenerator {
Utc::now().format("%Y-%m-%dT%H:%M:%S")
);
self.gen_process_metrics();
debug!("self_metrics: {:#?}", self.data);
trace!("self_metrics: {:#?}", self.data);
}

pub fn pop_metrics(&mut self) -> Vec<Metric> {
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! [scrape](https://prometheus.io/docs/prometheus/latest/getting_started).

use super::utils;
use crate::current_system_time_since_epoch;
use crate::exporters::{Exporter, MetricGenerator, MetricValueType};
use crate::sensors::utils::current_system_time_since_epoch;
use crate::sensors::{Sensor, Topology};
use chrono::Utc;
use hyper::service::{make_service_fn, service_fn};
Expand Down
16 changes: 13 additions & 3 deletions src/exporters/stdout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,14 @@ impl StdoutExporter {
fn summarized_view(&mut self, metrics: Vec<Metric>) {
let mut metrics_iter = metrics.iter();
let none_value = MetricValueType::Text("0".to_string());
let mut host_power_source = String::from("");
let host_power = match metrics_iter.find(|x| x.name == "scaph_host_power_microwatts") {
Some(m) => &m.metric_value,
Some(m) => {
if let Some(src) = &m.attributes.get("value_source") {
host_power_source = src.to_string()
}
&m.metric_value
}
None => &none_value,
};

Expand All @@ -121,8 +127,9 @@ impl StdoutExporter {
}

println!(
"Host:\t{} W",
(format!("{host_power}").parse::<f64>().unwrap() / 1000000.0)
"Host:\t{} W from {}",
(format!("{host_power}").parse::<f64>().unwrap() / 1000000.0),
host_power_source
);

if domain_names.is_some() {
Expand All @@ -133,6 +140,7 @@ impl StdoutExporter {
.iter()
.filter(|x| x.name == "scaph_socket_power_microwatts")
{
debug!("✅ Found socket power metric !");
let power = format!("{}", s.metric_value).parse::<f32>().unwrap() / 1000000.0;
let mut power_str = String::from("----");
if power > 0.0 {
Expand Down Expand Up @@ -176,6 +184,8 @@ impl StdoutExporter {
}
}
println!("{to_print}\n");
} else {
println!("{to_print} Could'nt get per-domain metrics.\n");
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use sensors::msr_rapl;
#[cfg(target_os = "linux")]
use sensors::powercap_rapl;

use std::time::{Duration, SystemTime};

/// Create a new [`Sensor`] instance with the default sensor available,
/// with its default options.
pub fn get_default_sensor() -> impl sensors::Sensor {
Expand All @@ -30,12 +28,6 @@ pub fn get_default_sensor() -> impl sensors::Sensor {
return msr_rapl::MsrRAPLSensor::new();
}

fn current_system_time_since_epoch() -> Duration {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
}

// Copyright 2020 The scaphandre authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading
Loading