forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IPMI DCMI based power reading rrdd plugin
Signed-off-by: Edwin Török <[email protected]>
- Loading branch information
1 parent
27f5adc
commit 1e0e1dc
Showing
4 changed files
with
105 additions
and
1 deletion.
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,16 @@ | ||
(executable | ||
(modes exe) | ||
(name rrdp_dcmi) | ||
(package rrdd-plugins) | ||
(public_name xcp-rrdd-dcmi) | ||
(libraries | ||
dune-build-info | ||
rrdd-plugin | ||
rrdd-plugins.libs | ||
xapi-idl.rrd | ||
xapi-log | ||
xapi-rrd | ||
astring | ||
) | ||
) | ||
|
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,87 @@ | ||
(* | ||
* Copyright (C) 2024 Cloud Software Group, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; version 2.1 only. with the special | ||
* exception on linking described in file LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
*) | ||
|
||
(** Read power measurements from IPMI DCMI where available. | ||
There is also IPMI SDR entity 21 that returns the same information (power consumption in watts), | ||
but isn't always available, and seems to be slower to read, especially when missing. | ||
*) | ||
|
||
open Rrdd_plugin | ||
|
||
module Process = Process (struct let name = "xcp-rrdd-dcmi" end) | ||
|
||
open Process | ||
|
||
let ipmitool_bin = "/usr/sbin/ipmitool" | ||
|
||
let ipmitool args = | ||
(* we connect to the local /dev/ipmi0 if available to read measurements from local BMC *) | ||
Filename.quote_command ipmitool_bin ("-I" :: "open" :: args) | ||
|
||
let discover () = | ||
Utils.exec_cmd | ||
(module Process.D) | ||
~cmdstring:(ipmitool ["discover"]) | ||
~f:(fun line -> | ||
D.debug "DCMI discover: %s" line ; | ||
if String.trim line = "Power management available" then | ||
Some true | ||
else | ||
None | ||
) | ||
|
||
let ( let+ ) x f = Option.map f x | ||
|
||
let ( let* ) = Option.bind | ||
|
||
let get_dcmi_power_reading () = | ||
Utils.exec_cmd | ||
(module Process.D) | ||
~cmdstring:(ipmitool ["power"; "reading"]) | ||
~f:(fun line -> | ||
let* k, v = line |> Astring.String.cut ~sep:":" in | ||
let k = String.trim k and v = String.trim v in | ||
if k = "Instantaneous power reading" then | ||
let* watts, units = Astring.String.cut ~sep:" " v in | ||
if units = "Watts" then | ||
Some (Int64.of_string watts) | ||
else | ||
None | ||
else | ||
None | ||
) | ||
|
||
let gen_dcmi_power_reading value = | ||
( Rrd.Host | ||
, Ds.ds_make ~name:"DCMI-power-reading" | ||
~description:"Host power usage reported by IPMI DCMI" | ||
~value:(Rrd.VT_Int64 value) ~ty:Rrd.Gauge ~default:true ~units:"W" ~min:0. | ||
() | ||
) | ||
|
||
let generate_dss () = | ||
match get_dcmi_power_reading () with | ||
| watts :: _ -> | ||
[gen_dcmi_power_reading watts] | ||
| _ -> | ||
[] | ||
|
||
let _ = | ||
initialise () ; | ||
match discover () with | ||
| [] -> | ||
exit 1 | ||
| _ -> | ||
main_loop ~neg_shift:0.5 ~target:(Reporter.Local 1) | ||
~protocol:Rrd_interface.V2 ~dss_f:generate_dss |
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 +1 @@ | ||
PLUGINS="xcp-rrdd-iostat xcp-rrdd-squeezed xcp-rrdd-xenpm" | ||
PLUGINS="xcp-rrdd-iostat xcp-rrdd-squeezed xcp-rrdd-xenpm xcp-rrdd-dcmi" |