Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / proxmox / proxmox_vm_count @ 86f20791

Historique | Voir | Annoter | Télécharger (2,11 ko)

1
#!/bin/bash
2
#%# family=auto
3

    
4
: << EOF
5
=head1 NAME
6
proxmox_vm_count - Outputs the running, stopped and total counts of ProxMox VMs and LXCs.
7

    
8
=head1 CONFIGURATION
9
This plugin needs to run as the root user in order to have permission to run lvs and vgs
10
  [proxmox_vm_count]
11
  [proxmox_count]
12
  user root
13
  group root
14

    
15
=head1 AUTHOR
16
=over 4
17
=item * Michael Grote
18
=back
19

    
20
=head1 LICENSE
21
GPLv3 or later
22

    
23
SPDX-License-Identifier: GPL-3.0-or-later
24

    
25
=head1 MAGIC MARKERS
26
=begin comment
27
These magic markers are used by munin-node-configure when installing
28
munin-node.
29
=end comment
30
  #%# family=auto
31
  #%# capabilities=autoconf suggest
32
=cut
33

    
34
EOF
35

    
36

    
37
if [ "$1" = "autoconf" ]; then
38
    if ! command -v qm &> /dev/null; then
39
        echo "[ERROR] qm could not be found!"
40
    elif ! command -v pct &> /dev/null; then
41
        echo "[ERROR] pct could not be found!"
42
    else
43
        echo "yes"
44
    fi
45
    exit 0
46
fi
47

    
48
# hole Variablen nur einmal
49
wqmlist=$(qm list)
50
wpctlist=$(pct list)
51

    
52
# Berechne VMs
53
total_vm=$(echo "$wqmlist" | sed 1d | wc -l)
54
running_vm=$(echo "$wqmlist" | sed 1d | grep -c running)
55
stopped_vm=$(echo "$wqmlist" | sed 1d | grep -c stopped)
56
total_lxc=$(echo "$wpctlist" | sed 1d | wc -l)
57
running_lxc=$(echo "$wpctlist" | sed 1d | grep -c running)
58
stopped_lxc=$(echo "$wpctlist" | sed 1d | grep -c stopped)
59

    
60
# Berechne Gesamtwert
61
total=$((total_vm + total_lxc))
62

    
63
if [ "$1" = "config" ]; then
64
    # setze label
65
    echo total_vm.label total Virtual Machines
66
    echo total.label total VMs and LXCs
67

    
68
    echo running_vm.label running Virtual Machines
69
    echo running_lxc.label running LXCs
70

    
71
    echo stopped_vm.label stopped Virtual Machines
72
    echo stopped_lxc.label stopped LXCs
73

    
74
    echo total_lxc.label total LXCs
75

    
76
    # setze optionen
77
    echo 'graph_title ProxMox - Number of VMs and LXCs'
78
    echo 'graph_vlabel Count'
79
    echo 'graph_category virtualization'
80
    echo 'graph_args -l 0'
81
    exit 0
82
fi
83
echo total.value "$total"
84

    
85
echo total_vm.value "$total_vm"
86
echo total_lxc.value "$total_lxc"
87

    
88
echo running_vm.value "$running_vm"
89
echo running_lxc.value "$running_lxc"
90

    
91
echo stopped_vm.value "$stopped_vm"
92
echo stopped_lxc.value "$stopped_lxc"
93
exit 0