mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
3c6e0e8ef8
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { GrafanaTheme2, isLiveChannelMessageEvent, isLiveChannelStatusEvent, LiveChannelScope } from '@grafana/data';
|
|
import { getBackendSrv, getGrafanaLiveSrv } from '@grafana/runtime';
|
|
import { Button, useTheme2 } from '@grafana/ui';
|
|
|
|
import { CrawlerStartButton } from './CrawlerStartButton';
|
|
|
|
interface CrawlerStatusMessage {
|
|
state: string;
|
|
started: string;
|
|
finished: string;
|
|
complete: number;
|
|
queue: number;
|
|
last: string;
|
|
}
|
|
|
|
export const CrawlerStatus = () => {
|
|
const styles = getStyles(useTheme2());
|
|
const [status, setStatus] = useState<CrawlerStatusMessage>();
|
|
|
|
useEffect(() => {
|
|
const subscription = getGrafanaLiveSrv()
|
|
.getStream<CrawlerStatusMessage>({
|
|
scope: LiveChannelScope.Grafana,
|
|
namespace: 'broadcast',
|
|
path: 'crawler',
|
|
})
|
|
.subscribe({
|
|
next: (evt) => {
|
|
if (isLiveChannelMessageEvent(evt)) {
|
|
setStatus(evt.message);
|
|
} else if (isLiveChannelStatusEvent(evt)) {
|
|
setStatus(evt.message);
|
|
}
|
|
},
|
|
});
|
|
return () => {
|
|
subscription.unsubscribe();
|
|
};
|
|
}, []);
|
|
|
|
if (!status) {
|
|
return (
|
|
<div className={styles.wrap}>
|
|
No status (never run)
|
|
<br />
|
|
<CrawlerStartButton />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className={styles.wrap}>
|
|
<pre>{JSON.stringify(status, null, 2)}</pre>
|
|
{status.state !== 'running' && <CrawlerStartButton />}
|
|
{status.state !== 'stopped' && (
|
|
<Button
|
|
variant="secondary"
|
|
onClick={() => {
|
|
getBackendSrv().post('/api/admin/crawler/stop');
|
|
}}
|
|
>
|
|
Stop
|
|
</Button>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const getStyles = (theme: GrafanaTheme2) => {
|
|
return {
|
|
wrap: css`
|
|
border: 4px solid red;
|
|
`,
|
|
running: css`
|
|
border: 4px solid green;
|
|
`,
|
|
};
|
|
};
|