Repository
Munin (contrib)
Last change
2021-07-16
Graph Categories
Family
manual
Capabilities
Keywords
Language
Shell
Authors

openstack_swift_stats_

Name

openstack_swift_stats_ – Plugin to monitor size of OpenStack Swift containers

About

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

  • Size in bytes
  • Growth in size per graph period (hour by default)
  • Number of objects
  • Growth in objects per graph period (hour by default)

Configuration

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

Configuration example for OVH:

  env.OS_TENANT_ID {{Redacted}}
  env.OS_TENANT_NAME {{Redacted}}
  env.OS_USERNAME user-{{Redacted}}
  env.OS_PASSWORD {{Redacted}}
</pre></code>

Usage

    1. Place the plugin in your plugins storage directory (/usr/share/munin/plugins)
    1. Symlink it into the active plugins directory (/etc/munin/plugins) with the name of your container after the last underscore (e.g. ln -s /usr/share/munin/plugins/openstack_swift_stats_ /etc/munin/plugins/openstack_swift_stats_mycontainer)
    1. 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.
    1. Add the OS_PASSWORD value for the chosen user (OS as in OpenStack, not Operating System).

Author

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

License

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

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

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

Magic Markers

#%# family=manual

#!/bin/sh

: <<=cut


=head1 NAME

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

=head1 ABOUT

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

=over

=item * Size in bytes

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

=item * Number of objects

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

=back

=head1 CONFIGURATION

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

=begin html

<pre><code>OS_AUTH_URL
OS_IDENTITY_API_VERSION
OS_REGION_NAME
OS_USER_DOMAIN_NAME
OS_PROJECT_DOMAIN_NAME
OS_TENANT_ID
OS_TENANT_NAME
OS_USERNAME
OS_PASSWORD
</pre></code>

=end html

Configuration example for OVH:

=begin html

<pre><code>[openstack_swift_size_*]
  env.OS_AUTH_URL https://auth.cloud.ovh.net/v3/
  env.OS_IDENTITY_API_VERSION 3
  env.OS_REGION_NAME SYD
  env.OS_USER_DOMAIN_NAME Default
  env.OS_PROJECT_DOMAIN_NAME Default
  
  env.OS_TENANT_ID {{Redacted}}
  env.OS_TENANT_NAME {{Redacted}}
  env.OS_USERNAME user-{{Redacted}}
  env.OS_PASSWORD {{Redacted}}
</pre></code>

=end html

=head1 USAGE

=over

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

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

=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.

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

=back

=head1 AUTHOR

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

=head1 LICENSE

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

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

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

=head1 MAGIC MARKERS

#%# family=manual

=cut






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

# Config for two graphs -- size and objects count.
case $1 in
   config)
        cat <<EOM
multigraph openstack_swift_stats_size
graph_title Swift container size ($CONTAINER)
graph_category cloud
graph_vlabel bytes
graph_args --base=1024 -l 0
graph_period hour
size.label Size
size.type GAUGE
size.draw AREA
size.min 0
growth.label Growth/\${graph_period}
growth.type DERIVE
growth.min 0

multigraph openstack_swift_stats_objects
graph_title Swift container object count ($CONTAINER)
graph_category cloud
graph_vlabel  
graph_args --base=1000 -l 0
graph_period hour
objects.label Objects
objects.type GAUGE
objects.draw AREA
objects.min 0
objgrowth.label Growth/\${graph_period}
objgrowth.type DERIVE
objgrowth.min 0
EOM
        exit 0;;
esac

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

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

# Size graph
printf "multigraph openstack_swift_stats_size\n"

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


# Objects graph
printf "multigraph openstack_swift_stats_objects\n"

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