mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-07-18 14:45:25 +00:00
add avg calculations
This commit is contained in:
parent
69a9c6de13
commit
69af56dc84
@ -34,6 +34,8 @@ export enum Calculations {
|
|||||||
ConvertMilliseconds = "convertMilliseconds",
|
ConvertMilliseconds = "convertMilliseconds",
|
||||||
MsTos = "msTos",
|
MsTos = "msTos",
|
||||||
Average = "average",
|
Average = "average",
|
||||||
|
PercentageAvg = "percentageAvg",
|
||||||
|
ApdexAvg = "apdexAvg",
|
||||||
}
|
}
|
||||||
export enum sizeEnum {
|
export enum sizeEnum {
|
||||||
XS = "XS",
|
XS = "XS",
|
||||||
|
@ -17,16 +17,21 @@
|
|||||||
import { MetricQueryTypes, Calculations } from "./data";
|
import { MetricQueryTypes, Calculations } from "./data";
|
||||||
export function useListConfig(config: any, index: string) {
|
export function useListConfig(config: any, index: string) {
|
||||||
const i = Number(index);
|
const i = Number(index);
|
||||||
|
const types = [
|
||||||
|
Calculations.Average,
|
||||||
|
Calculations.ApdexAvg,
|
||||||
|
Calculations.PercentageAvg,
|
||||||
|
];
|
||||||
const calculation =
|
const calculation =
|
||||||
config.metricConfig &&
|
config.metricConfig &&
|
||||||
config.metricConfig[i] &&
|
config.metricConfig[i] &&
|
||||||
config.metricConfig[i].calculation;
|
config.metricConfig[i].calculation;
|
||||||
const line =
|
const line =
|
||||||
config.metricTypes[i] === MetricQueryTypes.ReadMetricsValues &&
|
config.metricTypes[i] === MetricQueryTypes.ReadMetricsValues &&
|
||||||
calculation !== Calculations.Average;
|
!types.includes(calculation);
|
||||||
const isAvg =
|
const isAvg =
|
||||||
config.metricTypes[i] === MetricQueryTypes.ReadMetricsValues &&
|
config.metricTypes[i] === MetricQueryTypes.ReadMetricsValues &&
|
||||||
calculation === Calculations.Average;
|
types.includes(calculation);
|
||||||
return {
|
return {
|
||||||
isLinear: line,
|
isLinear: line,
|
||||||
isAvg,
|
isAvg,
|
||||||
|
@ -278,14 +278,20 @@ export function usePodsSource(
|
|||||||
}
|
}
|
||||||
const data = pods.map((d: Instance | any, idx: number) => {
|
const data = pods.map((d: Instance | any, idx: number) => {
|
||||||
config.metrics.map((name: string, index: number) => {
|
config.metrics.map((name: string, index: number) => {
|
||||||
const c = (config.metricConfig && config.metricConfig[index]) || {};
|
const c: any = (config.metricConfig && config.metricConfig[index]) || {};
|
||||||
const key = name + idx + index;
|
const key = name + idx + index;
|
||||||
if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValue) {
|
if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValue) {
|
||||||
d[name] = aggregation(resp.data[key], c);
|
d[name] = aggregation(resp.data[key], c);
|
||||||
}
|
}
|
||||||
if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues) {
|
if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues) {
|
||||||
d[name] = {};
|
d[name] = {};
|
||||||
if (c.calculation === Calculations.Average) {
|
if (
|
||||||
|
[
|
||||||
|
Calculations.Average,
|
||||||
|
Calculations.ApdexAvg,
|
||||||
|
Calculations.PercentageAvg,
|
||||||
|
].includes(c.calculation)
|
||||||
|
) {
|
||||||
d[name]["avg"] = calculateExp(resp.data[key].values.values, c);
|
d[name]["avg"] = calculateExp(resp.data[key].values.values, c);
|
||||||
}
|
}
|
||||||
d[name]["values"] = resp.data[key].values.values.map(
|
d[name]["values"] = resp.data[key].values.values.map(
|
||||||
@ -337,6 +343,24 @@ function calculateExp(
|
|||||||
).toFixed(2),
|
).toFixed(2),
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
|
case Calculations.PercentageAvg:
|
||||||
|
data = [
|
||||||
|
(
|
||||||
|
arr.map((d: { value: number }) => d.value).reduce((a, b) => a + b) /
|
||||||
|
arr.length /
|
||||||
|
100
|
||||||
|
).toFixed(2),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case Calculations.ApdexAvg:
|
||||||
|
data = [
|
||||||
|
(
|
||||||
|
arr.map((d: { value: number }) => d.value).reduce((a, b) => a + b) /
|
||||||
|
arr.length /
|
||||||
|
10000
|
||||||
|
).toFixed(2),
|
||||||
|
];
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
data = arr.map((d) => aggregation(d.value, config));
|
data = arr.map((d) => aggregation(d.value, config));
|
||||||
break;
|
break;
|
||||||
|
@ -263,10 +263,12 @@ export const TextColors: { [key: string]: string } = {
|
|||||||
export const CalculationOpts = [
|
export const CalculationOpts = [
|
||||||
{ label: "Percentage", value: "percentage" },
|
{ label: "Percentage", value: "percentage" },
|
||||||
{ label: "Apdex", value: "apdex" },
|
{ label: "Apdex", value: "apdex" },
|
||||||
|
{ label: "Avg-preview", value: "average" },
|
||||||
|
{ label: "Percentage + Avg-preview", value: "percentageAvg" },
|
||||||
|
{ label: "Apdex + Avg-preview", value: "apdexAvg" },
|
||||||
{ label: "Byte to KB", value: "byteToKB" },
|
{ label: "Byte to KB", value: "byteToKB" },
|
||||||
{ label: "Byte to MB", value: "byteToMB" },
|
{ label: "Byte to MB", value: "byteToMB" },
|
||||||
{ label: "Byte to GB", value: "byteToGB" },
|
{ label: "Byte to GB", value: "byteToGB" },
|
||||||
{ label: "Average", value: "average" },
|
|
||||||
{
|
{
|
||||||
label: "Milliseconds to YYYY-MM-DD HH:mm:ss",
|
label: "Milliseconds to YYYY-MM-DD HH:mm:ss",
|
||||||
value: "convertMilliseconds",
|
value: "convertMilliseconds",
|
||||||
|
Loading…
Reference in New Issue
Block a user