Skip to content

Commit

Permalink
Add energy metrics to load-watcher (#73)
Browse files Browse the repository at this point in the history
* Add energy metrics to load-watcher

* switch case in promResults2MetricMap()

---------

Co-authored-by: jose <jose.pedro.pereira.dos.santos@partner.ibm.com>
  • Loading branch information
jpedro1992 and jose authored Nov 12, 2024
1 parent d60c902 commit 500faea
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
64 changes: 44 additions & 20 deletions pkg/watcher/internal/metricsprovider/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,30 @@ import (
)

const (
EnableOpenShiftAuth = "ENABLE_OPENSHIFT_AUTH"
K8sPodCAFilePath = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
DefaultPromAddress = "http://prometheus-k8s:9090"
promStd = "stddev_over_time"
promAvg = "avg_over_time"
promCpuMetric = "instance:node_cpu:ratio"
promMemMetric = "instance:node_memory_utilisation:ratio"
promTransBandMetric = "instance:node_network_transmit_bytes:rate:sum"
promTransBandDropMetric = "instance:node_network_transmit_drop_excluding_lo:rate5m"
promRecBandMetric = "instance:node_network_receive_bytes:rate:sum"
promRecBandDropMetric = "instance:node_network_receive_drop_excluding_lo:rate5m"
promDiskIOMetric = "instance_device:node_disk_io_time_seconds:rate5m"
allHosts = "all"
hostMetricKey = "instance"
EnableOpenShiftAuth = "ENABLE_OPENSHIFT_AUTH"
K8sPodCAFilePath = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
DefaultPromAddress = "http://prometheus-k8s:9090"
promStd = "stddev_over_time"
promAvg = "avg_over_time"
promCpuMetric = "instance:node_cpu:ratio"
promMemMetric = "instance:node_memory_utilisation:ratio"
promTransBandMetric = "instance:node_network_transmit_bytes:rate:sum"
promTransBandDropMetric = "instance:node_network_transmit_drop_excluding_lo:rate5m"
promRecBandMetric = "instance:node_network_receive_bytes:rate:sum"
promRecBandDropMetric = "instance:node_network_receive_drop_excluding_lo:rate5m"
promDiskIOMetric = "instance_device:node_disk_io_time_seconds:rate5m"
promScaphHostPower = "scaph_host_power_microwatts"
promScaphHostJoules = "scaph_host_energy_microjoules"
promKeplerHostCoreJoules = "kepler_node_core_joules_total"
promKeplerHostUncoreJoules = "kepler_node_uncore_joules_total"
promKeplerHostDRAMJoules = "kepler_node_dram_joules_total"
promKeplerHostPackageJoules = "kepler_node_package_joules_total"
promKeplerHostOtherJoules = "kepler_node_other_joules_total"
promKeplerHostGPUJoules = "kepler_node_gpu_joules_total"
promKeplerHostPlatformJoules = "kepler_node_platform_joules_total"
promKeplerHostEnergyStat = "kepler_node_energy_stat"
allHosts = "all"
hostMetricKey = "instance"
)

type promClient struct {
Expand Down Expand Up @@ -159,7 +169,9 @@ func (s promClient) FetchHostMetrics(host string, window *watcher.Window) ([]wat
var anyerr error

for _, method := range []string{promAvg, promStd} {
for _, metric := range []string{promCpuMetric, promMemMetric, promTransBandMetric, promTransBandDropMetric, promRecBandMetric, promRecBandDropMetric, promDiskIOMetric} {
for _, metric := range []string{promCpuMetric, promMemMetric, promTransBandMetric, promTransBandDropMetric, promRecBandMetric, promRecBandDropMetric,
promDiskIOMetric, promScaphHostPower, promScaphHostJoules, promKeplerHostCoreJoules, promKeplerHostUncoreJoules, promKeplerHostDRAMJoules,
promKeplerHostPackageJoules, promKeplerHostOtherJoules, promKeplerHostGPUJoules, promKeplerHostPlatformJoules, promKeplerHostEnergyStat} {
promQuery := s.buildPromQuery(host, metric, method, window.Duration)
promResults, err := s.getPromResults(promQuery)

Expand All @@ -183,7 +195,9 @@ func (s promClient) FetchAllHostsMetrics(window *watcher.Window) (map[string][]w
var anyerr error

for _, method := range []string{promAvg, promStd} {
for _, metric := range []string{promCpuMetric, promMemMetric, promTransBandMetric, promTransBandDropMetric, promRecBandMetric, promRecBandDropMetric, promDiskIOMetric} {
for _, metric := range []string{promCpuMetric, promMemMetric, promTransBandMetric, promTransBandDropMetric, promRecBandMetric, promRecBandDropMetric,
promDiskIOMetric, promScaphHostPower, promScaphHostJoules, promKeplerHostCoreJoules, promKeplerHostUncoreJoules, promKeplerHostDRAMJoules,
promKeplerHostPackageJoules, promKeplerHostOtherJoules, promKeplerHostGPUJoules, promKeplerHostPlatformJoules, promKeplerHostEnergyStat} {
promQuery := s.buildPromQuery(allHosts, metric, method, window.Duration)
promResults, err := s.getPromResults(promQuery)

Expand Down Expand Up @@ -254,14 +268,24 @@ func (s promClient) promResults2MetricMap(promresults model.Value, metric string

curMetrics := make(map[string][]watcher.Metric)

if metric == promCpuMetric {
switch metric {
case promCpuMetric: // CPU metrics
metricType = watcher.CPU
} else if metric == promMemMetric {
case promMemMetric: // Memory metrics
metricType = watcher.Memory
} else if metric == promDiskIOMetric {
case promDiskIOMetric: // Storage metrics
metricType = watcher.Storage
} else {
case promScaphHostPower, promScaphHostJoules, // Energy-related metrics
promKeplerHostCoreJoules, promKeplerHostUncoreJoules,
promKeplerHostDRAMJoules, promKeplerHostPackageJoules,
promKeplerHostOtherJoules, promKeplerHostGPUJoules,
promKeplerHostPlatformJoules, promKeplerHostEnergyStat:
metricType = watcher.Energy
case promTransBandMetric, promTransBandDropMetric, // Bandwidth-related metrics
promRecBandMetric, promRecBandDropMetric:
metricType = watcher.Bandwidth
default:
metricType = watcher.Unknown
}

if method == promAvg {
Expand Down
8 changes: 5 additions & 3 deletions pkg/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ limitations under the License.
*/

/*
Package Watcher is responsible for watching latest metrics from metrics provider via a fetcher client.
It exposes an HTTP REST endpoint to get these metrics, in addition to application API via clients
This also uses a fast json parser
Package Watcher is responsible for watching latest metrics from metrics provider via a fetcher client.
It exposes an HTTP REST endpoint to get these metrics, in addition to application API via clients
This also uses a fast json parser
*/
package watcher

Expand Down Expand Up @@ -45,6 +45,8 @@ const (
Memory = "Memory"
Bandwidth = "Bandwidth"
Storage = "Storage"
Energy = "Energy"
Unknown = "Unknown"
Average = "AVG"
Std = "STD"
Latest = "Latest"
Expand Down

0 comments on commit 500faea

Please sign in to comment.