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 energy metrics to load-watcher #73

Merged
merged 2 commits into from
Nov 12, 2024
Merged
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
64 changes: 44 additions & 20 deletions pkg/watcher/internal/metricsprovider/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,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 @@ -158,7 +168,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 @@ -182,7 +194,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 @@ -253,14 +267,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
Loading