Skip to content

Cloud‐Toolkit

keilhofh edited this page Oct 24, 2024 · 7 revisions

jPowerMonitor cannot read out the power consumption, e.g. of the CPU or the entire system, itself, but is dependent on a measurement backend with a REST or CSV interface.

This is not a problem on physical computers, as tools such as LibreHardwareMonitor are available under Windows or Running Average Power Limit(RAPL) under Linux. The Cloud Toolkit extension for jPowerMonitor aims to improve the transparency of energy consumption in the cloud.

CPU power consumption estimation

Based on internally determined CPU utilization data, the jPowerMonitor Cloud-Toolkit provides a relatively accurate estimate of CPU power consumption, even in virtualized environments. The methodology follows the principles of Cloud Carbon Footprint.

In the jPowerMonitor configuration, an additional measurement method “est” (short for “estimation”, alongside “lhm” for LibreHardwareMonitor and “csv” for the generic CSV interface) has now been introduced (from version >= 1.2.0).

The “est” measurement method only requires two additional input parameters:

  • cpuMinWatts: minimum power consumption of the CPU (“idle” consumption)
  • cpuMaxWatts: maximum power consumption of the CPU (under full load)

On local systems, both values can be determined in advance using LibreHardwareMonitor or another measurement tool. If necessary, the CPU manufacturer's specifications from the data sheet can be used instead, e.g. “Idle” consumption and TDP (Thermal Design Power).

If it is possible to obtain real “live” measurement data, this is of course always more accurate and therefore preferable.

There are various tables on the internet for cloud platforms, from which the values for different VM instance types, for example, can be read (see e.g. cloud-carbon-coefficients/data or re-cinq). The current average values for AWS (Amazon Web Services) EC2 are already preconfigured in the jpowermonitor.yaml template. For a CO2eq consumption that is automatically and correctly converted by jPowerMonitor from the energy estimate data, the electricity mix (“carbonDioxideEmissionFactor”, see 9) at the location of the cloud data center must also be specified. A detailed description of the configuration can be found in the README.md file.

Prometheus interface

Configuration

Since version 1.2.0 of the jPowerMonitor Java agent, users can publish power and energy values as well as the calculated CO2 consumption of applications via a Prometheus interface.

To avoid sending too many values, only the values for the filtered methods are currently sent to Prometheus. If, for example, the measurement data for internal Java or Spring Boot methods is to be included, the corresponding namespaces (e.g. “java.lang”, “org.springframework”) must be added to the filter configuration.

In the configuration of the jPowerMonitor Java agent, there is now a “monitoring” section with the currently only specification “prometheus”. Here the writing of the filtered values to the Prometheus interface can be switched on (“enabled” flag), and the http port (“httpPort” setting) on which the data is published to Prometheus can be set. You can also define an interval in seconds after which the energy values are written to Prometheus again (“writeEnergyIntervalInS”) and specify whether you also want to publish the general JVM metrics (“publishJvmMetrics”). These contain information about the Java Virtual Machine used, the garbage collector, loaded classes and main memory consumption.

Provided metrics

The Prometheus interface offers the following metrics:

  • jPowerMonitor_power_per_method_filtered: Current values per method (W)
  • jPowerMonitor_energy_per_method_filtered: Energy values per method (J)
  • jPowerMonitor_co2_per_method_filtered: CO2 values per method (gCO2eq)

All published values contain the following attributes:

  • pid - the process Id of the application being measured
  • thread - the thread id of the thread in which the current method is running
  • method - the method that is being measured
  • job - fixed to “jPowerMonitor”

Grafana dashboard

The metrics can be visualized with the help of Grafana. For example, the following PromQL (Prometheus Query Language) expression can be used to determine the top 5 most energy-hungry methods and display them in a bar chart in Grafana, for example: topk(5, sort_desc(sum by(method) (jPowerMonitor_energy_per_method_filtered{job=~“jPowerMonitor”})))

All the metrics and their attributes listed above can be accessed via PromQL. Grafana already offers a range of preconfigured dashboards for the JMX exporter to visualize the JVM standard metrics.

See e.g. Example for a Grafana JVM standard metrics-Dashboard