-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Does not work currently, as everything is behind a super secret API.
- Loading branch information
Showing
14 changed files
with
684 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ declare -a arr=( | |
"WorkspacesApi" | ||
"DevelopersApi" | ||
"AccessApi" | ||
"MetricsApi" | ||
) | ||
|
||
for i in "${arr[@]}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/react/src/components/Metrics/MetricsLineChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import { Stack, Typography } from '@mui/joy'; | ||
import { XAxis, YAxis, LineChart, Line, Tooltip, Legend } from 'recharts'; | ||
import { format } from 'date-fns'; | ||
import { LineProps } from 'recharts'; | ||
import { FilterMetricsRequest } from '@theniledev/js'; | ||
|
||
import { useMetrics } from './hooks'; | ||
|
||
export enum DataKeys { | ||
timestamp = 'timestamp', | ||
value = 'value', | ||
instanceId = 'instanceId', | ||
attributes = 'attributes', | ||
} | ||
|
||
export type MetricsComponentProps = { | ||
height?: number; | ||
width?: number; | ||
timeFormat?: 'string'; | ||
line?: LineProps; | ||
}; | ||
|
||
export default function MetricsLineChart( | ||
props: FilterMetricsRequest & MetricsComponentProps | ||
): React.ReactElement | null { | ||
const { | ||
filter, | ||
width = 500, | ||
height = 300, | ||
timeFormat = 'HH:ss', | ||
line = { type: 'monotone', stroke: '#82ca9d' }, | ||
} = props; | ||
const { isLoading, metrics } = useMetrics(props); | ||
const metricName = filter.metricName; | ||
|
||
if (isLoading) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Stack> | ||
<Typography level="h4">{metricName}</Typography> | ||
<LineChart data={metrics} width={width} height={height}> | ||
<Legend /> | ||
<Tooltip /> | ||
<XAxis | ||
dataKey={DataKeys.timestamp} | ||
tickFormatter={(time: string | Date): string => { | ||
if (time instanceof Date) { | ||
return format(time, timeFormat); | ||
} | ||
return time; | ||
}} | ||
/> | ||
<YAxis /> | ||
{/* eslint-disable-next-line @typescript-eslint/no-explicit-any*/} | ||
<Line dataKey={DataKeys.value} {...(line as any)} /> | ||
</LineChart> | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { | ||
Filter, | ||
FilterMetricsRequest, | ||
Measurement, | ||
Metric, | ||
} from '@theniledev/js'; | ||
|
||
import { useNile } from '../../context'; | ||
import Queries, { useQuery } from '../../lib/queries'; | ||
|
||
type Props = FilterMetricsRequest; | ||
type UseMetricsReturn = { | ||
isLoading: boolean; | ||
metrics: Measurement[]; | ||
}; | ||
|
||
export const useMetrics = (props?: Props): UseMetricsReturn => { | ||
const nile = useNile(); | ||
|
||
const filter: void | Filter = props?.filter; | ||
|
||
// API does not like this currently | ||
if (filter && filter.metricName === '') { | ||
delete filter.metricName; | ||
} | ||
|
||
const { data: fetchedData = [], isLoading } = useQuery( | ||
[Queries.FilterMetrics(JSON.stringify(filter))], | ||
() => | ||
nile.metrics.filterMetrics({ | ||
...props, | ||
filter: filter ? filter : {}, | ||
}), | ||
{ enabled: Boolean(nile.workspace && nile.authToken) } | ||
); | ||
|
||
const flatMetrics = React.useMemo( | ||
() => | ||
fetchedData?.flatMap((metric: Metric) => { | ||
return metric.measurements; | ||
}), | ||
[fetchedData] | ||
); | ||
|
||
return { isLoading, metrics: flatMetrics }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { useMetrics } from './hooks'; | ||
export { default as MetricsLineChart } from './MetricsLineChart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// Button.stories.ts|tsx | ||
|
||
import React from 'react'; | ||
import { Meta, Story } from '@storybook/react'; | ||
|
||
|
Oops, something went wrong.