Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add host panels to L0 dsahboard #190

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 80 additions & 4 deletions jsonnet/dashboards/monitoring.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ local getClusterRowGridY(numOfClusters, panelWidth, panelHeight) =
*/
getGridY(2 + panelHeight, numOfClusters - 1, panelWidth, panelHeight);

local getHostRowGridY(numOfHosts, panelWidth, panelHeightHosts, panelHeightClusters) =
/**
* Compute grid Y coordinate of services row based on number of hosts.
*
* @param index The index of host.
* @return grid Y coordinate as number.
*/
getGridY(3 + panelHeightHosts + panelHeightClusters, numOfHosts - 1, panelWidth, panelHeightHosts);

{
grafanaDashboards+::

Expand All @@ -67,10 +76,13 @@ local getClusterRowGridY(numOfClusters, panelWidth, panelHeight) =
local numOfClusters =
if $.isClusterMonitoring() then std.length($._config.clusterMonitoring.clusters) else 0;

local numOfHosts =
if $.isHostMonitoring() then std.length($._config.hostMonitoring.hosts) else 0;

local getUid(defaultUid, obj, templateGroup) =
if $.isAnyDefault([obj], templateGroup) then defaultUid else $.getCustomUid([defaultUid, obj.name]);

if $.isClusterMonitoring() then
if $.isHostMonitoring() || $.isClusterMonitoring() then
{
monitoring:
local dNationLink =
Expand All @@ -83,6 +95,54 @@ local getClusterRowGridY(numOfClusters, panelWidth, panelHeight) =
targetBlank=true,
);

local hostPanel(index, host) = [

local panelHeight = tpl.panel.gridPos.h;
local panelWidth = tpl.panel.gridPos.w;

local gridX =
if std.type(tpl.panel.gridPos.x) == 'number' then
tpl.panel.gridPos.x
else
getGridX(index, panelWidth);

local gridY =
if std.type(tpl.panel.gridPos.y) == 'number' then
tpl.panel.gridPos.y
else
getGridY(getClusterRowGridY(numOfClusters, $._config.templates.L0.k8s.main.panel.gridPos.w, $._config.templates.L0.k8s.main.panel.gridPos.h), index, panelWidth, panelHeight);

statPanel.new(
title='Host %s' % host.name,
datasource=tpl.panel.datasource,
graphMode=tpl.panel.graphMode,
colorMode=tpl.panel.colorMode,
unit=tpl.panel.unit,
decimals=tpl.panel.decimals,
)
.addTarget({ type: 'single', instant: true, expr: tpl.panel.expr % { job: std.join('|', $.getAlertJobs(host)), groupHost: $._config.prometheusRules.alertGroupHost, groupHostApp: $._config.prometheusRules.alertGroupHostApp, maxWarnings: maxWarnings } })
.addThresholds($.grafanaThresholds(tpl.panel.thresholds))
.addMappings(tpl.panel.mappings)
.addDataLinks(
$.updateDataLinksCommonArgs(
if std.length(tpl.panel.dataLinks) > 0 then
tpl.panel.dataLinks % { job: host.jobName }
else
[{ title: 'Host Monitoring', url: '/d/%s?%s&var-job=%s' % [getUid($._config.grafanaDashboards.ids.hostMonitoring, host, $._config.templates.L1.host), $._config.grafanaDashboards.dataLinkCommonArgsNoCluster, host.jobName] }]
)
)
{
gridPos: {
x: gridX,
y: gridY,
w: panelWidth,
h: panelHeight,
},
}
for tpl in $.getTemplates($._config.templates.L0.host, host)
if (std.objectHas(tpl, 'panel') && tpl.panel != {})
];

local clusterPanel(index, cluster) = [

local panelHeight = tpl.panel.gridPos.h;
Expand Down Expand Up @@ -168,8 +228,8 @@ local getClusterRowGridY(numOfClusters, panelWidth, panelHeight) =
if std.type(tpl.panel.gridPos.y) == 'number' then
tpl.panel.gridPos.y
else
getClusterRowGridY(
numOfClusters, $._config.templates.L0.k8s.main.panel.gridPos.w, $._config.templates.L0.k8s.main.panel.gridPos.h
getHostRowGridY(
numOfHosts, $._config.templates.L0.host.main.panel.gridPos.w, $._config.templates.L0.host.main.panel.gridPos.h, $._config.templates.L0.k8s.main.panel.gridPos.h
);

statPanel.new(
Expand Down Expand Up @@ -211,6 +271,12 @@ local getClusterRowGridY(numOfClusters, panelWidth, panelHeight) =
if (std.objectHas(tpl, 'panel') && tpl.panel != {})
];

local hostPanels =
std.flattenArrays([
hostPanel(host.index, host.item)
for host in $.zipWithIndex($._config.hostMonitoring.hosts)
]);

local clusterPanels =
std.flattenArrays([
clusterPanel(cluster.index, cluster.item)
Expand Down Expand Up @@ -238,10 +304,20 @@ local getClusterRowGridY(numOfClusters, panelWidth, panelHeight) =
[row.new('Clusters') { gridPos: { x: 0, y: 0, w: 24, h: 1 } }] + clusterPanels
else []
) +
(
if $.isHostMonitoring() then
[
row.new('Hosts') {
local rowY = getClusterRowGridY(numOfClusters, $._config.templates.L0.k8s.main.panel.gridPos.w, $._config.templates.L0.k8s.main.panel.gridPos.h) - 1,
gridPos: { x: 0, y: rowY, w: 24, h: 1 },
},
] + hostPanels
else []
) +
(
if $.isBlackBoxMonitoring() then
[row.new('Services') {
local rowY = getClusterRowGridY(numOfClusters, $._config.templates.L0.k8s.main.panel.gridPos.w, $._config.templates.L0.k8s.main.panel.gridPos.h) - 1,
local rowY = getHostRowGridY(numOfHosts, $._config.templates.L0.host.main.panel.gridPos.w, $._config.templates.L0.host.main.panel.gridPos.h, $._config.templates.L0.k8s.main.panel.gridPos.h) - 1,
gridPos: { x: 0, y: rowY, w: 24, h: 1 },
}] + blackBoxPanels
else []
Expand Down
Loading