// Copyright 2021 99cloud
//
// Licensed 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, { Component } from 'react';
import { Col, Row } from 'antd';
import styles from 'pages/monitor/containers/StorageCluster/index.less';
import { observer } from 'mobx-react';
import { handleResponses } from 'components/PrometheusChart/utils/dataHandler';
import { get, merge } from 'lodash';
import BaseCard from 'components/PrometheusChart/BaseCard';
import { ChartType } from 'components/PrometheusChart/utils/utils';
import ChartCard from 'components/PrometheusChart/ChartCard';
@observer
class Charts extends Component {
constructor(props) {
super(props);
this.store = props.store;
}
renderTopCards() {
const baseConfig = {
constructorParams: {
requestType: 'current',
formatDataFn: handleResponses,
},
visibleHeight: 55,
renderContent: (store) => (
{get(store, 'data[0].y', 0)}
),
};
const chartLists = [
{
title: t('Server Status'),
span: 6,
constructorParams: {
metricKey: 'rabbitMQService.serviceStatus',
formatDataFn: (resps) => {
const tmp = {
up: 0,
down: 0,
};
const result = get(resps[0], 'data.result', []);
result.forEach((r) => {
parseInt(r.value[1], 10) === 1 ? (tmp.up += 1) : (tmp.down += 1);
});
return tmp;
},
},
renderContent: (store) => {
const { data } = store;
return (
{data.up + t('Up')}
{data.down + t('Down')}
);
},
},
{
title: t('Connected Threads'),
constructorParams: {
metricKey: 'rabbitMQService.totalConnections',
},
},
{
title: t('Total Queues'),
constructorParams: {
metricKey: 'rabbitMQService.totalQueues',
},
},
{
title: t('Total Exchanges'),
constructorParams: {
metricKey: 'rabbitMQService.totalExchanges',
},
},
{
title: t('Total Consumers'),
constructorParams: {
metricKey: 'rabbitMQService.totalConsumers',
},
},
];
return (
{chartLists.map((chartProps) => {
const config = merge({}, baseConfig, chartProps);
const { span, ...rest } = config;
return (
);
})}
);
}
renderChartCards() {
const baseConfig = {
span: 12,
constructorParams: {
requestType: 'range',
formatDataFn: handleResponses,
},
chartProps: {
height: 300,
scale: {
y: {
nice: true,
},
},
},
};
const chartLists = [
{
title: t('Published Out'),
constructorParams: {
metricKey: 'rabbitMQService.publishedOut',
},
chartProps: {
chartType: ChartType.ONELINE,
scale: {
y: {
alias: t('Published Out'),
},
},
},
},
{
title: t('Published In'),
constructorParams: {
metricKey: 'rabbitMQService.publishedIn',
},
chartProps: {
chartType: ChartType.ONELINE,
scale: {
y: {
alias: t('Published In'),
},
},
},
},
// {
// title: t('Total Message'),
// constructorParams: {
// metricKey: 'rabbitMQService.totalMessage',
// },
// chartProps: {
// chartType: ChartType.ONELINE,
// scale: {
// y: {
// alias: t('Total Message'),
// },
// },
// },
// },
{
title: t('Channel'),
constructorParams: {
metricKey: 'rabbitMQService.channel',
},
chartProps: {
chartType: ChartType.ONELINE,
scale: {
y: {
alias: t('Channel'),
},
},
},
},
];
return (
{chartLists.map((chartProps) => {
const config = merge({}, baseConfig, chartProps);
const { span, ...rest } = config;
return (
);
})}
);
}
render() {
if (this.store.isLoading) {
return null;
}
return (
{this.renderTopCards()}
{this.renderChartCards()}
);
}
}
export default Charts;