Skip to content

Commit 47da2bf

Browse files
committed
revert CpuStateMetric component
1 parent 42b22d3 commit 47da2bf

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

app/pages/project/instances/instance/tabs/MetricsTab/CpuMetricsTab.tsx

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,31 @@ export default function CpuMetricsTab() {
3030
path: { instance },
3131
query: { project },
3232
})
33+
3334
const { startTime, endTime, dateTimeRangePicker } = useMetricsContext()
3435

3536
type CpuChartType = OxqlVcpuState | 'all'
3637

38+
const queryBase = {
39+
metricName: 'virtual_machine:vcpu_usage' as const,
40+
startTime,
41+
endTime,
42+
groupBy: { cols: ['vcpu_id'], op: 'sum' } as const,
43+
}
44+
3745
const stateItems: { label: string; value: CpuChartType }[] = [
3846
{ label: 'State: Running', value: 'run' },
3947
{ label: 'State: Emulating', value: 'emulation' },
4048
{ label: 'State: Idling', value: 'idle' },
4149
{ label: 'State: Waiting', value: 'waiting' },
4250
{ label: 'All states', value: 'all' },
4351
]
44-
const [selectedState, setSelectedState] = useState(stateItems[0].value)
4552

46-
const CpuStateMetric = ({ state }: { state: CpuChartType }) => (
47-
<OxqlMetric
48-
title={`CPU Utilization: ${stateItems.find((i) => i.value === state)?.label.replace('State: ', '')}`}
49-
eqFilters={{ instance_id: instanceData.id, state }}
50-
metricName={'virtual_machine:vcpu_usage' as const}
51-
startTime={startTime}
52-
endTime={endTime}
53-
groupBy={{ cols: ['vcpu_id'], op: 'sum' } as const}
54-
/>
55-
)
53+
const [selectedState, setSelectedState] = useState(stateItems[0].value)
5654

55+
const title = `CPU Utilization: ${stateItems
56+
.find((i) => i.value === selectedState)
57+
?.label.replace('State: ', '')}`
5758
return (
5859
<>
5960
<MetricHeader>
@@ -73,18 +74,38 @@ export default function CpuMetricsTab() {
7374
{selectedState === 'all' ? (
7475
<>
7576
<MetricRow>
76-
<CpuStateMetric state="run" />
77-
<CpuStateMetric state="emulation" />
77+
<OxqlMetric
78+
title="CPU Utilization: Running"
79+
eqFilters={{ instance_id: instanceData.id, state: 'run' }}
80+
{...queryBase}
81+
/>
82+
<OxqlMetric
83+
title="CPU Utilization: Emulation"
84+
eqFilters={{ instance_id: instanceData.id, state: 'emulation' }}
85+
{...queryBase}
86+
/>
7887
</MetricRow>
7988

8089
<MetricRow>
81-
<CpuStateMetric state="idle" />
82-
<CpuStateMetric state="waiting" />
90+
<OxqlMetric
91+
title="CPU Utilization: Idling"
92+
eqFilters={{ instance_id: instanceData.id, state: 'idle' }}
93+
{...queryBase}
94+
/>
95+
<OxqlMetric
96+
title="CPU Utilization: Waiting"
97+
eqFilters={{ instance_id: instanceData.id, state: 'waiting' }}
98+
{...queryBase}
99+
/>{' '}
83100
</MetricRow>
84101
</>
85102
) : (
86103
<MetricRow>
87-
<CpuStateMetric state={selectedState} />
104+
<OxqlMetric
105+
title={title}
106+
eqFilters={{ instance_id: instanceData.id, state: selectedState }}
107+
{...queryBase}
108+
/>
88109
</MetricRow>
89110
)}
90111
</MetricCollection>

0 commit comments

Comments
 (0)