2021-09-23 15:43:43 +05:30
|
|
|
import { Select, Space } from 'antd';
|
|
|
|
|
import Graph from 'components/Graph';
|
2021-08-26 11:50:47 +05:30
|
|
|
import React, { useEffect, useState } from 'react';
|
2021-10-20 09:24:55 +05:30
|
|
|
import { connect, useSelector } from 'react-redux';
|
2021-11-22 16:13:14 +05:30
|
|
|
import { GetService, getUsageData, usageDataItem } from 'store/actions';
|
2021-08-26 11:50:47 +05:30
|
|
|
import { servicesListItem } from 'store/actions/MetricsActions';
|
2021-09-23 15:43:43 +05:30
|
|
|
import { AppState } from 'store/reducers';
|
2021-08-26 11:50:47 +05:30
|
|
|
import { isOnboardingSkipped } from 'utils/app';
|
2021-02-21 06:02:06 +05:30
|
|
|
const { Option } = Select;
|
2021-10-20 09:24:55 +05:30
|
|
|
import { GlobalTime } from 'types/actions/globalTime';
|
|
|
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
2021-11-22 16:13:14 +05:30
|
|
|
import MetricReducer from 'types/reducer/metrics';
|
2021-10-20 09:24:55 +05:30
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
import { Card } from './styles';
|
2021-01-03 18:15:44 +05:30
|
|
|
|
|
|
|
|
interface UsageExplorerProps {
|
2021-01-18 02:18:49 +05:30
|
|
|
usageData: usageDataItem[];
|
2021-11-22 12:26:20 +05:30
|
|
|
getUsageData: (
|
|
|
|
|
minTime: number,
|
|
|
|
|
maxTime: number,
|
2021-12-02 20:32:08 +05:30
|
|
|
selectedInterval: number,
|
2021-11-22 12:26:20 +05:30
|
|
|
selectedService: string,
|
|
|
|
|
) => void;
|
2021-11-22 16:13:14 +05:30
|
|
|
getServicesList: ({
|
|
|
|
|
selectedTimeInterval,
|
|
|
|
|
}: {
|
|
|
|
|
selectedTimeInterval: GlobalReducer['selectedTime'];
|
|
|
|
|
}) => void;
|
2021-01-18 02:18:49 +05:30
|
|
|
globalTime: GlobalTime;
|
2021-02-21 06:02:06 +05:30
|
|
|
servicesList: servicesListItem[];
|
|
|
|
|
totalCount: number;
|
2021-01-03 18:15:44 +05:30
|
|
|
}
|
2021-02-21 06:02:06 +05:30
|
|
|
const timeDaysOptions = [
|
2021-08-26 11:50:47 +05:30
|
|
|
{ value: 30, label: 'Last 30 Days' },
|
|
|
|
|
{ value: 7, label: 'Last week' },
|
|
|
|
|
{ value: 1, label: 'Last day' },
|
2021-02-21 06:02:06 +05:30
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const interval = [
|
2021-02-21 06:23:56 +05:30
|
|
|
{
|
|
|
|
|
value: 604800,
|
|
|
|
|
chartDivideMultiplier: 1,
|
2021-08-26 11:50:47 +05:30
|
|
|
label: 'Weekly',
|
2021-02-21 06:23:56 +05:30
|
|
|
applicableOn: [timeDaysOptions[0]],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 86400,
|
|
|
|
|
chartDivideMultiplier: 30,
|
2021-08-26 11:50:47 +05:30
|
|
|
label: 'Daily',
|
2021-02-21 06:23:56 +05:30
|
|
|
applicableOn: [timeDaysOptions[0], timeDaysOptions[1]],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 3600,
|
|
|
|
|
chartDivideMultiplier: 10,
|
2021-08-26 11:50:47 +05:30
|
|
|
label: 'Hours',
|
2021-02-21 06:23:56 +05:30
|
|
|
applicableOn: [timeDaysOptions[2], timeDaysOptions[1]],
|
|
|
|
|
},
|
2021-02-21 06:02:06 +05:30
|
|
|
];
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2021-11-22 12:26:20 +05:30
|
|
|
const _UsageExplorer = (props: UsageExplorerProps): JSX.Element => {
|
2021-02-21 06:23:56 +05:30
|
|
|
const [selectedTime, setSelectedTime] = useState(timeDaysOptions[1]);
|
|
|
|
|
const [selectedInterval, setSelectedInterval] = useState(interval[2]);
|
2021-08-26 11:50:47 +05:30
|
|
|
const [selectedService, setSelectedService] = useState<string>('');
|
2021-11-22 16:13:14 +05:30
|
|
|
const { selectedTime: globalSelectedTime } = useSelector<
|
|
|
|
|
AppState,
|
|
|
|
|
GlobalReducer
|
|
|
|
|
>((state) => state.globalTime);
|
2021-11-22 12:26:20 +05:30
|
|
|
const {
|
|
|
|
|
getServicesList,
|
|
|
|
|
getUsageData,
|
|
|
|
|
globalTime,
|
|
|
|
|
totalCount,
|
|
|
|
|
usageData,
|
|
|
|
|
} = props;
|
2021-11-22 16:13:14 +05:30
|
|
|
const { services } = useSelector<AppState, MetricReducer>(
|
|
|
|
|
(state) => state.metrics,
|
|
|
|
|
);
|
2021-05-23 15:40:48 +05:30
|
|
|
|
2021-02-21 06:02:06 +05:30
|
|
|
useEffect(() => {
|
2021-02-21 06:23:56 +05:30
|
|
|
if (selectedTime && selectedInterval) {
|
|
|
|
|
const maxTime = new Date().getTime() * 1000000;
|
|
|
|
|
const minTime = maxTime - selectedTime.value * 24 * 3600000 * 1000000;
|
|
|
|
|
|
2021-11-22 12:26:20 +05:30
|
|
|
getUsageData(minTime, maxTime, selectedInterval.value, selectedService);
|
2021-02-21 06:02:06 +05:30
|
|
|
}
|
2021-11-22 12:26:20 +05:30
|
|
|
}, [selectedTime, selectedInterval, selectedService, getUsageData]);
|
2021-02-21 06:02:06 +05:30
|
|
|
|
2021-01-18 02:18:49 +05:30
|
|
|
useEffect(() => {
|
2021-11-22 16:13:14 +05:30
|
|
|
getServicesList({
|
|
|
|
|
selectedTimeInterval: globalSelectedTime,
|
|
|
|
|
});
|
|
|
|
|
}, [globalTime, getServicesList, globalSelectedTime]);
|
2021-02-21 06:02:06 +05:30
|
|
|
|
2021-01-18 02:18:49 +05:30
|
|
|
const data = {
|
2021-11-22 12:26:20 +05:30
|
|
|
labels: usageData.map((s) => new Date(s.timestamp / 1000000)),
|
2021-01-18 02:18:49 +05:30
|
|
|
datasets: [
|
|
|
|
|
{
|
2021-08-26 11:50:47 +05:30
|
|
|
label: 'Span Count',
|
2021-11-22 12:26:20 +05:30
|
|
|
data: usageData.map((s) => s.count),
|
2021-08-26 11:50:47 +05:30
|
|
|
backgroundColor: 'rgba(255, 99, 132, 0.2)',
|
|
|
|
|
borderColor: 'rgba(255, 99, 132, 1)',
|
2021-01-18 02:18:49 +05:30
|
|
|
borderWidth: 2,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2021-01-18 02:18:49 +05:30
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
2021-02-21 06:23:56 +05:30
|
|
|
<Space style={{ marginTop: 40, marginLeft: 20 }}>
|
2021-02-21 06:02:06 +05:30
|
|
|
<Space>
|
2021-02-21 06:23:56 +05:30
|
|
|
<Select
|
2021-11-22 12:26:20 +05:30
|
|
|
onSelect={(value): void => {
|
2021-02-21 06:23:56 +05:30
|
|
|
setSelectedTime(
|
|
|
|
|
timeDaysOptions.filter((item) => item.value == parseInt(value))[0],
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
value={selectedTime.label}
|
|
|
|
|
>
|
|
|
|
|
{timeDaysOptions.map(({ value, label }) => (
|
2021-11-22 12:26:20 +05:30
|
|
|
<Option key={value} value={value}>
|
|
|
|
|
{label}
|
|
|
|
|
</Option>
|
2021-02-21 06:02:06 +05:30
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
</Space>
|
2021-02-21 06:23:56 +05:30
|
|
|
<Space>
|
|
|
|
|
<Select
|
2021-11-22 12:26:20 +05:30
|
|
|
onSelect={(value): void => {
|
2021-02-21 06:23:56 +05:30
|
|
|
setSelectedInterval(
|
2021-11-22 12:26:20 +05:30
|
|
|
interval.filter((item) => item.value === parseInt(value))[0],
|
2021-02-21 06:23:56 +05:30
|
|
|
);
|
|
|
|
|
}}
|
2021-11-22 12:26:20 +05:30
|
|
|
value={selectedInterval.label}
|
2021-02-21 06:23:56 +05:30
|
|
|
>
|
|
|
|
|
{interval
|
2021-11-22 12:26:20 +05:30
|
|
|
.filter((interval) => interval.applicableOn.includes(selectedTime))
|
2021-02-21 06:23:56 +05:30
|
|
|
.map((item) => (
|
2021-11-22 12:26:20 +05:30
|
|
|
<Option key={item.label} value={item.value}>
|
|
|
|
|
{item.label}
|
|
|
|
|
</Option>
|
2021-02-21 06:23:56 +05:30
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
</Space>
|
2021-02-21 06:02:06 +05:30
|
|
|
|
|
|
|
|
<Space>
|
2021-02-21 06:23:56 +05:30
|
|
|
<Select
|
2021-11-22 12:26:20 +05:30
|
|
|
onSelect={(value): void => {
|
2021-02-21 06:23:56 +05:30
|
|
|
setSelectedService(value);
|
|
|
|
|
}}
|
2021-08-26 11:50:47 +05:30
|
|
|
value={selectedService || 'All Services'}
|
2021-02-21 06:23:56 +05:30
|
|
|
>
|
2021-08-26 11:50:47 +05:30
|
|
|
<Option value={''}>All Services</Option>
|
2021-11-22 16:13:14 +05:30
|
|
|
{services?.map((service) => (
|
2021-11-22 12:26:20 +05:30
|
|
|
<Option key={service.serviceName} value={service.serviceName}>
|
|
|
|
|
{service.serviceName}
|
|
|
|
|
</Option>
|
2021-02-21 06:23:56 +05:30
|
|
|
))}
|
2021-02-21 06:02:06 +05:30
|
|
|
</Select>
|
|
|
|
|
</Space>
|
|
|
|
|
|
2021-11-22 12:26:20 +05:30
|
|
|
{isOnboardingSkipped() && totalCount === 0 ? (
|
2021-02-21 06:23:56 +05:30
|
|
|
<Space
|
|
|
|
|
style={{
|
2021-08-26 11:50:47 +05:30
|
|
|
width: '100%',
|
|
|
|
|
margin: '40px 0',
|
2021-02-21 06:23:56 +05:30
|
|
|
marginLeft: 20,
|
2021-08-26 11:50:47 +05:30
|
|
|
justifyContent: 'center',
|
2021-02-21 06:23:56 +05:30
|
|
|
}}
|
|
|
|
|
>
|
2021-02-21 06:02:06 +05:30
|
|
|
No spans found. Please add instrumentation (follow this
|
2021-02-21 06:23:56 +05:30
|
|
|
<a
|
2021-08-26 11:50:47 +05:30
|
|
|
href={'https://signoz.io/docs/instrumentation/overview'}
|
|
|
|
|
target={'_blank'}
|
2021-02-21 06:23:56 +05:30
|
|
|
style={{ marginLeft: 3 }}
|
2021-08-26 11:50:47 +05:30
|
|
|
rel="noreferrer"
|
2021-02-21 06:23:56 +05:30
|
|
|
>
|
|
|
|
|
guide
|
|
|
|
|
</a>
|
|
|
|
|
)
|
|
|
|
|
</Space>
|
|
|
|
|
) : (
|
2021-08-26 11:50:47 +05:30
|
|
|
<Space style={{ display: 'block', marginLeft: 20, width: 200 }}>
|
2021-11-22 12:26:20 +05:30
|
|
|
{`Total count is ${totalCount}`}
|
2021-02-21 06:02:06 +05:30
|
|
|
</Space>
|
2021-02-21 06:23:56 +05:30
|
|
|
)}
|
2021-02-21 06:02:06 +05:30
|
|
|
</Space>
|
|
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
<Card>
|
|
|
|
|
<Graph data={data} type="bar" />
|
2021-01-18 02:18:49 +05:30
|
|
|
</Card>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
};
|
2021-01-03 18:15:44 +05:30
|
|
|
|
2021-01-18 02:18:49 +05:30
|
|
|
const mapStateToProps = (
|
2021-09-23 15:43:43 +05:30
|
|
|
state: AppState,
|
2021-02-21 06:23:56 +05:30
|
|
|
): {
|
|
|
|
|
totalCount: number;
|
|
|
|
|
globalTime: GlobalTime;
|
|
|
|
|
usageData: usageDataItem[];
|
|
|
|
|
} => {
|
2021-02-21 06:02:06 +05:30
|
|
|
let totalCount = 0;
|
2021-08-26 11:50:47 +05:30
|
|
|
for (const item of state.usageDate) {
|
2021-02-21 06:23:56 +05:30
|
|
|
totalCount = totalCount + item.count;
|
2021-02-21 06:02:06 +05:30
|
|
|
}
|
2021-02-21 06:23:56 +05:30
|
|
|
return {
|
|
|
|
|
totalCount: totalCount,
|
|
|
|
|
usageData: state.usageDate,
|
|
|
|
|
globalTime: state.globalTime,
|
|
|
|
|
};
|
2021-01-03 18:15:44 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const UsageExplorer = connect(mapStateToProps, {
|
2021-01-18 02:18:49 +05:30
|
|
|
getUsageData: getUsageData,
|
2021-11-22 16:13:14 +05:30
|
|
|
getServicesList: GetService,
|
2021-01-18 02:18:49 +05:30
|
|
|
})(_UsageExplorer);
|