From bc0edccfa0b6e33d6ed147fef4e3349ecedd028a Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Fri, 8 Jan 2021 13:04:22 +0100 Subject: [PATCH] Add guest counter for PVE cluster and node Also update the Zabbix template to handle those new counters GLPI #47604 --- zabbix_scripts/check_pve_sudo | 22 +++ zabbix_templates/Template_App_PVE_Cluster.xml | 238 ++++++++++++++++++++++---- 2 files changed, 230 insertions(+), 30 deletions(-) diff --git a/zabbix_scripts/check_pve_sudo b/zabbix_scripts/check_pve_sudo index 2875727..6d3e877 100644 --- a/zabbix_scripts/check_pve_sudo +++ b/zabbix_scripts/check_pve_sudo @@ -51,6 +51,12 @@ if ($cluster){ read => 0, write => 0 }; + $json->{guests} = { + qemu => 0, + qemu_running => 0, + lxc => 0, + lxc_running => 0 + }; my @nodes = (); foreach my $item (@{$cluster}){ if ($item->{type} eq 'cluster'){ @@ -79,11 +85,27 @@ if ($cluster){ $json->{network}->{out} += $guest->{netout} || 0; $json->{disk}->{read} += $guest->{diskread} || 0; $json->{disk}->{write} += $guest->{diskwrite} || 0; + my $type = $guest->{type}; + $json->{guests}->{$type}++; + $json->{guests}->{$type . '_running'}++ if ($guest->{status} eq 'running'); } } elsif ($node){ + $json->{guests} = { + qemu => 0, + qemu_running => 0, + lxc => 0, + lxc_running => 0 + }; foreach my $item (qw(status version subscription)){ $json->{$item} = get_api_data("/nodes/$node/$item"); } + my $guests = get_api_data('/cluster/resources', '--type=vm'); + foreach my $guest (@{$guests}){ + next if ($guest->{node} ne $node); + my $type = $guest->{type}; + $json->{guests}->{$type}++; + $json->{guests}->{$type . '_running'}++ if ($guest->{status} eq 'running'); + } } elsif ($guest){ my $guests = get_api_data('/cluster/resources', '--type=vm'); foreach my $g (@{$guests}){ diff --git a/zabbix_templates/Template_App_PVE_Cluster.xml b/zabbix_templates/Template_App_PVE_Cluster.xml index 449f0e6..209a8b2 100644 --- a/zabbix_templates/Template_App_PVE_Cluster.xml +++ b/zabbix_templates/Template_App_PVE_Cluster.xml @@ -1,7 +1,7 @@ - 4.4 - 2020-03-02T15:26:38Z + 5.0 + 2021-01-08T12:03:11Z Templates @@ -201,6 +201,50 @@ POST + PVE Cluster: Number of LXC guests + DEPENDENT + pve.check[cluster,lxc] + 0 + 1825d + !container(s) + + + Vitualization + + + + + JSONPATH + $.guests.lxc + + + + pve.check.all[cluster] + + + + PVE Cluster: Number of running LXC guests + DEPENDENT + pve.check[cluster,lxc_running] + 0 + 1825d + !container(s) + + + Vitualization + + + + + JSONPATH + $.guests.lxc_running + + + + pve.check.all[cluster] + + + PVE Cluster: Free memory DEPENDENT pve.check[cluster,mem_free] @@ -368,6 +412,50 @@ + PVE Cluster: Number of QEMU guests + DEPENDENT + pve.check[cluster,qemu] + 0 + 1825d + !vm + + + Vitualization + + + + + JSONPATH + $.guests.qemu + + + + pve.check.all[cluster] + + + + PVE Cluster: Number of running QEMU guests + DEPENDENT + pve.check[cluster,qemu_running] + 0 + 1825d + !vm + + + Vitualization + + + + + JSONPATH + $.guests.qemu_running + + + + pve.check.all[cluster] + + + PVE Cluster: Quorate DEPENDENT pve.check[cluster,quorate] @@ -964,6 +1052,40 @@ POST + PVE Node: {#PVE_NODE_NAME} LXC guests + DEPENDENT + pve.check[node,{#PVE_NODE_NAME},lxc] + 0 + 1825d + !container(s) + + + JSONPATH + $.guests.lxc + + + + pve.check.all[node,{#PVE_NODE_NAME}] + + + + PVE Node: {#PVE_NODE_NAME} running LXC guests + DEPENDENT + pve.check[node,{#PVE_NODE_NAME},lxc_running] + 0 + 1825d + !container(s) + + + JSONPATH + $.guests.lxc_running + + + + pve.check.all[node,{#PVE_NODE_NAME}] + + + PVE Node: {#PVE_NODE_NAME} free memory DEPENDENT pve.check[node,{#PVE_NODE_NAME},mem_free] @@ -1055,6 +1177,40 @@ POST + PVE Node: {#PVE_NODE_NAME} QEMU guests + DEPENDENT + pve.check[node,{#PVE_NODE_NAME},qemu] + 0 + 1825d + !vm + + + JSONPATH + $.guests.qemu + + + + pve.check.all[node,{#PVE_NODE_NAME}] + + + + PVE Node: {#PVE_NODE_NAME} running QEMU guests + DEPENDENT + pve.check[node,{#PVE_NODE_NAME},qemu_running] + 0 + 1825d + !vm + + + JSONPATH + $.guests.qemu_running + + + + pve.check.all[node,{#PVE_NODE_NAME}] + + + PVE Node: {#PVE_NODE_NAME} uptime DEPENDENT pve.check[node,{#PVE_NODE_NAME},uptime] @@ -1501,114 +1657,114 @@ - PVE: Pool: {#PVE_POOL_ID}: Disk space allocation - STACKED - FIXED + PVE: Pool: {#PVE_POOL_ID}: Disk I/O - 2774A4 + GRADIENT_LINE + 00BB00 Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},maxdisk] + pve.check[pool,{#PVE_POOL_ID},diskread] 1 - DD0000 + GRADIENT_LINE + EE0000 Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},template_maxdisk] + pve.check[pool,{#PVE_POOL_ID},diskwrite] - PVE: Pool: {#PVE_POOL_ID}: Trafic réseau + PVE: Pool: {#PVE_POOL_ID}: Disk space allocation + STACKED + FIXED - GRADIENT_LINE - 00AA00 + 2774A4 Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},netin] + pve.check[pool,{#PVE_POOL_ID},maxdisk] 1 - GRADIENT_LINE - FF9999 + DD0000 Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},netout] + pve.check[pool,{#PVE_POOL_ID},template_maxdisk] - PVE: Pool: {#PVE_POOL_ID} CPU usage + PVE: Pool: {#PVE_POOL_ID}: Memory usage FIXED GRADIENT_LINE - 000099 + 00AA00 Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},cpu] + pve.check[pool,{#PVE_POOL_ID},mem] 1 BOLD_LINE EE0000 - RIGHT Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},maxcpu] + pve.check[pool,{#PVE_POOL_ID},maxmem] - PVE: Pool: {#PVE_POOL_ID} Disk I/O + PVE: Pool: {#PVE_POOL_ID}: Trafic réseau GRADIENT_LINE - 00BB00 + 00AA00 Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},diskread] + pve.check[pool,{#PVE_POOL_ID},netin] 1 GRADIENT_LINE - EE0000 + FF9999 Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},diskwrite] + pve.check[pool,{#PVE_POOL_ID},netout] - PVE: Pool: {#PVE_POOL_ID} Memory usage + PVE: Pool: {#PVE_POOL_ID} CPU usage FIXED GRADIENT_LINE - 00AA00 + 000099 Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},mem] + pve.check[pool,{#PVE_POOL_ID},cpu] 1 BOLD_LINE EE0000 + RIGHT Template_App_PVE_Cluster - pve.check[pool,{#PVE_POOL_ID},maxmem] + pve.check[pool,{#PVE_POOL_ID},maxcpu] @@ -1824,6 +1980,28 @@ + PVE Cluster: Guests + STACKED + + + 1 + F63100 + + Template_App_PVE_Cluster + pve.check[cluster,lxc_running] + + + + 2 + 1A7C11 + + Template_App_PVE_Cluster + pve.check[cluster,qemu_running] + + + + + PVE Cluster: KSM shared memory