mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
* dynamically determine path prefix Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * minor changes per PR review Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * use Context for apiPath and pathPrefix Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * remove unhandled "/version" path Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * only process index once instead of on every req Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * remove unneeded tag fragment Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * switch api path to const Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * revert Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * update tests Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * linter updates Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * simplify Signed-off-by: James Ranson <james_ranson@cable.comcast.com> * updates per peer review Signed-off-by: James Ranson <james_ranson@cable.comcast.com>
29 lines
1 KiB
TypeScript
29 lines
1 KiB
TypeScript
import React, { FC } from 'react';
|
|
import { RouteComponentProps } from '@reach/router';
|
|
import { useFetch } from '../../hooks/useFetch';
|
|
import { withStatusIndicator } from '../../components/withStatusIndicator';
|
|
import AlertsContent, { RuleStatus, AlertsProps } from './AlertContents';
|
|
import { usePathPrefix } from '../../contexts/PathPrefixContext';
|
|
import { API_PATH } from '../../constants/constants';
|
|
|
|
const AlertsWithStatusIndicator = withStatusIndicator(AlertsContent);
|
|
|
|
const Alerts: FC<RouteComponentProps> = () => {
|
|
const pathPrefix = usePathPrefix();
|
|
const { response, error, isLoading } = useFetch<AlertsProps>(`${pathPrefix}/${API_PATH}/rules?type=alert`);
|
|
|
|
const ruleStatsCount: RuleStatus<number> = {
|
|
inactive: 0,
|
|
pending: 0,
|
|
firing: 0,
|
|
};
|
|
|
|
if (response.data && response.data.groups) {
|
|
response.data.groups.forEach(el => el.rules.forEach(r => ruleStatsCount[r.state]++));
|
|
}
|
|
|
|
return <AlertsWithStatusIndicator {...response.data} statsCount={ruleStatsCount} error={error} isLoading={isLoading} />;
|
|
};
|
|
|
|
export default Alerts;
|