Unverified Commit 0b77ae0a authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

added metrics layout (#2048)

parent 946a9582
......@@ -230,7 +230,7 @@ export default [
name: 'metrics',
icon: 'DashboardOutlined',
footerRender: false,
// component: './Metrics',
component: './Metrics',
},
{
path: '/about',
......
This diff is collapsed.
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {useEffect, useState} from "react";
import {Area, AreaConfig} from "@ant-design/plots";
const CPU = () => {
const [data, setData] = useState([]);
useEffect(() => {
asyncFetch();
}, []);
const asyncFetch = () => {
fetch('https://gw.alipayobjects.com/os/bmw-prod/1d565782-dde4-4bb6-8946-ea6a38ccf184.json')
.then((response) => response.json())
.then((json) => setData(json))
.catch((error) => {
console.log('fetch data failed', error);
});
};
const config :AreaConfig = {
data,
height: 200,
xField: 'Date',
yField: 'scales',
xAxis: {
tickCount: 5,
},
animation: false,
slider: {
start: 0.1,
end: 0.9,
trendCfg: {
isArea: true,
},
},
};
return <Area {...config} />;
}
export default CPU;
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {LightFilter, ProFormDateTimeRangePicker, ProFormRadio} from "@ant-design/pro-components";
import React from "react";
import {DATE_RANGE_OPTIONS} from "@/pages/Metrics/Server/constants";
type GlobalFilterProps = {
dateRange: string;
startTime: any;
endTime: any;
handleDateRadioChange: (e: any) => void;
handleRangeChange: (e: any) => void;
}
const GlobalFilter: React.FC<GlobalFilterProps> = (props) => {
const {dateRange, startTime, endTime, handleDateRadioChange, handleRangeChange} = props;
console.log('GlobalFilter', props);
return <>
<LightFilter
initialValues={{dateRange: 'today',}}
layout="vertical"
bordered
>
<ProFormRadio.Group
name="dateRange"
radioType="radio"
initialValue={dateRange}
fieldProps={{onChange: handleDateRadioChange}}
options={DATE_RANGE_OPTIONS}
/>
<ProFormDateTimeRangePicker
name="datetimeRanger"
label="日期时间范围"
allowClear={false}
initialValue={[startTime, endTime]}
fieldProps={{
onChange: handleRangeChange,
style: {width: '100%'},
value: [startTime, endTime],
}}
/>
</LightFilter>
</>;
}
export default GlobalFilter;
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {useEffect, useState} from "react";
import {Area, AreaConfig} from "@ant-design/plots";
const Heap = () => {
const [data, setData] = useState([]);
useEffect(() => {
asyncFetch();
}, []);
const asyncFetch = () => {
fetch('https://gw.alipayobjects.com/os/bmw-prod/b21e7336-0b3e-486c-9070-612ede49284e.json')
.then((response) => response.json())
.then((json) => setData(json))
.catch((error) => {
console.log('fetch data failed', error);
});
};
const config: AreaConfig = {
data,
height: 200,
xField: 'date',
yField: 'value',
seriesField: 'country',
slider: {
start: 0.1,
end: 0.9,
},
};
return <Area {...config} />;
}
export default Heap;
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {useEffect, useState} from "react";
import {Area, AreaConfig} from "@ant-design/plots";
const OutHeap = () => {
const [data, setData] = useState([]);
useEffect(() => {
asyncFetch();
}, []);
const asyncFetch = () => {
fetch('https://gw.alipayobjects.com/os/bmw-prod/b21e7336-0b3e-486c-9070-612ede49284e.json')
.then((response) => response.json())
.then((json) => setData(json))
.catch((error) => {
console.log('fetch data failed', error);
});
};
const config: AreaConfig = {
data,
height: 200,
xField: 'date',
yField: 'value',
seriesField: 'country',
slider: {
start: 0.1,
end: 0.9,
},
};
return <Area {...config} />;
}
export default OutHeap;
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {useEffect, useState} from "react";
import {Area, AreaConfig} from "@ant-design/plots";
const Thread = () => {
const [data, setData] = useState([]);
useEffect(() => {
asyncFetch();
}, []);
const asyncFetch = () => {
fetch('https://gw.alipayobjects.com/os/bmw-prod/b21e7336-0b3e-486c-9070-612ede49284e.json')
.then((response) => response.json())
.then((json) => setData(json))
.catch((error) => {
console.log('fetch data failed', error);
});
};
const config: AreaConfig = {
data,
height: 200,
xField: 'date',
yField: 'value',
seriesField: 'country',
slider: {
start: 0.1,
end: 0.9,
},
};
return <Area {...config} />;
}
export default Thread;
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
export const DATE_RANGE_OPTIONS = [
{
value: 'all',
label: '所有',
},
{
value: '60s',
label: '60秒',
},
{
value: '5min',
label: '5分钟',
},
{
value: '10min',
label: '10分钟',
},
{
value: '1h',
label: '1小时',
},
{
value: '2h',
label: '2小时',
},
{
value: '5h',
label: '5小时',
},
{
value: '12h',
label: '12小时',
},
{
value: '24h',
label: '24小时',
},
{
value: 'today',
label: '今天',
},
{
value: 'yesterday',
label: '昨天',
},
{
value: 'yesterdaybefore',
label: '前天 ',
},
{
value: 'last7days',
label: '最近7天',
},
{
value: 'last15days',
label: '最近15天',
},
{
value: 'monthly',
label: '本月',
},
]
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
const getSubMinTime = (currentTime : Date ,minutes: number) => {
const pastTime = new Date(currentTime.getTime() - minutes * 60000);
return pastTime;
};
const getSubMinutesEndTime = (currentTime : Date ,minutes: number) => {
const pastTime = new Date(
currentTime.getFullYear(),
currentTime.getMonth(),
currentTime.getDate(),
currentTime.getHours(),
59,
59,59,
);
return pastTime;
};
const getSubDateTime = (currentTime : Date ,day: number) => {
const pastTime = new Date(
currentTime.getFullYear(),
currentTime.getMonth(),
currentTime.getDate() - day,
0, 0, 0, 0
);
return pastTime;
};
const getSubDateEndTime = (currentTime : Date ,day: number) => {
const pastTime = new Date(
currentTime.getFullYear(),
currentTime.getMonth(),
currentTime.getDate() - day,
23, 59, 59, 59
);
return pastTime;
};
const getSubMon = (currentTime : Date ,month: number) => {
const pastTime = new Date(
currentTime.getFullYear(),
currentTime.getMonth() - month,
1,
0, 0, 0, 0
);
return pastTime;
};
const getSubMonEnd = (currentTime : Date ,month: number) => {
const pastTime = new Date(
currentTime.getFullYear(),
currentTime.getMonth() - month,
currentTime.getDay(),
23, 59, 59, 59
);
return pastTime;
};
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {
ProCard,
} from "@ant-design/pro-components";
import CPU from "@/pages/Metrics/Server/CPU";
import Heap from "@/pages/Metrics/Server/Heap";
import OutHeap from "@/pages/Metrics/Server/OutHeap";
import Thread from "@/pages/Metrics/Server/Thread";
import {CPUIcon, HeapIcon, OutHeapIcon, ThreadIcon} from "@/components/Icons/MetricsIcon";
import {Space} from "antd";
import {useEffect, useState} from "react";
import GlobalFilter from "@/pages/Metrics/Server/GlobalFilter";
export const imgStyle = {
display: 'block',
width: 24,
height: 24,
};
const Server = () => {
const [currentTime, setCurrentTime] = useState(new Date());
const [dateRange, setDateRange] = useState<string>('today');
const [startTime, setStartTime] = useState(new Date());
const [endTime, setEndTime] = useState(new Date());
useEffect(() => {
const timer = setInterval(() => {
setCurrentTime(new Date());
}, 1000);
return () => {
clearInterval(timer);
};
}, []);
const handleDateRadioChange = (e: any) => {
const dateKey = e.target.value;
setDateRange(dateKey)
switch (dateKey) {
case 'all':
setStartTime(getSubMinTime(currentTime,24 * 60 * 9999))
setEndTime(currentTime)
break;
case '60s':
setStartTime(getSubMinTime(currentTime,1))
setEndTime(currentTime)
break;
case '5min':
console.log('5min')
setStartTime(getSubMinTime(currentTime,5))
setEndTime(currentTime)
break;
case '10min':
console.log('10min')
setStartTime(getSubMinTime(currentTime,10))
setEndTime(currentTime)
break;
case '1h':
setStartTime(getSubMinTime(currentTime,60))
setEndTime(currentTime)
break;
case '2h':
setStartTime(getSubMinTime(currentTime,2 * 60))
setEndTime(currentTime)
break;
case '5h':
setStartTime(getSubMinTime(currentTime,5 * 60))
setEndTime(currentTime)
break;
case '12h':
setStartTime(getSubMinTime(currentTime,12 * 60))
setEndTime(currentTime)
break;
case '24h':
setStartTime(getSubMinTime(currentTime,24 * 60))
setEndTime(currentTime)
break;
case 'today':
setStartTime(getSubDateTime(currentTime,0))
setEndTime(getSubDateEndTime(currentTime,0))
break;
case 'yesterday':
setStartTime(getSubDateTime(currentTime,1))
setEndTime(getSubDateEndTime(currentTime,1))
break;
case 'yesterdaybefore':
setStartTime(getSubDateTime(currentTime,2))
setEndTime(getSubDateEndTime(currentTime,2))
break;
case 'last7days':
setStartTime(getSubDateTime(currentTime,7))
setEndTime(getSubDateEndTime(currentTime,0))
break;
case 'last15days':
setStartTime(getSubDateTime(currentTime,15))
setEndTime(getSubDateEndTime(currentTime,0))
break;
case 'monthly':
setStartTime(
new Date(
currentTime.getFullYear(),
currentTime.getMonth(),
currentTime.getDate(),
0, 0, 0, 0
)
)
// setEndTime(getLastDayOfMonth(new Date()))
break;
default:
setStartTime(getSubMinTime(currentTime,24 * 60 * 999))
setEndTime(currentTime)
break;
}
}
const handleRangeChange = (e: any) => {
e.map((item: any) => {
setStartTime(item[0])
setEndTime(item[1])
})
}
return <>
<ProCard style={{height: '8vh'}} ghost colSpan={'100%'}>
<GlobalFilter dateRange={dateRange} endTime={endTime} startTime={startTime}
handleDateRadioChange={handleDateRadioChange} handleRangeChange={handleRangeChange}/>
</ProCard>
<ProCard style={{height: '90vh'}} ghost wrap size={'small'} split={'vertical'}>
<ProCard style={{height: '20vh'}} split={'vertical'}>
<ProCard title={<Space><CPUIcon style={imgStyle}/>CPU</Space>}>
<CPU/>
</ProCard>
<ProCard title={<Space><HeapIcon style={imgStyle}/>Heap</Space>}>
<Heap/>
</ProCard>
<ProCard title={<Space><ThreadIcon style={imgStyle}/>Thread</Space>}>
<Thread/>
</ProCard>
<ProCard title={<Space><OutHeapIcon style={imgStyle}/>Out Heap</Space>}>
<OutHeap/>
</ProCard>
</ProCard>
</ProCard>
</>
}
export default Server;
\ No newline at end of file
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import React from "react";
import Server from "@/pages/Metrics/Server";
import {PageContainer} from "@ant-design/pro-components";
export default () => {
return <PageContainer title={false}>
<Server/>
</PageContainer>;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment