mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
feat: change columns for active queries (#4676)
This commit is contained in:
parent
15e1d16afc
commit
02a182e2a1
4 changed files with 28 additions and 25 deletions
|
@ -14,7 +14,7 @@ import PreviewIcons from "./components/Main/Icons/PreviewIcons";
|
||||||
import WithTemplate from "./pages/WithTemplate";
|
import WithTemplate from "./pages/WithTemplate";
|
||||||
import Relabel from "./pages/Relabel";
|
import Relabel from "./pages/Relabel";
|
||||||
import ExploreLogs from "./pages/ExploreLogs/ExploreLogs";
|
import ExploreLogs from "./pages/ExploreLogs/ExploreLogs";
|
||||||
import from "./pages/ActiveQueries";
|
import ActiveQueries from "./pages/ActiveQueries";
|
||||||
|
|
||||||
const App: FC = () => {
|
const App: FC = () => {
|
||||||
const [loadedTheme, setLoadedTheme] = useState(false);
|
const [loadedTheme, setLoadedTheme] = useState(false);
|
||||||
|
|
|
@ -11,6 +11,8 @@ import classNames from "classnames";
|
||||||
import Button from "../../components/Main/Button/Button";
|
import Button from "../../components/Main/Button/Button";
|
||||||
import { RefreshIcon } from "../../components/Main/Icons";
|
import { RefreshIcon } from "../../components/Main/Icons";
|
||||||
import "./style.scss";
|
import "./style.scss";
|
||||||
|
import { DATE_TIME_FORMAT } from "../../constants/date";
|
||||||
|
import { roundStep } from "../../utils/time";
|
||||||
|
|
||||||
const ActiveQueries: FC = () => {
|
const ActiveQueries: FC = () => {
|
||||||
const { isMobile } = useDeviceDetect();
|
const { isMobile } = useDeviceDetect();
|
||||||
|
@ -18,28 +20,30 @@ const ActiveQueries: FC = () => {
|
||||||
|
|
||||||
const { data, lastUpdated, isLoading, error, fetchData } = useFetchActiveQueries();
|
const { data, lastUpdated, isLoading, error, fetchData } = useFetchActiveQueries();
|
||||||
|
|
||||||
const activeQueries = useMemo(() => data.map(({ duration, ...item }: ActiveQueriesType) => ({
|
const activeQueries = useMemo(() => data.map((item: ActiveQueriesType) => {
|
||||||
duration,
|
const from = dayjs(item.start).tz().format(DATE_TIME_FORMAT);
|
||||||
|
const to = dayjs(item.end).tz().format(DATE_TIME_FORMAT);
|
||||||
|
return {
|
||||||
|
duration: item.duration,
|
||||||
|
remote_addr: item.remote_addr,
|
||||||
|
query: item.query,
|
||||||
|
args: `${from} to ${to}, step=${roundStep(item.step)}`,
|
||||||
data: JSON.stringify(item, null, 2),
|
data: JSON.stringify(item, null, 2),
|
||||||
from: dayjs(item.start).tz().format("MMM DD, YYYY \nHH:mm:ss.SSS"),
|
} as ActiveQueriesType;
|
||||||
to: dayjs(item.end).tz().format("MMM DD, YYYY \nHH:mm:ss.SSS"),
|
}), [data, timezone]);
|
||||||
...item,
|
|
||||||
})), [data, timezone]);
|
|
||||||
|
|
||||||
const columns = useMemo(() => {
|
const columns = useMemo(() => {
|
||||||
if (!activeQueries?.length) return [];
|
if (!activeQueries?.length) return [];
|
||||||
const hideColumns = ["end", "start", "data"];
|
const keys = Object.keys(activeQueries[0]) as (keyof ActiveQueriesType)[];
|
||||||
const keys = new Set<string>();
|
|
||||||
for (const item of activeQueries) {
|
const titles: Partial<Record<keyof ActiveQueriesType, string>> = {
|
||||||
for (const key in item) {
|
remote_addr: "client address",
|
||||||
keys.add(key);
|
};
|
||||||
}
|
const hideColumns = ["data"];
|
||||||
}
|
|
||||||
return Array.from(keys)
|
return keys.filter((col) => !hideColumns.includes(col)).map((key) => ({
|
||||||
.filter((col) => !hideColumns.includes(col))
|
key: key,
|
||||||
.map((key) => ({
|
title: titles[key] || key,
|
||||||
key: key as keyof ActiveQueriesType,
|
|
||||||
title: key,
|
|
||||||
}));
|
}));
|
||||||
}, [activeQueries]);
|
}, [activeQueries]);
|
||||||
|
|
||||||
|
@ -76,7 +80,7 @@ const ActiveQueries: FC = () => {
|
||||||
<Table
|
<Table
|
||||||
rows={activeQueries}
|
rows={activeQueries}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
defaultOrderBy={"from"}
|
defaultOrderBy={"duration"}
|
||||||
copyToClipboard={"data"}
|
copyToClipboard={"data"}
|
||||||
paginationOffset={{ startIndex: 0, endIndex: Infinity }}
|
paginationOffset={{ startIndex: 0, endIndex: Infinity }}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -147,7 +147,6 @@ export interface ActiveQueriesType {
|
||||||
query: string;
|
query: string;
|
||||||
remote_addr: string;
|
remote_addr: string;
|
||||||
step: number;
|
step: number;
|
||||||
from?: string;
|
args?: string;
|
||||||
to?: string;
|
|
||||||
data?: string;
|
data?: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ const shortDurations = supportedDurations.map(d => d.short);
|
||||||
|
|
||||||
export const roundToMilliseconds = (num: number): number => Math.round(num*1000)/1000;
|
export const roundToMilliseconds = (num: number): number => Math.round(num*1000)/1000;
|
||||||
|
|
||||||
const roundStep = (step: number) => {
|
export const roundStep = (step: number) => {
|
||||||
let result = roundToMilliseconds(step);
|
let result = roundToMilliseconds(step);
|
||||||
const integerStep = Math.round(step);
|
const integerStep = Math.round(step);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue