From 3a210d22219bebba29eebb8d462640bd9d284101 Mon Sep 17 00:00:00 2001 From: Jose Pedro Pereira dos Santos Date: Fri, 17 Mar 2023 16:12:29 +0100 Subject: [PATCH] addition of bandwidth and storage metrics (#59) Co-authored-by: Abdul Qadeer --- .../internal/metricsprovider/prometheus.go | 33 ++++++++++++------- pkg/watcher/watcher.go | 2 ++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pkg/watcher/internal/metricsprovider/prometheus.go b/pkg/watcher/internal/metricsprovider/prometheus.go index 712aa2c..87800cc 100644 --- a/pkg/watcher/internal/metricsprovider/prometheus.go +++ b/pkg/watcher/internal/metricsprovider/prometheus.go @@ -43,15 +43,20 @@ import ( ) const ( - EnableOpenShiftAuth = "ENABLE_OPENSHIFT_AUTH" - DefaultPromAddress = "http://prometheus-k8s:9090" - promStd = "stddev_over_time" - promAvg = "avg_over_time" - promCpuMetric = "instance:node_cpu:ratio" - promMemMetric = "instance:node_memory_utilisation:ratio" - allHosts = "all" - hostMetricKey = "instance" - defaultKubeConfig = "~/.kube/config" + EnableOpenShiftAuth = "ENABLE_OPENSHIFT_AUTH" + 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" + defaultKubeConfig = "~/.kube/config" ) type promClient struct { @@ -167,7 +172,7 @@ 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} { + for _, metric := range []string{promCpuMetric, promMemMetric, promTransBandMetric, promTransBandDropMetric, promRecBandMetric, promRecBandDropMetric, promDiskIOMetric} { promQuery := s.buildPromQuery(host, metric, method, window.Duration) promResults, err := s.getPromResults(promQuery) @@ -191,7 +196,7 @@ 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} { + for _, metric := range []string{promCpuMetric, promMemMetric, promTransBandMetric, promTransBandDropMetric, promRecBandMetric, promRecBandDropMetric, promDiskIOMetric} { promQuery := s.buildPromQuery(allHosts, metric, method, window.Duration) promResults, err := s.getPromResults(promQuery) @@ -264,8 +269,12 @@ func (s promClient) promResults2MetricMap(promresults model.Value, metric string if metric == promCpuMetric { metricType = watcher.CPU - } else { + } else if metric == promMemMetric { metricType = watcher.Memory + } else if metric == promDiskIOMetric { + metricType = watcher.Storage + } else { + metricType = watcher.Bandwidth } if method == promAvg { diff --git a/pkg/watcher/watcher.go b/pkg/watcher/watcher.go index a5253b5..7985f68 100644 --- a/pkg/watcher/watcher.go +++ b/pkg/watcher/watcher.go @@ -43,6 +43,8 @@ const ( FiveMinutes = "5m" CPU = "CPU" Memory = "Memory" + Bandwidth = "Bandwidth" + Storage = "Storage" Average = "AVG" Std = "STD" Latest = "Latest"