Projet

Général

Profil

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

root / plugins / openstack / openstack_swift_stats_ @ 181f3ed9

Historique | Voir | Annoter | Télécharger (4,33 ko)

1
#!/bin/sh
2

    
3
: <<=cut
4

    
5

    
6
=head1 NAME
7

    
8
B<openstack_swift_stats_> -- Plugin to monitor size of OpenStack Swift containers
9

    
10
=head1 ABOUT
11

    
12
Multigraph plugin. Graphs the following statistics about an OpenStack Swift container:
13

    
14
=over
15

    
16
=item * Size in bytes
17

    
18
=item * Growth in size per graph period (hour by default)
19

    
20
=item * Number of objects
21

    
22
=item * Growth in objects per graph period (hour by default)
23

    
24
=back
25

    
26
=head1 CONFIGURATION
27

    
28
Configuration values are mandatory. Names are identical to the environment values used by the Swift commands and passed directly to it.
29
They can be copied from the openrc.sh file provided by your OpenStack hosting provider, along with the password.
30

    
31
=begin html
32

    
33
<pre><code>OS_AUTH_URL
34
OS_IDENTITY_API_VERSION
35
OS_REGION_NAME
36
OS_USER_DOMAIN_NAME
37
OS_PROJECT_DOMAIN_NAME
38
OS_TENANT_ID
39
OS_TENANT_NAME
40
OS_USERNAME
41
OS_PASSWORD
42
</pre></code>
43

    
44
=end html
45

    
46
Configuration example for OVH:
47

    
48
=begin html
49

    
50
<pre><code>[openstack_swift_size_*]
51
  env.OS_AUTH_URL https://auth.cloud.ovh.net/v3/
52
  env.OS_IDENTITY_API_VERSION 3
53
  env.OS_REGION_NAME SYD
54
  env.OS_USER_DOMAIN_NAME Default
55
  env.OS_PROJECT_DOMAIN_NAME Default
56
  
57
  env.OS_TENANT_ID {{Redacted}}
58
  env.OS_TENANT_NAME {{Redacted}}
59
  env.OS_USERNAME user-{{Redacted}}
60
  env.OS_PASSWORD {{Redacted}}
61
</pre></code>
62

    
63
=end html
64

    
65
=head1 USAGE
66

    
67
=over
68

    
69
=item 1. Place the plugin in your plugins storage directory (/usr/share/munin/plugins)
70

    
71
=item 2. Symlink it into the active plugins directory (/etc/munin/plugins) with the name of your container after the last underscore
72
  (e.g. ln -s /usr/share/munin/plugins/openstack_swift_stats_ /etc/munin/plugins/openstack_swift_stats_mycontainer)
73

    
74
=item 3. Copy the OpenStack login environment variables from the openrc.sh file provided by your hosting provider to your plugin config file as shown in the configuration section.
75

    
76
=item 4. Add the C<OS_PASSWORD> value for the chosen user (OS as in OpenStack, not Operating System).
77

    
78
=back
79

    
80
=head1 AUTHOR
81

    
82
Copyright (C) 2020 Sophie Parker (cortices@github)
83

    
84
=head1 LICENSE
85

    
86
This program is free software; you can redistribute it and/or
87
modify it under the terms of the GNU General Public License
88
as published by the Free Software Foundation; version 2 dated June,
89
1991.
90

    
91
This program is distributed in the hope that it will be useful,
92
but WITHOUT ANY WARRANTY; without even the implied warranty of
93
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
94
GNU General Public License for more details.
95

    
96
You should have received a copy of the GNU General Public License
97
along with this program; if not, write to the Free Software
98
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
99

    
100
=head1 MAGIC MARKERS
101

    
102
#%# family=manual
103

    
104
=cut
105

    
106

    
107

    
108

    
109

    
110

    
111
# Get container to check by splitting off end of filename.
112
ME="${0##*/}"
113
CONTAINER=$(printf "%s" "$ME" | cut -d'_' -f4 -)
114
# printf "$CONTAINER\n"
115

    
116
# Config for two graphs -- size and objects count.
117
case $1 in
118
   config)
119
        cat <<EOM
120
multigraph openstack_swift_stats_size
121
graph_title Swift container size ($CONTAINER)
122
graph_category cloud
123
graph_vlabel bytes
124
graph_args --base=1024 -l 0
125
graph_period hour
126
size.label Size
127
size.type GAUGE
128
size.draw AREA
129
size.min 0
130
growth.label Growth/\${graph_period}
131
growth.type DERIVE
132
growth.min 0
133

    
134
multigraph openstack_swift_stats_objects
135
graph_title Swift container object count ($CONTAINER)
136
graph_category cloud
137
graph_vlabel  
138
graph_args --base=1000 -l 0
139
graph_period hour
140
objects.label Objects
141
objects.type GAUGE
142
objects.draw AREA
143
objects.min 0
144
objgrowth.label Growth/\${graph_period}
145
objgrowth.type DERIVE
146
objgrowth.min 0
147
EOM
148
        exit 0;;
149
esac
150

    
151
# Regular invocation
152
# Use `swift stat` command line tool to get container stats.
153

    
154
STATS_RAW=$(swift stat "$CONTAINER")
155
OBJECTS_COUNT=$(printf "%s" "$STATS_RAW" | awk 'NR==3 {print $2}' IFS=" " FS=": ")
156
OBJECTS_SIZE=$(printf "%s" "$STATS_RAW" | awk 'NR==4 {print $2}' IFS=" " FS=": ")
157

    
158
# Size graph
159
printf "multigraph openstack_swift_stats_size\n"
160

    
161
# Check value is an integer.
162
case $OBJECTS_SIZE in
163
    (*[!0-9]*|'')   printf "U\n";;    # Emit magic error value
164
    (*)             printf "size.value %s\ngrowth.value %s\n" "$OBJECTS_SIZE" "$OBJECTS_SIZE";;
165
esac
166

    
167

    
168
# Objects graph
169
printf "multigraph openstack_swift_stats_objects\n"
170

    
171
case $OBJECTS_COUNT in
172
    (*[!0-9]*|'')   printf "U\n";;    # Emit magic error value
173
    (*)             printf "objects.value %s\nobjgrowth.value %s\n" "$OBJECTS_COUNT" "$OBJECTS_COUNT";;
174
esac
175