2018-09-02 09:11:21 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-08-31 11:49:32 -05:00
|
|
|
import { hot } from 'react-hot-loader';
|
|
|
|
import { connect } from 'react-redux';
|
2019-04-30 09:46:46 -05:00
|
|
|
import { StoreState } from 'app/types';
|
2018-09-02 13:36:03 -05:00
|
|
|
import { getNavModel } from 'app/core/selectors/navModel';
|
2018-09-07 10:55:38 -05:00
|
|
|
import { getServerStats, ServerStat } from './state/apis';
|
2019-01-28 15:27:19 -06:00
|
|
|
import Page from 'app/core/components/Page/Page';
|
2019-06-18 10:17:27 -05:00
|
|
|
import { NavModel } from '@grafana/data';
|
2018-08-31 11:49:32 -05:00
|
|
|
|
2018-09-02 12:36:36 -05:00
|
|
|
interface Props {
|
|
|
|
navModel: NavModel;
|
2018-08-31 11:49:32 -05:00
|
|
|
getServerStats: () => Promise<ServerStat[]>;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
stats: ServerStat[];
|
2019-01-28 15:27:19 -06:00
|
|
|
isLoading: boolean;
|
2018-08-31 11:49:32 -05:00
|
|
|
}
|
|
|
|
|
2018-09-02 09:11:21 -05:00
|
|
|
export class ServerStats extends PureComponent<Props, State> {
|
2019-10-03 07:11:21 -05:00
|
|
|
state: State = {
|
|
|
|
stats: [],
|
|
|
|
isLoading: true,
|
|
|
|
};
|
2018-08-31 11:49:32 -05:00
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
try {
|
|
|
|
const stats = await this.props.getServerStats();
|
2019-01-28 15:27:19 -06:00
|
|
|
this.setState({ stats, isLoading: false });
|
2018-08-31 11:49:32 -05:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { navModel } = this.props;
|
2019-01-28 15:27:19 -06:00
|
|
|
const { stats, isLoading } = this.state;
|
2018-08-31 11:49:32 -05:00
|
|
|
|
|
|
|
return (
|
2019-01-28 15:27:19 -06:00
|
|
|
<Page navModel={navModel}>
|
|
|
|
<Page.Contents isLoading={isLoading}>
|
2018-08-31 11:49:32 -05:00
|
|
|
<table className="filter-table form-inline">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Value</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>{stats.map(StatItem)}</tbody>
|
|
|
|
</table>
|
2019-01-28 15:27:19 -06:00
|
|
|
</Page.Contents>
|
|
|
|
</Page>
|
2018-08-31 11:49:32 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function StatItem(stat: ServerStat) {
|
|
|
|
return (
|
|
|
|
<tr key={stat.name}>
|
|
|
|
<td>{stat.name}</td>
|
|
|
|
<td>{stat.value}</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-02 12:36:36 -05:00
|
|
|
const mapStateToProps = (state: StoreState) => ({
|
2018-09-02 13:36:03 -05:00
|
|
|
navModel: getNavModel(state.navIndex, 'server-stats'),
|
2018-08-31 11:49:32 -05:00
|
|
|
getServerStats: getServerStats,
|
|
|
|
});
|
|
|
|
|
2018-09-02 12:36:36 -05:00
|
|
|
export default hot(module)(connect(mapStateToProps)(ServerStats));
|