Ivan Galakhov 4 лет назад
Родитель
Сommit
22ea01be2b

+ 23 - 22
dashboard/src/main/home/cluster-dashboard/dashboard/Metrics.tsx

@@ -40,9 +40,11 @@ const Metrics: React.FC = () => {
   const [ingressOptions, setIngressOptions] = useState([]);
   const [selectedIngress, setSelectedIngress] = useState(null);
   const [selectedRange, setSelectedRange] = useState("1H");
-  const [selectedMetric, setSelectedMetric] = useState("nginx:errors");
+  const [selectedMetric, setSelectedMetric] = useState(
+    "nginx:latency-histogram"
+  );
   const [selectedMetricLabel, setSelectedMetricLabel] = useState(
-    "5XX Error Percentage "
+    "Latency Histogram"
   );
   const [data, setData] = useState<NormalizedMetricsData[]>([]);
   const [showMetricsSettings, setShowMetricsSettings] = useState(false);
@@ -106,6 +108,10 @@ const Metrics: React.FC = () => {
                 value: "nginx:latency",
                 label: "Request Latency",
               },
+              {
+                value: "nginx:latency-histogram",
+                label: "Latency Histogram",
+              },
             ]);
             setLoading(false);
           })
@@ -124,26 +130,21 @@ const Metrics: React.FC = () => {
 
   const renderMetricsSettings = () => {
     if (showMetricsSettings) {
-      if (
-        selectedMetric == "nginx:errors" ||
-        selectedMetric == "nginx:latency"
-      ) {
-        return (
-          <>
-            <DropdownOverlay onClick={() => setShowMetricsSettings(false)} />
-            <DropdownAlt dropdownWidth="330px" dropdownMaxHeight="300px">
-              <Label>Additional Settings</Label>
-              <SelectRow
-                label="Target Ingress"
-                value={selectedIngress}
-                setActiveValue={(x: any) => setSelectedIngress(x)}
-                options={ingressOptions}
-                width="100%"
-              />
-            </DropdownAlt>
-          </>
-        );
-      }
+      return (
+        <>
+          <DropdownOverlay onClick={() => setShowMetricsSettings(false)} />
+          <DropdownAlt dropdownWidth="330px" dropdownMaxHeight="300px">
+            <Label>Additional Settings</Label>
+            <SelectRow
+              label="Target Ingress"
+              value={selectedIngress}
+              setActiveValue={(x: any) => setSelectedIngress(x)}
+              options={ingressOptions}
+              width="100%"
+            />
+          </DropdownAlt>
+        </>
+      );
     }
   };
 

+ 1 - 1
dashboard/src/main/home/cluster-dashboard/expanded-chart/metrics/MetricNormalizer.ts

@@ -39,7 +39,7 @@ export class MetricNormalizer {
     if (this.kind.includes("nginx:errors")) {
       return this.parseNGINXErrorsMetrics(this.metric_results);
     }
-    if (this.kind.includes("nginx:latency")) {
+    if (this.kind.includes("nginx:latency") || this.kind.includes("nginx:latency-histogram")) {
       return this.parseNGINXLatencyMetrics(this.metric_results);
     }
     if (this.kind.includes("hpa_replicas")) {

+ 3 - 1
internal/kubernetes/prometheus/metrics.go

@@ -128,6 +128,8 @@ func QueryPrometheus(
 		num := fmt.Sprintf(`sum(rate(nginx_ingress_controller_request_duration_seconds_sum{namespace=~"%s",ingress=~"%s"}[5m]) OR on() vector(0))`, opts.Namespace, selectionRegex)
 		denom := fmt.Sprintf(`sum(rate(nginx_ingress_controller_request_duration_seconds_count{namespace=~"%s",ingress=~"%s"}[5m]))`, opts.Namespace, selectionRegex)
 		query = fmt.Sprintf(`%s / %s OR on() vector(0)`, num, denom)
+	} else if opts.Metric == "nginx:latency-histogram" {
+		query = fmt.Sprintf(`histogram_quantile(0.99, sum(rate(nginx_ingress_controller_request_duration_seconds_bucket{status!="404",status!="500",namespace=~"%s",ingress=~"%s"}[5m])) by (le, ingress))`, opts.Namespace, selectionRegex)
 	} else if opts.Metric == "cpu_hpa_threshold" {
 		// get the name of the kube hpa metric
 		metricName, hpaMetricName := getKubeHPAMetricName(clientset, service, opts, "spec_target_metric")
@@ -253,7 +255,7 @@ func parseQuery(rawQuery []byte, metric string) ([]byte, error) {
 				singletonResult.Memory = values[1]
 			} else if metric == "hpa_replicas" {
 				singletonResult.Replicas = values[1]
-			} else if metric == "nginx:latency" {
+			} else if metric == "nginx:latency" || metric == "nginx:latency-histogram" {
 				singletonResult.Latency = values[1]
 			}