/
CheckUsage.tsx
59 lines (56 loc) · 1.96 KB
/
CheckUsage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { FC } from 'react';
import { useFormContext } from 'react-hook-form';
import { calculateUsage } from '../checkUsageCalc';
import { css } from 'emotion';
import { GrafanaTheme } from '@grafana/data';
import { useStyles, Icon } from '@grafana/ui';
import { CheckFormValues } from 'types';
const getStyles = (theme: GrafanaTheme) => ({
container: css`
background-color: ${theme.colors.bg2};
padding: ${theme.spacing.lg};
margin-bottom: ${theme.spacing.md};
`,
header: css`
margin-bottom: ${theme.spacing.md};
`,
icon: css`
margin-right: ${theme.spacing.sm};
`,
section: css`
margin-bottom: ${theme.spacing.sm};
`,
value: css`
margin-left: ${theme.spacing.xs};
`,
});
export const CheckUsage: FC = () => {
const styles = useStyles(getStyles);
const { watch } = useFormContext();
const { checkType, frequency, probes }: Partial<CheckFormValues> = watch(['checkType', 'frequency', 'probes']);
if (!checkType?.value || !frequency || !probes) {
return null;
}
const { checksPerMonth, activeSeries, logsGbPerMonth } = calculateUsage({
probeCount: probes.length,
frequencySeconds: frequency,
checkType: checkType.value,
});
return (
<div className={styles.container}>
<h5 className={styles.header}>Approximate expected usage for this check</h5>
<div className={styles.section}>
<Icon className={styles.icon} name={'calendar-alt'} />
Checks per month: <strong className={styles.value}>{checksPerMonth.toLocaleString()}</strong>
</div>
<div className={styles.section}>
<Icon className={styles.icon} name={'chart-line'} />
Active series: <strong className={styles.value}>{activeSeries.toLocaleString()}</strong>
</div>
<div className={styles.section}>
<Icon className={styles.icon} name={'database'} />
Log usage per month (GB): <strong className={styles.value}>{logsGbPerMonth.toLocaleString()}</strong>
</div>
</div>
);
};