From 9a31f8b508ef5a9f3286abf808b714f001ee9071 Mon Sep 17 00:00:00 2001 From: Joe Talerico aka rook Date: Wed, 23 Oct 2024 17:50:42 -0400 Subject: [PATCH 1/5] Adding podMem Adding the podMem similar to the podCPU to our csv/result data Signed-off-by: Joe Talerico aka rook --- cmd/k8s-netperf/k8s-netperf.go | 3 +++ pkg/archive/archive.go | 29 ++++++++++++++++++++++++++--- pkg/metrics/system.go | 29 ++++++++++++++++++++++++++++- pkg/results/result.go | 16 ++++++++++++++++ 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/cmd/k8s-netperf/k8s-netperf.go b/cmd/k8s-netperf/k8s-netperf.go index 44fcbeb..379926f 100644 --- a/cmd/k8s-netperf/k8s-netperf.go +++ b/cmd/k8s-netperf/k8s-netperf.go @@ -259,6 +259,8 @@ var rootCmd = &cobra.Command{ sr.Results[i].ServerMetrics, _ = metrics.QueryNodeCPU(npr.ServerNodeInfo, pcon, npr.StartTime, npr.EndTime) sr.Results[i].ClientPodCPU, _ = metrics.TopPodCPU(npr.ClientNodeInfo, pcon, npr.StartTime, npr.EndTime) sr.Results[i].ServerPodCPU, _ = metrics.TopPodCPU(npr.ServerNodeInfo, pcon, npr.StartTime, npr.EndTime) + sr.Results[i].ClientPodMem, _ = metrics.TopPodMem(npr.ClientNodeInfo, pcon, npr.StartTime, npr.EndTime) + sr.Results[i].ServerPodMem, _ = metrics.TopPodMem(npr.ServerNodeInfo, pcon, npr.StartTime, npr.EndTime) } } } @@ -319,6 +321,7 @@ var rootCmd = &cobra.Command{ if showMetrics { result.ShowNodeCPU(sr) result.ShowPodCPU(sr) + result.ShowPodMem(sr) } } else { err = archive.WriteJSONResult(sr) diff --git a/pkg/archive/archive.go b/pkg/archive/archive.go index 4fc19d2..d575ecb 100644 --- a/pkg/archive/archive.go +++ b/pkg/archive/archive.go @@ -44,8 +44,10 @@ type Doc struct { Metadata result.Metadata `json:"metadata"` ServerNodeCPU metrics.NodeCPU `json:"serverCPU"` ServerPodCPU []metrics.PodCPU `json:"serverPods"` + ServerPodMem []metrics.PodMem `json:"serverPodsMem"` ClientNodeCPU metrics.NodeCPU `json:"clientCPU"` ClientPodCPU []metrics.PodCPU `json:"clientPods"` + ClientPodMem []metrics.PodMem `json:"clientPodsMem"` Confidence []float64 `json:"confidence"` ServerNodeInfo metrics.NodeInfo `json:"serverNodeInfo"` ClientNodeInfo metrics.NodeInfo `json:"clientNodeInfo"` @@ -108,6 +110,8 @@ func BuildDocs(sr result.ScenarioResults, uuid string) ([]interface{}, error) { ServerNodeCPU: r.ServerMetrics, ClientNodeCPU: r.ClientMetrics, ServerPodCPU: r.ServerPodCPU.Results, + ServerPodMem: r.ServerPodMem.MemResults, + ClientPodMem: r.ClientPodMem.MemResults, ClientPodCPU: r.ClientPodCPU.Results, Metadata: sr.Metadata, AcrossAZ: r.AcrossAZ, @@ -189,7 +193,7 @@ func commonCsvDataFields(row result.Data) []string { } // Writes all the mertics to the archive. -func writeArchive(cpuarchive, podarchive *csv.Writer, role string, row result.Data, podResults []metrics.PodCPU) error { +func writeArchive(cpuarchive, podarchive, podmemarchive *csv.Writer, role string, row result.Data, podResults []metrics.PodCPU, podMem []metrics.PodMem) error { roleFieldData := []string{role} for _, pod := range podResults { if err := podarchive.Write(append(append(roleFieldData, @@ -200,6 +204,15 @@ func writeArchive(cpuarchive, podarchive *csv.Writer, role string, row result.Da return fmt.Errorf("failed to write archive to file") } } + for _, pod := range podMem { + if err := podmemarchive.Write(append(append(roleFieldData, + commonCsvDataFields(row)...), + pod.Name, + fmt.Sprintf("%f", pod.Value), + )); err != nil { + return fmt.Errorf("failed to write archive to file") + } + } cpu := row.ClientMetrics if role == "Server" { @@ -223,6 +236,12 @@ func writeArchive(cpuarchive, podarchive *csv.Writer, role string, row result.Da // WritePromCSVResult writes the prom data in CSV format func WritePromCSVResult(r result.ScenarioResults) error { d := time.Now().Unix() + + podmemfp, err := os.Create(fmt.Sprintf("podmem-result-%d.csv", d)) + if err != nil { + return fmt.Errorf("failed to open pod mem archive file") + } + defer podmemfp.Close() podfp, err := os.Create(fmt.Sprintf("podcpu-result-%d.csv", d)) if err != nil { return fmt.Errorf("failed to open pod cpu archive file") @@ -237,6 +256,9 @@ func WritePromCSVResult(r result.ScenarioResults) error { defer cpuarchive.Flush() podarchive := csv.NewWriter(podfp) defer podarchive.Flush() + + podmemarchive := csv.NewWriter(podmemfp) + defer podmemarchive.Flush() roleField := []string{"Role"} cpudata := append(append(roleField, commonCsvHeaderFields()...), @@ -260,13 +282,14 @@ func WritePromCSVResult(r result.ScenarioResults) error { return fmt.Errorf("failed to write pod archive to file") } for _, row := range r.Results { - if err := writeArchive(cpuarchive, podarchive, "Client", row, row.ClientPodCPU.Results); err != nil { + if err := writeArchive(cpuarchive, podarchive, podmemarchive, "Client", row, row.ClientPodCPU.Results, row.ClientPodMem.MemResults); err != nil { return err } - if err := writeArchive(cpuarchive, podarchive, "Server", row, row.ServerPodCPU.Results); err != nil { + if err := writeArchive(cpuarchive, podarchive, podmemarchive, "Server", row, row.ServerPodCPU.Results, row.ServerPodMem.MemResults); err != nil { return err } } + return nil } diff --git a/pkg/metrics/system.go b/pkg/metrics/system.go index 5c9cda6..f2cb59c 100644 --- a/pkg/metrics/system.go +++ b/pkg/metrics/system.go @@ -40,9 +40,15 @@ type PodCPU struct { Value float64 `json:"cpuUsage"` } +type PodMem struct { + Name string `json:"podName"` + Value float64 `json:"memUsage"` +} + // PodValues is a collection of PodCPU type PodValues struct { - Results []PodCPU + Results []PodCPU + MemResults []PodMem } // PromConnect stores the prom information @@ -187,6 +193,27 @@ func TopPodCPU(node NodeInfo, conn PromConnect, start time.Time, end time.Time) return pods, true } +// TopPodMem will return the top 5 Mem consumers for a specific node +func TopPodMem(node NodeInfo, conn PromConnect, start time.Time, end time.Time) (PodValues, bool) { + var pods PodValues + query := fmt.Sprintf("topk(5,container_memory_rss{container!=\"POD\",name!=\"\",node=~\"%s\"})", node.NodeName) + logging.Debugf("Prom Query : %s", query) + val, err := conn.Client.QueryRange(query, start, end, time.Minute) + if err != nil { + logging.Error("Issue querying Prometheus") + return pods, false + } + v := val.(model.Matrix) + for _, s := range v { + p := PodMem{ + Name: string(s.Metric["pod"]), + Value: avg(s.Values), + } + pods.MemResults = append(pods.MemResults, p) + } + return pods, true +} + // Calculates average for the given data func avg(data []model.SamplePair) float64 { sum := 0.0 diff --git a/pkg/results/result.go b/pkg/results/result.go index 6b701ef..b2a7646 100644 --- a/pkg/results/result.go +++ b/pkg/results/result.go @@ -43,7 +43,9 @@ type Data struct { ClientMetrics metrics.NodeCPU ServerMetrics metrics.NodeCPU ClientPodCPU metrics.PodValues + ClientPodMem metrics.PodValues ServerPodCPU metrics.PodValues + ServerPodMem metrics.PodValues } // ScenarioResults each scenario could have multiple results @@ -201,6 +203,20 @@ func ShowPodCPU(s ScenarioResults) { table.Render() } +// ShowPodMem accepts ScenarioResults and presents to the user via stdout the Podmem info +func ShowPodMem(s ScenarioResults) { + table := initTable([]string{"Result Type", "Driver", "Role", "Scenario", "Parallelism", "Host Network", "Service", "Message Size", "Burst", "Same node", "Pod", "Utilization"}) + for _, r := range s.Results { + for _, pod := range r.ClientPodMem.MemResults { + table.Append([]string{"Pod Mem RSS Utilization", r.Driver, "Client", r.Profile, fmt.Sprintf("%d", r.Parallelism), fmt.Sprintf("%t", r.HostNetwork), fmt.Sprintf("%t", r.Service), fmt.Sprintf("%d", r.MessageSize), fmt.Sprintf("%d", r.Burst), fmt.Sprintf("%t", r.SameNode), fmt.Sprintf("%.20s", pod.Name), fmt.Sprintf("%f", pod.Value)}) + } + for _, pod := range r.ServerPodMem.MemResults { + table.Append([]string{"Pod Mem RSS Utilization", r.Driver, "Server", r.Profile, fmt.Sprintf("%d", r.Parallelism), fmt.Sprintf("%t", r.HostNetwork), fmt.Sprintf("%t", r.Service), fmt.Sprintf("%d", r.MessageSize), fmt.Sprintf("%d", r.Burst), fmt.Sprintf("%t", r.SameNode), fmt.Sprintf("%.20s", pod.Name), fmt.Sprintf("%f", pod.Value)}) + } + } + table.Render() +} + // ShowNodeCPU accepts ScenarioResults and presents to the user via stdout the NodeCPU info func ShowNodeCPU(s ScenarioResults) { table := initTable([]string{"Result Type", "Driver", "Role", "Scenario", "Parallelism", "Host Network", "Service", "Message Size", "Burst", "Same node", "Idle CPU", "User CPU", "System CPU", "Steal CPU", "IOWait CPU", "Nice CPU", "SoftIRQ CPU", "IRQ CPU"}) From 9f12223dcb4e0ef30f0054d49742b1727424c2ba Mon Sep 17 00:00:00 2001 From: Joe Talerico aka rook Date: Thu, 24 Oct 2024 14:25:30 -0400 Subject: [PATCH 2/5] Fixing mem query, adding vswitchd Signed-off-by: Joe Talerico aka rook --- pkg/metrics/system.go | 52 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/pkg/metrics/system.go b/pkg/metrics/system.go index f2cb59c..e0a8681 100644 --- a/pkg/metrics/system.go +++ b/pkg/metrics/system.go @@ -24,14 +24,16 @@ type NodeInfo struct { // NodeCPU stores CPU information for a specific Node type NodeCPU struct { - Idle float64 `json:"idleCPU"` - User float64 `json:"userCPU"` - Steal float64 `json:"stealCPU"` - System float64 `json:"systemCPU"` - Nice float64 `json:"niceCPU"` - Irq float64 `json:"irqCPU"` - Softirq float64 `json:"softCPU"` - Iowait float64 `json:"ioCPU"` + Idle float64 `json:"idleCPU"` + User float64 `json:"userCPU"` + Steal float64 `json:"stealCPU"` + System float64 `json:"systemCPU"` + Nice float64 `json:"niceCPU"` + Irq float64 `json:"irqCPU"` + Softirq float64 `json:"softCPU"` + Iowait float64 `json:"ioCPU"` + VSwitchCPU float64 `json:"vSwitchCPU"` + VSwitchMem float64 `json:"vSwitchMem"` } // PodCPU stores pod CPU @@ -193,10 +195,42 @@ func TopPodCPU(node NodeInfo, conn PromConnect, start time.Time, end time.Time) return pods, true } +// VSwitchCPU will return the vswitchd cpu usage for specific node +func VSwitchCPU(node NodeInfo, conn PromConnect, start time.Time, end time.Time, ndata *NodeCPU) bool { + query := fmt.Sprintf("irate(container_cpu_usage_seconds_total{id=~\"/system.slice/ovs-vswitchd.service\", node=~\"%s\"}[2m])*100", node.NodeName) + logging.Debugf("Prom Query : %s", query) + val, err := conn.Client.QueryRange(query, start, end, time.Minute) + if err != nil { + logging.Error("Issue querying Prometheus") + return false + } + v := val.(model.Matrix) + for _, s := range v { + ndata.VSwitchCPU = avg(s.Values) + } + return true +} + +// VSwitchMem will return the vswitchd cpu usage for specific node +func VSwitchMem(node NodeInfo, conn PromConnect, start time.Time, end time.Time, ndata *NodeCPU) bool { + query := fmt.Sprintf("container_memory_rss{id=~\"/system.slice/ovs-vswitchd.service\", node=~\"%s\"}", node.NodeName) + logging.Debugf("Prom Query : %s", query) + val, err := conn.Client.QueryRange(query, start, end, time.Minute) + if err != nil { + logging.Error("Issue querying Prometheus") + return false + } + v := val.(model.Matrix) + for _, s := range v { + ndata.VSwitchMem = avg(s.Values) + } + return true +} + // TopPodMem will return the top 5 Mem consumers for a specific node func TopPodMem(node NodeInfo, conn PromConnect, start time.Time, end time.Time) (PodValues, bool) { var pods PodValues - query := fmt.Sprintf("topk(5,container_memory_rss{container!=\"POD\",name!=\"\",node=~\"%s\"})", node.NodeName) + query := fmt.Sprintf("topk(5,sum(container_memory_rss{container!=\"POD\",name!=\"\",node=~\"%s\"}) by (pod, namespace, node))", node.NodeName) logging.Debugf("Prom Query : %s", query) val, err := conn.Client.QueryRange(query, start, end, time.Minute) if err != nil { From eada10562a15a85446a6fa3e79266cb4194a0820 Mon Sep 17 00:00:00 2001 From: Joe Talerico aka rook Date: Fri, 15 Nov 2024 12:28:50 -0500 Subject: [PATCH 3/5] Adding vswitch data Signed-off-by: Joe Talerico aka rook --- cmd/k8s-netperf/k8s-netperf.go | 4 + pkg/archive/archive.go | 158 ++++++++++++++++++++------------- pkg/metrics/system.go | 4 +- 3 files changed, 101 insertions(+), 65 deletions(-) diff --git a/cmd/k8s-netperf/k8s-netperf.go b/cmd/k8s-netperf/k8s-netperf.go index 379926f..84789a3 100644 --- a/cmd/k8s-netperf/k8s-netperf.go +++ b/cmd/k8s-netperf/k8s-netperf.go @@ -257,6 +257,10 @@ var rootCmd = &cobra.Command{ if len(npr.ClientNodeInfo.NodeName) > 0 && len(npr.ServerNodeInfo.NodeName) > 0 { sr.Results[i].ClientMetrics, _ = metrics.QueryNodeCPU(npr.ClientNodeInfo, pcon, npr.StartTime, npr.EndTime) sr.Results[i].ServerMetrics, _ = metrics.QueryNodeCPU(npr.ServerNodeInfo, pcon, npr.StartTime, npr.EndTime) + metrics.VSwitchCPU(npr.ClientNodeInfo, pcon, npr.StartTime, npr.EndTime, &sr.Results[i].ClientMetrics) + metrics.VSwitchMem(npr.ClientNodeInfo, pcon, npr.StartTime, npr.EndTime, &sr.Results[i].ClientMetrics) + metrics.VSwitchCPU(npr.ServerNodeInfo, pcon, npr.StartTime, npr.EndTime, &sr.Results[i].ServerMetrics) + metrics.VSwitchMem(npr.ServerNodeInfo, pcon, npr.StartTime, npr.EndTime, &sr.Results[i].ServerMetrics) sr.Results[i].ClientPodCPU, _ = metrics.TopPodCPU(npr.ClientNodeInfo, pcon, npr.StartTime, npr.EndTime) sr.Results[i].ServerPodCPU, _ = metrics.TopPodCPU(npr.ServerNodeInfo, pcon, npr.StartTime, npr.EndTime) sr.Results[i].ClientPodMem, _ = metrics.TopPodMem(npr.ClientNodeInfo, pcon, npr.StartTime, npr.EndTime) diff --git a/pkg/archive/archive.go b/pkg/archive/archive.go index d575ecb..ac88b68 100644 --- a/pkg/archive/archive.go +++ b/pkg/archive/archive.go @@ -19,38 +19,42 @@ const ltcyMetric = "usec" // Doc struct of the JSON document to be indexed type Doc struct { - UUID string `json:"uuid"` - Timestamp time.Time `json:"timestamp"` - HostNetwork bool `json:"hostNetwork"` - Driver string `json:"driver"` - Parallelism int `json:"parallelism"` - Profile string `json:"profile"` - Duration int `json:"duration"` - Service bool `json:"service"` - Local bool `json:"local"` - Virt bool `json:"virt"` - AcrossAZ bool `json:"acrossAZ"` - Samples int `json:"samples"` - Messagesize int `json:"messageSize"` - Burst int `json:"burst"` - Throughput float64 `json:"throughput"` - Latency float64 `json:"latency"` - TputMetric string `json:"tputMetric"` - LtcyMetric string `json:"ltcyMetric"` - TCPRetransmit float64 `json:"tcpRetransmits"` - UDPLossPercent float64 `json:"udpLossPercent"` - ToolVersion string `json:"toolVersion"` - ToolGitCommit string `json:"toolGitCommit"` - Metadata result.Metadata `json:"metadata"` - ServerNodeCPU metrics.NodeCPU `json:"serverCPU"` - ServerPodCPU []metrics.PodCPU `json:"serverPods"` - ServerPodMem []metrics.PodMem `json:"serverPodsMem"` - ClientNodeCPU metrics.NodeCPU `json:"clientCPU"` - ClientPodCPU []metrics.PodCPU `json:"clientPods"` - ClientPodMem []metrics.PodMem `json:"clientPodsMem"` - Confidence []float64 `json:"confidence"` - ServerNodeInfo metrics.NodeInfo `json:"serverNodeInfo"` - ClientNodeInfo metrics.NodeInfo `json:"clientNodeInfo"` + UUID string `json:"uuid"` + Timestamp time.Time `json:"timestamp"` + HostNetwork bool `json:"hostNetwork"` + Driver string `json:"driver"` + Parallelism int `json:"parallelism"` + Profile string `json:"profile"` + Duration int `json:"duration"` + Service bool `json:"service"` + Local bool `json:"local"` + Virt bool `json:"virt"` + AcrossAZ bool `json:"acrossAZ"` + Samples int `json:"samples"` + Messagesize int `json:"messageSize"` + Burst int `json:"burst"` + Throughput float64 `json:"throughput"` + Latency float64 `json:"latency"` + TputMetric string `json:"tputMetric"` + LtcyMetric string `json:"ltcyMetric"` + TCPRetransmit float64 `json:"tcpRetransmits"` + UDPLossPercent float64 `json:"udpLossPercent"` + ToolVersion string `json:"toolVersion"` + ToolGitCommit string `json:"toolGitCommit"` + Metadata result.Metadata `json:"metadata"` + ServerNodeCPU metrics.NodeCPU `json:"serverCPU"` + ServerPodCPU []metrics.PodCPU `json:"serverPods"` + ServerPodMem []metrics.PodMem `json:"serverPodsMem"` + ClientNodeCPU metrics.NodeCPU `json:"clientCPU"` + ClientPodCPU []metrics.PodCPU `json:"clientPods"` + ClientPodMem []metrics.PodMem `json:"clientPodsMem"` + Confidence []float64 `json:"confidence"` + ServerNodeInfo metrics.NodeInfo `json:"serverNodeInfo"` + ClientNodeInfo metrics.NodeInfo `json:"clientNodeInfo"` + ServerVSwitchCpu float64 `json:"serverVswtichCpu"` + ServerVSwitchMem float64 `json:"serverVswitchMem"` + ClientVSwitchCpu float64 `json:"clientVswtichCpu"` + ClientVSwiitchMem float64 `json:"clientVswitchMem"` } // Connect returns a client connected to the desired cluster. @@ -91,33 +95,37 @@ func BuildDocs(sr result.ScenarioResults, uuid string) ([]interface{}, error) { } c := []float64{lo, hi} d := Doc{ - UUID: uuid, - Timestamp: time, - ToolVersion: sr.Version, - ToolGitCommit: sr.GitCommit, - Driver: r.Driver, - HostNetwork: r.HostNetwork, - Parallelism: r.Parallelism, - Profile: r.Profile, - Duration: r.Duration, - Virt: sr.Virt, - Samples: r.Samples, - Service: r.Service, - Messagesize: r.MessageSize, - Burst: r.Burst, - TputMetric: r.Metric, - LtcyMetric: ltcyMetric, - ServerNodeCPU: r.ServerMetrics, - ClientNodeCPU: r.ClientMetrics, - ServerPodCPU: r.ServerPodCPU.Results, - ServerPodMem: r.ServerPodMem.MemResults, - ClientPodMem: r.ClientPodMem.MemResults, - ClientPodCPU: r.ClientPodCPU.Results, - Metadata: sr.Metadata, - AcrossAZ: r.AcrossAZ, - Confidence: c, - ClientNodeInfo: r.ClientNodeInfo, - ServerNodeInfo: r.ServerNodeInfo, + UUID: uuid, + Timestamp: time, + ToolVersion: sr.Version, + ToolGitCommit: sr.GitCommit, + Driver: r.Driver, + HostNetwork: r.HostNetwork, + Parallelism: r.Parallelism, + Profile: r.Profile, + Duration: r.Duration, + Virt: sr.Virt, + Samples: r.Samples, + Service: r.Service, + Messagesize: r.MessageSize, + Burst: r.Burst, + TputMetric: r.Metric, + LtcyMetric: ltcyMetric, + ServerNodeCPU: r.ServerMetrics, + ClientNodeCPU: r.ClientMetrics, + ServerPodCPU: r.ServerPodCPU.Results, + ServerPodMem: r.ServerPodMem.MemResults, + ClientPodMem: r.ClientPodMem.MemResults, + ClientPodCPU: r.ClientPodCPU.Results, + ClientVSwitchCpu: r.ClientMetrics.VSwitchCPU, + ClientVSwiitchMem: r.ClientMetrics.VSwitchMem, + ServerVSwitchCpu: r.ServerMetrics.VSwitchCPU, + ServerVSwitchMem: r.ServerMetrics.VSwitchMem, + Metadata: sr.Metadata, + AcrossAZ: r.AcrossAZ, + Confidence: c, + ClientNodeInfo: r.ClientNodeInfo, + ServerNodeInfo: r.ServerNodeInfo, } UDPLossPercent, e := result.Average(r.LossSummary) if e != nil { @@ -193,7 +201,7 @@ func commonCsvDataFields(row result.Data) []string { } // Writes all the mertics to the archive. -func writeArchive(cpuarchive, podarchive, podmemarchive *csv.Writer, role string, row result.Data, podResults []metrics.PodCPU, podMem []metrics.PodMem) error { +func writeArchive(vswitch, cpuarchive, podarchive, podmemarchive *csv.Writer, role string, row result.Data, podResults []metrics.PodCPU, podMem []metrics.PodMem) error { roleFieldData := []string{role} for _, pod := range podResults { if err := podarchive.Write(append(append(roleFieldData, @@ -218,6 +226,12 @@ func writeArchive(cpuarchive, podarchive, podmemarchive *csv.Writer, role string if role == "Server" { cpu = row.ServerMetrics } + if err := vswitch.Write(append(append(roleFieldData, + commonCsvDataFields(row)...), + fmt.Sprintf("%f", cpu.VSwitchCPU), + fmt.Sprintf("%f", cpu.VSwitchMem))); err != nil { + return fmt.Errorf("failed to write archive to file") + } if err := cpuarchive.Write(append(append(roleFieldData, commonCsvDataFields(row)...), fmt.Sprintf("%f", cpu.Idle), @@ -237,6 +251,11 @@ func writeArchive(cpuarchive, podarchive, podmemarchive *csv.Writer, role string func WritePromCSVResult(r result.ScenarioResults) error { d := time.Now().Unix() + vswitchfp, err := os.Create(fmt.Sprintf("vswitch-result-%d.csv", d)) + if err != nil { + return fmt.Errorf("failed to open vswitch archive file") + } + defer vswitchfp.Close() podmemfp, err := os.Create(fmt.Sprintf("podmem-result-%d.csv", d)) if err != nil { return fmt.Errorf("failed to open pod mem archive file") @@ -252,13 +271,15 @@ func WritePromCSVResult(r result.ScenarioResults) error { return fmt.Errorf("failed to open cpu archive file") } defer cpufp.Close() + vswitch := csv.NewWriter(vswitchfp) + defer vswitch.Flush() cpuarchive := csv.NewWriter(cpufp) defer cpuarchive.Flush() podarchive := csv.NewWriter(podfp) defer podarchive.Flush() - podmemarchive := csv.NewWriter(podmemfp) defer podmemarchive.Flush() + roleField := []string{"Role"} cpudata := append(append(roleField, commonCsvHeaderFields()...), @@ -275,17 +296,28 @@ func WritePromCSVResult(r result.ScenarioResults) error { "Pod Name", "Utilization", ) + vswtichdata := append(append(roleField, + commonCsvHeaderFields()...), + "CPU Utilization", + "Memory Utilization", + ) if err := cpuarchive.Write(cpudata); err != nil { return fmt.Errorf("failed to write cpu archive to file") } if err := podarchive.Write(poddata); err != nil { return fmt.Errorf("failed to write pod archive to file") } + if err := podmemarchive.Write(poddata); err != nil { + return fmt.Errorf("failed to write pod archive to file") + } + if err := vswitch.Write(vswtichdata); err != nil { + return fmt.Errorf("failed to write vswitch archive to file") + } for _, row := range r.Results { - if err := writeArchive(cpuarchive, podarchive, podmemarchive, "Client", row, row.ClientPodCPU.Results, row.ClientPodMem.MemResults); err != nil { + if err := writeArchive(vswitch, cpuarchive, podarchive, podmemarchive, "Client", row, row.ClientPodCPU.Results, row.ClientPodMem.MemResults); err != nil { return err } - if err := writeArchive(cpuarchive, podarchive, podmemarchive, "Server", row, row.ServerPodCPU.Results, row.ServerPodMem.MemResults); err != nil { + if err := writeArchive(vswitch, cpuarchive, podarchive, podmemarchive, "Server", row, row.ServerPodCPU.Results, row.ServerPodMem.MemResults); err != nil { return err } } diff --git a/pkg/metrics/system.go b/pkg/metrics/system.go index e0a8681..34ab9f4 100644 --- a/pkg/metrics/system.go +++ b/pkg/metrics/system.go @@ -177,7 +177,7 @@ func QueryNodeCPU(node NodeInfo, conn PromConnect, start time.Time, end time.Tim // TopPodCPU will return the top 5 CPU consumers for a specific node func TopPodCPU(node NodeInfo, conn PromConnect, start time.Time, end time.Time) (PodValues, bool) { var pods PodValues - query := fmt.Sprintf("topk(5,sum(irate(container_cpu_usage_seconds_total{name!=\"\",instance=~\"%s:.*\"}[2m]) * 100) by (pod, namespace, instance))", node.IP) + query := fmt.Sprintf("topk(10,sum(irate(container_cpu_usage_seconds_total{name!=\"\",instance=~\"%s:.*\"}[2m]) * 100) by (pod, namespace, instance))", node.IP) logging.Debugf("Prom Query : %s", query) val, err := conn.Client.QueryRange(query, start, end, time.Minute) if err != nil { @@ -230,7 +230,7 @@ func VSwitchMem(node NodeInfo, conn PromConnect, start time.Time, end time.Time, // TopPodMem will return the top 5 Mem consumers for a specific node func TopPodMem(node NodeInfo, conn PromConnect, start time.Time, end time.Time) (PodValues, bool) { var pods PodValues - query := fmt.Sprintf("topk(5,sum(container_memory_rss{container!=\"POD\",name!=\"\",node=~\"%s\"}) by (pod, namespace, node))", node.NodeName) + query := fmt.Sprintf("topk(10,sum(container_memory_rss{container!=\"POD\",name!=\"\",node=~\"%s\"}) by (pod, namespace, node))", node.NodeName) logging.Debugf("Prom Query : %s", query) val, err := conn.Client.QueryRange(query, start, end, time.Minute) if err != nil { From 2cf30f647652536aa4cc2b9691066ae81d5f8010 Mon Sep 17 00:00:00 2001 From: "Joe Talerico (rook)" Date: Fri, 15 Nov 2024 13:50:44 -0500 Subject: [PATCH 4/5] Update pkg/metrics/system.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Raúl Sevilla --- pkg/metrics/system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/metrics/system.go b/pkg/metrics/system.go index 34ab9f4..a8483b1 100644 --- a/pkg/metrics/system.go +++ b/pkg/metrics/system.go @@ -174,7 +174,7 @@ func QueryNodeCPU(node NodeInfo, conn PromConnect, start time.Time, end time.Tim return cpu, true } -// TopPodCPU will return the top 5 CPU consumers for a specific node +// TopPodCPU will return the top 10 CPU consumers for a specific node func TopPodCPU(node NodeInfo, conn PromConnect, start time.Time, end time.Time) (PodValues, bool) { var pods PodValues query := fmt.Sprintf("topk(10,sum(irate(container_cpu_usage_seconds_total{name!=\"\",instance=~\"%s:.*\"}[2m]) * 100) by (pod, namespace, instance))", node.IP) From e40f13734ce1b39cf4d067bfd9f33bd97c287c57 Mon Sep 17 00:00:00 2001 From: "Joe Talerico (rook)" Date: Fri, 15 Nov 2024 13:51:06 -0500 Subject: [PATCH 5/5] Update pkg/metrics/system.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Raúl Sevilla --- pkg/metrics/system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/metrics/system.go b/pkg/metrics/system.go index a8483b1..f02559c 100644 --- a/pkg/metrics/system.go +++ b/pkg/metrics/system.go @@ -227,7 +227,7 @@ func VSwitchMem(node NodeInfo, conn PromConnect, start time.Time, end time.Time, return true } -// TopPodMem will return the top 5 Mem consumers for a specific node +// TopPodMem will return the top 10 Mem consumers for a specific node func TopPodMem(node NodeInfo, conn PromConnect, start time.Time, end time.Time) (PodValues, bool) { var pods PodValues query := fmt.Sprintf("topk(10,sum(container_memory_rss{container!=\"POD\",name!=\"\",node=~\"%s\"}) by (pod, namespace, node))", node.NodeName)