import { css } from '@emotion/css'; import React, { useEffect, useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { config } from '@grafana/runtime'; import { CardContainer, LinkButton, useStyles2 } from '@grafana/ui'; import { AccessControlAction } from 'app/types'; import { contextSrv } from '../../core/services/context_srv'; import { Loader } from '../plugins/admin/components/Loader'; import { CrawlerStatus } from './CrawlerStatus'; import { ExportStatus } from './ExportStatus'; import { getServerStats, ServerStat } from './state/apis'; export const ServerStats = () => { const [stats, setStats] = useState(null); const [isLoading, setIsLoading] = useState(false); const styles = useStyles2(getStyles); const hasAccessToDataSources = contextSrv.hasAccess(AccessControlAction.DataSourcesRead, contextSrv.isGrafanaAdmin); const hasAccessToAdminUsers = contextSrv.hasAccess(AccessControlAction.UsersRead, contextSrv.isGrafanaAdmin); useEffect(() => { if (contextSrv.hasAccess(AccessControlAction.ActionServerStatsRead, contextSrv.isGrafanaAdmin)) { setIsLoading(true); getServerStats().then((stats) => { setStats(stats); setIsLoading(false); }); } }, []); if (!contextSrv.hasAccess(AccessControlAction.ActionServerStatsRead, contextSrv.isGrafanaAdmin)) { return null; } return ( <>

Instance statistics

{isLoading ? (
) : stats ? (
Manage dashboards } />
Manage data sources ) } /> Alerts } />
Manage users ) } />
) : (

No stats found.

)} {config.featureToggles.dashboardPreviews && config.featureToggles.dashboardPreviewsAdmin && } {config.featureToggles.export && } ); }; const getStyles = (theme: GrafanaTheme2) => { return { title: css` margin-bottom: ${theme.spacing(4)}; `, row: css` display: flex; justify-content: space-between; width: 100%; & > div:not(:last-of-type) { margin-right: ${theme.spacing(2)}; } & > div { width: 33.3%; } `, doubleRow: css` display: flex; flex-direction: column; & > div:first-of-type { margin-bottom: ${theme.spacing(2)}; } `, loader: css` height: 290px; `, notFound: css` font-size: ${theme.typography.h6.fontSize}; text-align: center; height: 290px; `, }; }; type StatCardProps = { content: Array>; footer?: JSX.Element | boolean; }; const StatCard = ({ content, footer }: StatCardProps) => { const styles = useStyles2(getCardStyles); return (
{content.map((item) => { return (
{item.name} {item.value}
); })}
{footer &&
{footer}
}
); }; const getCardStyles = (theme: GrafanaTheme2) => { return { container: css` padding: ${theme.spacing(2)}; `, inner: css` display: flex; flex-direction: column; width: 100%; `, content: css` flex: 1 0 auto; `, row: css` display: flex; justify-content: space-between; width: 100%; margin-bottom: ${theme.spacing(2)}; align-items: center; `, }; };