public async Task Handle(MetricQueryRequest <NodeRamUsageWidget> request, CancellationToken cancellationToken) { var nodeCPUUsageWidget = request.DataContext; var client = kubernetesHelper.GetKubernetesClient(nodeCPUUsageWidget); var metricsResponse = await client.GetNodeMetricsAsync(nodeCPUUsageWidget.NodeName, cancellationToken); if (metricsResponse.IsValid) { var metric = MetricHelper.ParseMemoryUnit(metricsResponse.Usage.Memory); request.DataContext.Value = metric.BaseValue; request.DataContext.State = State.Ok; } else { nodeCPUUsageWidget.State = State.Invalid; } }
public async Task Handle(MetricQueryRequest <PodRamUsageWidget> request, CancellationToken cancellationToken) { var nodeCPUUsageWidget = request.DataContext; var client = kubernetesHelper.GetKubernetesClient(nodeCPUUsageWidget); var metricsResponse = await client.GetPodMetricsAsync(nodeCPUUsageWidget.Namespace, nodeCPUUsageWidget.PodName, cancellationToken); if (metricsResponse.IsValid) { var metricSum = metricsResponse.ContainerMetricss.Sum(containerMetric => MetricHelper.ParseMemoryUnit(containerMetric.Usage.Memory).BaseValue); request.DataContext.Value = metricSum; request.DataContext.State = State.Ok; } else { nodeCPUUsageWidget.State = State.Invalid; } }