Skip to content

Commit

Permalink
Add Projects to Node Top consumers
Browse files Browse the repository at this point in the history
  • Loading branch information
rawagner committed Apr 15, 2020
1 parent 8578428 commit 33a1414
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DashboardCardTitle from '@console/shared/src/components/dashboard/dashboa
import UtilizationBody from '@console/shared/src/components/dashboard/utilization-card/UtilizationBody';
import { ByteDataTypes } from '@console/shared/src/graph-helper/data-utils';
import { getNodeAddresses } from '@console/shared/src/selectors/node';
import { PodModel } from '@console/internal/models';
import { PodModel, ProjectModel } from '@console/internal/models';
import {
humanizeCpuCores,
humanizeBinaryBytes,
Expand Down Expand Up @@ -43,6 +43,12 @@ const getPodConsumers = (query: string, nodeName: string) => ({
metric: 'pod',
});

const getProjectConsumers = (query: string) => ({
query,
model: ProjectModel,
metric: 'namespace',
});

export const CPUPopover: React.FC<PopoverProps> = ({
nodeName,
nodeIp,
Expand All @@ -53,7 +59,10 @@ export const CPUPopover: React.FC<PopoverProps> = ({
}) => {
const consumers = React.useMemo(() => {
const queries = getTopConsumerQueries(nodeIp);
return [getPodConsumers(queries[NodeQueries.PODS_BY_CPU], nodeName)];
return [
getProjectConsumers(queries[NodeQueries.PROJECTS_BY_CPU]),
getPodConsumers(queries[NodeQueries.PODS_BY_CPU], nodeName),
];
}, [nodeIp, nodeName]);
return (
<ConsumerPopover
Expand All @@ -78,7 +87,10 @@ export const MemoryPopover: React.FC<PopoverProps> = ({
}) => {
const consumers = React.useMemo(() => {
const queries = getTopConsumerQueries(nodeIp);
return [getPodConsumers(queries[NodeQueries.PODS_BY_MEMORY], nodeName)];
return [
getProjectConsumers(queries[NodeQueries.PROJECTS_BY_MEMORY]),
getPodConsumers(queries[NodeQueries.PODS_BY_MEMORY], nodeName),
];
}, [nodeIp, nodeName]);
return (
<ConsumerPopover
Expand Down Expand Up @@ -109,9 +121,18 @@ const UtilizationCard: React.FC = () => {
getMultilineQueries(nodeName),
getResourceQutoaQueries(nodeName),
[
[getPodConsumers(topConsumerQueries[NodeQueries.PODS_BY_FILESYSTEM], nodeName)],
[getPodConsumers(topConsumerQueries[NodeQueries.PODS_BY_NETWORK_IN], nodeName)],
[getPodConsumers(topConsumerQueries[NodeQueries.PODS_BY_NETWORK_OUT], nodeName)],
[
getProjectConsumers(topConsumerQueries[NodeQueries.PROJECTS_BY_FILESYSTEM]),
getPodConsumers(topConsumerQueries[NodeQueries.PODS_BY_FILESYSTEM], nodeName),
],
[
getProjectConsumers(topConsumerQueries[NodeQueries.PROJECTS_BY_NETWORK_IN]),
getPodConsumers(topConsumerQueries[NodeQueries.PODS_BY_NETWORK_IN], nodeName),
],
[
getProjectConsumers(topConsumerQueries[NodeQueries.PROJECTS_BY_NETWORK_OUT]),
getPodConsumers(topConsumerQueries[NodeQueries.PODS_BY_NETWORK_OUT], nodeName),
],
],
];
}, [nodeIp, nodeName]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export enum NodeQueries {
PODS_BY_FILESYSTEM = 'PODS_BY_FILESYSTEM',
PODS_BY_NETWORK_IN = 'PODS_BY_NETWORK_IN',
PODS_BY_NETWORK_OUT = 'PODS_BY_NETWORK_OUT',
PROJECTS_BY_CPU = 'PROJECTS_BY_CPU',
PROJECTS_BY_MEMORY = 'PROJECTS_BY_MEMORY',
PROJECTS_BY_FILESYSTEM = 'PROJECTS_BY_FILESYSTEM',
PROJECTS_BY_NETWORK_IN = 'PROJECTS_BY_NETWORK_IN',
PROJECTS_BY_NETWORK_OUT = 'PROJECTS_BY_NETWORK_OUT',
FILESYSTEM_USAGE = 'FILESYSTEM_USAGE',
FILESYSTEM_TOTAL = 'FILESYSTEM_TOTAL',
NETWORK_IN_UTILIZATION = 'NETWORK_IN_UTILIZATION',
Expand Down Expand Up @@ -59,6 +64,21 @@ const top25Queries = {
[NodeQueries.PODS_BY_NETWORK_OUT]: _.template(
`topk(25, sort_desc(sum(rate(container_network_transmit_bytes_total{ container="POD", pod!= "", instance=~'<%= ipAddress %>:.*'}[5m])) BY (pod, namespace)))`,
),
[NodeQueries.PROJECTS_BY_CPU]: _.template(
`topk(25, sort_desc(sum(rate(container_cpu_usage_seconds_total{container="",pod!="", instance=~'<%= ipAddress %>:.*'}[5m])) by (namespace)))`,
),
[NodeQueries.PROJECTS_BY_MEMORY]: _.template(
`topk(25, sort_desc(sum(avg_over_time(container_memory_working_set_bytes{container="",pod!="",instance=~'<%= ipAddress %>:.*'}[5m])) BY (namespace)))`,
),
[NodeQueries.PROJECTS_BY_FILESYSTEM]: _.template(
`topk(25, sort_desc(sum(container_fs_usage_bytes{instance=~'<%= ipAddress %>:.*'}) BY (namespace)))`,
),
[NodeQueries.PROJECTS_BY_NETWORK_IN]: _.template(
`topk(25, sort_desc(sum(rate(container_network_receive_bytes_total{ container="POD", pod!= "", instance=~'<%= ipAddress %>:.*'}[5m])) BY (namespace)))`,
),
[NodeQueries.PROJECTS_BY_NETWORK_OUT]: _.template(
`topk(25, sort_desc(sum(rate(container_network_transmit_bytes_total{ container="POD", pod!= "", instance=~'<%= ipAddress %>:.*'}[5m])) BY (namespace)))`,
),
};

const resourceQuotaQueries = {
Expand Down Expand Up @@ -128,4 +148,15 @@ export const getTopConsumerQueries = (ipAddress: string) => ({
[NodeQueries.PODS_BY_NETWORK_OUT]: top25Queries[NodeQueries.PODS_BY_NETWORK_OUT]({
ipAddress,
}),
[NodeQueries.PROJECTS_BY_CPU]: top25Queries[NodeQueries.PROJECTS_BY_CPU]({ ipAddress }),
[NodeQueries.PROJECTS_BY_MEMORY]: top25Queries[NodeQueries.PROJECTS_BY_MEMORY]({ ipAddress }),
[NodeQueries.PROJECTS_BY_FILESYSTEM]: top25Queries[NodeQueries.PROJECTS_BY_FILESYSTEM]({
ipAddress,
}),
[NodeQueries.PROJECTS_BY_NETWORK_IN]: top25Queries[NodeQueries.PROJECTS_BY_NETWORK_IN]({
ipAddress,
}),
[NodeQueries.PROJECTS_BY_NETWORK_OUT]: top25Queries[NodeQueries.PROJECTS_BY_NETWORK_OUT]({
ipAddress,
}),
});

0 comments on commit 33a1414

Please sign in to comment.