Projet

Général

Profil

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

root / plugins / proxmox / proxmox_vm_count @ c1854c05

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

1 c1854c05 Michael Grote
#!/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
Unknown license
22
23
=head1 MAGIC MARKERS
24
=begin comment
25
These magic markers are used by munin-node-configure when installing
26
munin-node.
27
=end comment
28
  #%# family=auto
29
  #%# capabilities=autoconf suggest
30
=cut
31
32
EOF
33
34
35
if [ "$1" = "autoconf" ]; then
36
    if ! command -v qm &> /dev/null; then
37
        echo "[ERROR] qm could not be found!"
38
    elif ! command -v pct &> /dev/null; then
39
        echo "[ERROR] pct could not be found!"
40
    else
41
        echo "yes"
42
    fi
43
    exit 0
44
fi
45
46
# hole Variablen nur einmal
47
wqmlist=$(qm list)
48
wpctlist=$(pct list)
49
50
# Berechne VMs
51
total_vm=$(echo "$wqmlist" | sed 1d | wc -l)
52
running_vm=$(echo "$wqmlist" | sed 1d | grep -c running)
53
stopped_vm=$(echo "$wqmlist" | sed 1d | grep -c stopped)
54
total_lxc=$(echo "$wpctlist" | sed 1d | wc -l)
55
running_lxc=$(echo "$wpctlist" | sed 1d | grep -c running)
56
stopped_lxc=$(echo "$wpctlist" | sed 1d | grep -c stopped)
57
58
# Berechne Gesamtwert
59
total=$((total_vm + total_lxc))
60
61
if [ "$1" = "config" ]; then
62
    # setze label
63
    echo total_vm.label total Virtual Machines
64
    echo total.label total VMs and LXCs
65
66
    echo running_vm.label running Virtual Machines
67
    echo running_lxc.label running LXCs
68
69
    echo stopped_vm.label stopped Virtual Machines
70
    echo stopped_lxc.label stopped LXCs
71
72
    echo total_lxc.label total LXCs
73
74
    # setze optionen
75
    echo 'graph_title ProxMox - Number of VMs and LXCs'
76
    echo 'graph_vlabel Count'
77
    echo 'graph_category virtualization'
78
    echo 'graph_args -l 0'
79
    exit 0
80
fi
81
echo total.value "$total"
82
83
echo total_vm.value "$total_vm"
84
echo total_lxc.value "$total_lxc"
85
86
echo running_vm.value "$running_vm"
87
echo running_lxc.value "$running_lxc"
88
89
echo stopped_vm.value "$stopped_vm"
90
echo stopped_lxc.value "$stopped_lxc"
91
exit 0