Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add some utils #261

Merged
merged 2 commits into from
May 19, 2023
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
12 changes: 7 additions & 5 deletions src/components/Charts/RingProgressChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IProps {
percent: number;
type: string;
config?: any;
contentFormatter?:(p:number)=>string;
}

const ColorMap = {
Expand All @@ -17,7 +18,7 @@ const ColorMap = {
}

function RingProgressChart(props: IProps) {
const { percent, type, config } = props;
const { percent, type, config,contentFormatter } = props;

const calcColor = () => {
const level = calcNodeHealty(percent);
Expand All @@ -37,19 +38,20 @@ function RingProgressChart(props: IProps) {
title: {
style: {
color: '#000',
fontSize: '12px',
lineHeight: '14px',
fontSize: '16px',
lineHeight: '16px',
},
formatter: () => type,
},
content: {
style: {
color: '#000',
fontWeight: 'bold',
marginTop: '15px',
fontSize: '14px',
marginTop: '10px',
fontSize: '12px',
lineHeight: '14px',
},
formatter:contentFormatter
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/components/Charts/SpaceChart.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
padding: 12px 0;
overflow: auto;
height: 100%;
max-height: 240px;
overflow-y: auto;

>.tip {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/MachineDashboard/Cards/DiskCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DiskCard = forwardRef((props: IProps, ref) => {

const asyncGetDiskUsageDetails = async () => {
const clusterSuffix1 = cluster ? `,${getClusterPrefix()}="${cluster.id}"` : '';
const instanceSuffix = `, instance=~"^${instance.replaceAll(".", "\.")}.*"`;
const instanceSuffix = instance!=='all'?`, instance=~"^${instance.replaceAll(".", "\.")}.*"`:'';
const queries: any = [
{
refId: 'diskSize',
Expand All @@ -42,7 +42,7 @@ const DiskCard = forwardRef((props: IProps, ref) => {
}
];
const data = await asyncBatchQueries(queries);
const { results } = data;
const { results } = data as any;
const details = results.diskSize.result.map(item => {
const metricItem = results.diskUsed.result.find(usedItem => usedItem.metric.device === item.metric.device);
let used = 0;
Expand All @@ -54,7 +54,7 @@ const DiskCard = forwardRef((props: IProps, ref) => {
device: item.metric.device,
mountpoint: item.metric.mountpoint,
used,
name: instance,
name: item.metric.instance.split(':')[0],
}
});
setDiskUsageDetails(details);
Expand Down
12 changes: 12 additions & 0 deletions src/utils/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ export const getProperByteDesc = (bytes: number) => {
desc: value + unit,
}
}

export const getProperByUnit = (bytes: number, unit: string) => {
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] as const;
const i = sizes.findIndex(s => s === unit);
const value = (bytes / Math.pow(1024, i)).toFixed(2)
return {
value:parseFloat(value),
unit,
desc: value + unit,
}
}

export const getAutoLatency = (latency: number) => {
if (latency > 60 * 1000 * 1000) {
// min
Expand Down