2021-01-03 23:32:14 +08:00
|
|
|
import React from "react";
|
2021-01-04 00:07:19 +08:00
|
|
|
import { connect, ConnectedProps } from "react-redux";
|
2021-01-03 23:32:14 +08:00
|
|
|
import Container from "@material-ui/core/Container";
|
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
|
|
|
import Grid from "@material-ui/core/Grid";
|
|
|
|
import Typography from "@material-ui/core/Typography";
|
2021-01-05 04:05:37 +08:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
|
|
|
import SyntaxHighlighter from "react-syntax-highlighter";
|
|
|
|
import syntaxHighlightStyle from "react-syntax-highlighter/dist/esm/styles/hljs/github";
|
2021-01-04 00:07:19 +08:00
|
|
|
import { getRedisInfoAsync } from "../actions/redisInfoActions";
|
|
|
|
import { usePolling } from "../hooks";
|
|
|
|
import { AppState } from "../store";
|
2021-01-05 04:05:37 +08:00
|
|
|
import { timeAgoUnix } from "../utils";
|
2021-01-03 23:32:14 +08:00
|
|
|
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
|
|
container: {
|
|
|
|
paddingTop: theme.spacing(4),
|
|
|
|
paddingBottom: theme.spacing(4),
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2021-01-04 00:07:19 +08:00
|
|
|
function mapStateToProps(state: AppState) {
|
|
|
|
return {
|
|
|
|
loading: state.redis.loading,
|
|
|
|
redisInfo: state.redis.data,
|
2021-01-05 01:31:10 +08:00
|
|
|
redisAddress: state.redis.address,
|
2021-01-05 04:05:37 +08:00
|
|
|
redisInfoRaw: state.redis.rawData,
|
2021-01-04 00:07:19 +08:00
|
|
|
pollInterval: state.settings.pollInterval,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const connector = connect(mapStateToProps, { getRedisInfoAsync });
|
|
|
|
type Props = ConnectedProps<typeof connector>;
|
|
|
|
|
|
|
|
function RedisInfoView(props: Props) {
|
2021-01-03 23:32:14 +08:00
|
|
|
const classes = useStyles();
|
2021-01-05 04:05:37 +08:00
|
|
|
const { pollInterval, getRedisInfoAsync, redisInfo, redisInfoRaw } = props;
|
2021-01-04 00:07:19 +08:00
|
|
|
|
|
|
|
usePolling(getRedisInfoAsync, pollInterval);
|
2021-01-03 23:32:14 +08:00
|
|
|
|
2021-01-05 01:31:10 +08:00
|
|
|
// Metrics to show
|
|
|
|
// - Used Memory
|
|
|
|
// - Memory Fragmentation Ratio
|
|
|
|
// - Connected Clients
|
|
|
|
// - Connected Replicas (slaves)
|
|
|
|
// - Persistence (rdb_last_save_time, rdb_changes_since_last_save)
|
|
|
|
// - Errors (rejected_connections)
|
|
|
|
|
2021-01-03 23:32:14 +08:00
|
|
|
return (
|
|
|
|
<Container maxWidth="lg" className={classes.container}>
|
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item xs={12}>
|
|
|
|
<Typography variant="h5">Redis Info</Typography>
|
2021-01-05 01:31:10 +08:00
|
|
|
<Typography variant="subtitle1" color="textSecondary">
|
|
|
|
Connected to: {props.redisAddress}
|
|
|
|
</Typography>
|
2021-01-03 23:32:14 +08:00
|
|
|
</Grid>
|
2021-01-05 04:05:37 +08:00
|
|
|
{redisInfo !== null && (
|
|
|
|
<>
|
|
|
|
<Grid item xs={12}>
|
|
|
|
<Typography variant="h6" color="textSecondary">
|
|
|
|
Server
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard title="Version" content={redisInfo.redis_version} />
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard
|
|
|
|
title="Uptime"
|
|
|
|
content={`${redisInfo.uptime_in_days} days`}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={6} />
|
|
|
|
<Grid item xs={12}>
|
|
|
|
<Typography variant="h6" color="textSecondary">
|
|
|
|
Memory
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard
|
|
|
|
title="Used Memory"
|
|
|
|
content={redisInfo.used_memory_human}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard
|
|
|
|
title="Peak Memory Used"
|
|
|
|
content={redisInfo.used_memory_peak_human}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard
|
|
|
|
title="Memory Fragmentation Ratio"
|
|
|
|
content={redisInfo.mem_fragmentation_ratio}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3} />
|
|
|
|
<Grid item xs={12}>
|
|
|
|
<Typography variant="h6" color="textSecondary">
|
|
|
|
Connections
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard
|
|
|
|
title="Connected Clients"
|
|
|
|
content={redisInfo.connected_clients}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard
|
|
|
|
title="Connected Replicas"
|
|
|
|
content={redisInfo.connected_slaves}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={6} />
|
|
|
|
<Grid item xs={12}>
|
|
|
|
<Typography variant="h6" color="textSecondary">
|
|
|
|
Persistence
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard
|
|
|
|
title="Last Save to Disk"
|
|
|
|
content={timeAgoUnix(parseInt(redisInfo.rdb_last_save_time))}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={3}>
|
|
|
|
<MetricCard
|
|
|
|
title="Number of Changes Since Last Dump"
|
|
|
|
content={redisInfo.rdb_changes_since_last_save}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={6} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{redisInfoRaw !== null && (
|
|
|
|
<>
|
|
|
|
<Grid item xs={6}>
|
|
|
|
<Typography variant="h6" color="textSecondary">
|
|
|
|
INFO Command Output
|
|
|
|
</Typography>
|
|
|
|
<SyntaxHighlighter language="yaml" style={syntaxHighlightStyle}>
|
|
|
|
{redisInfoRaw}
|
|
|
|
</SyntaxHighlighter>
|
|
|
|
</Grid>
|
|
|
|
</>
|
|
|
|
)}
|
2021-01-03 23:32:14 +08:00
|
|
|
</Grid>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-05 04:05:37 +08:00
|
|
|
interface MetricCardProps {
|
|
|
|
title: string;
|
|
|
|
content: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function MetricCard(props: MetricCardProps) {
|
|
|
|
return (
|
|
|
|
<Card variant="outlined">
|
|
|
|
<CardContent>
|
|
|
|
<Typography
|
|
|
|
gutterBottom
|
|
|
|
color="textPrimary"
|
|
|
|
variant="h5"
|
|
|
|
align="center"
|
|
|
|
>
|
|
|
|
{props.content}
|
|
|
|
</Typography>
|
|
|
|
<Typography color="textSecondary" variant="subtitle2" align="center">
|
|
|
|
{props.title}
|
|
|
|
</Typography>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-04 00:07:19 +08:00
|
|
|
export default connector(RedisInfoView);
|