Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/web/projects/vgpu/hooks/useInstantVector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cardApi from '~/vgpu/api/card';
import { onMounted, ref, watch, watchEffect } from 'vue';
import { timeParse } from '@/utils';
import { timeParse, calculatePrometheusStep } from '@/utils';

const useInstantVector = (configs, parseQuery = (query) => query, times) => {
const data = ref(configs);
Expand Down Expand Up @@ -38,7 +38,7 @@ const useInstantVector = (configs, parseQuery = (query) => query, times) => {
range: {
start: timeParse(times?.value[0]),
end: timeParse(times?.value[1]),
step: '1m',
step: calculatePrometheusStep(times?.value[0], times?.value[1]),
},
});

Expand All @@ -63,7 +63,7 @@ const useInstantVector = (configs, parseQuery = (query) => query, times) => {
range: {
start: timeParse(times.value[0]),
end: timeParse(times.value[1]),
step: '1m',
step: calculatePrometheusStep(times.value[0], times.value[1]),
},
});

Expand Down
7 changes: 4 additions & 3 deletions packages/web/projects/vgpu/hooks/useRangeVector.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import cardApi from '~/vgpu/api/card';
import { ref, watchEffect } from 'vue';
import { timeParse } from '@/utils';
import { timeParse, calculatePrometheusStep } from '@/utils';

const useInstantVector = (configs, parseQuery = (query) => query) => {
const data = ref(configs);

const fetchData = async () => {
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
const end = new Date();

const reqs = configs.map(({ query }) =>
cardApi.getRangeVector({
range: {
start: timeParse(start),
end: timeParse(new Date()),
step: '1m',
end: timeParse(end),
step: calculatePrometheusStep(start, end),
},
query: item.query.replace('$node', detail.value.name),
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/web/projects/vgpu/views/card/admin/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import useInstantVector from '~/vgpu/hooks/useInstantVector';
import { QuestionFilled } from '@element-plus/icons-vue';
import EchartsPlus from '@/components/Echarts-plus.vue';
import cardApi from '~/vgpu/api/card';
import { timeParse } from '@/utils';
import { timeParse, calculatePrometheusStep } from '@/utils';
import { getLineOptions } from '~/vgpu/views/monitor/overview/getOptions';
import { getLineOptions as getLineOptions2 } from '~/vgpu/components/config';
import TimeSelect from '~/vgpu/components/timeSelect.vue';
Expand Down Expand Up @@ -304,7 +304,7 @@ const fetchLineData = async () => {
range: {
start: timeParse(times.value[0]),
end: timeParse(times.value[1]),
step: '1m',
step: calculatePrometheusStep(times.value[0], times.value[1]),
},
query: item.query.replaceAll(`$deviceuuid`, route.params.uuid),
})
Expand Down
9 changes: 1 addition & 8 deletions packages/web/projects/vgpu/views/monitor/overview/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,12 @@ const nodeTotalTop = {
const rangeConfig = ref(rangeConfigInit);

const fetchRangeData = () => {
// Calculate dynamic step based on time range to avoid exceeding Prometheus 11,000 data points limit
const step = calculatePrometheusStep(times.value[0], times.value[1]);
console.log('[Prometheus Step]', {
start: times.value[0],
end: times.value[1],
calculatedStep: step,
});

const params = {
range: {
start: timeParse(times.value[0]),
end: timeParse(times.value[1]),
step: step,
step: calculatePrometheusStep(times.value[0], times.value[1]),
},
};

Expand Down
4 changes: 2 additions & 2 deletions packages/web/projects/vgpu/views/task/admin/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import { onMounted, ref, watch, watchEffect } from 'vue';
import useInstantVector from '~/vgpu/hooks/useInstantVector';
import cardApi from '~/vgpu/api/card';
import { QuestionFilled } from '@element-plus/icons-vue';
import { roundToDecimal, timeParse, calculateDuration } from '@/utils';
import { roundToDecimal, timeParse, calculateDuration, calculatePrometheusStep } from '@/utils';
import taskApi from '~/vgpu/api/task';
import BlockBox from '@/components/BlockBox.vue';
import Gauge from '~/vgpu/components/gauge.vue';
Expand Down Expand Up @@ -246,7 +246,7 @@ const fetchLineData = async () => {
range: {
start: timeParse(times.value[0]),
end: timeParse(times.value[1]),
step: '1m',
step: calculatePrometheusStep(times.value[0], times.value[1]),
},
query: item.query
.replaceAll(`$container`, detail.value.name)
Expand Down
20 changes: 15 additions & 5 deletions packages/web/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,20 @@ export const clearEdges = (items) =>
export const calculatePrometheusStep = (startTime, endTime, maxPoints = 11000) => {
const start = new Date(startTime);
const end = new Date(endTime);

if (isNaN(start.getTime()) || isNaN(end.getTime())) {
return '1m';
}

const durationMs = end.getTime() - start.getTime();
if (durationMs <= 0) {

if (durationMs <= 0 || !isFinite(durationMs)) {
return '1m';
}

const durationMinutes = durationMs / (1000 * 60);
const minStepMinutes = Math.ceil(durationMinutes / maxPoints);

if (durationMinutes <= 15) {
// ≤ 15 minutes: second-level precision
const points15s = Math.ceil(durationMinutes / 0.25);
Expand All @@ -606,8 +611,13 @@ export const calculatePrometheusStep = (startTime, endTime, maxPoints = 11000) =
if (dataPointsWith24h <= maxPoints) {
return '24h';
}

const minStepDays = Math.ceil(dataPointsWith24h / maxPoints);

if (!isFinite(minStepDays) || isNaN(minStepDays) || minStepDays <= 0) {
return '24h';
}

return `${minStepDays * 24}h`;
}
};
Loading