From 307795493a64e4317e2ad173699806e2610dcb2f Mon Sep 17 00:00:00 2001 From: cortices Date: Fri, 1 Jan 2021 14:11:32 +1100 Subject: [PATCH 1/5] Add openstack_swift_stats_ plugin --- .../openstack_swift/openstack_swift_stats_ | 69 +++++++++++++++++ .../openstack_swift_stats_.pod | 77 +++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100755 plugins/openstack_swift/openstack_swift_stats_ create mode 100644 plugins/openstack_swift/openstack_swift_stats_.pod diff --git a/plugins/openstack_swift/openstack_swift_stats_ b/plugins/openstack_swift/openstack_swift_stats_ new file mode 100755 index 00000000..90addcff --- /dev/null +++ b/plugins/openstack_swift/openstack_swift_stats_ @@ -0,0 +1,69 @@ +#!/bin/bash + +ME="${0##*/}" +CONTAINER=$(printf "$ME" | cut -d'_' -f4 -) +# printf "$CONTAINER\n" + +case $1 in + config) + cat <=3&&NR<=4 {print $2}' FS=": " ORS=" ") ) + +# Size graph +printf "multigraph openstack_swift_stats_size\n" + +# Check value is an integer. +[ -n "${STAT_OUTPUT[1]}" ] && [ "${STAT_OUTPUT[1]}" -eq "${STAT_OUTPUT[1]}" ] 2>/dev/null +if [ $? -ne 0 ]; then + printf "size.value 0\n" + printf "Error: no usable size value from swift command.\n" 1>&2 + exit 1 +fi + +printf "size.value ${STAT_OUTPUT[1]}\ngrowth.value ${STAT_OUTPUT[1]}\n" + +# Objects graph +printf "multigraph openstack_swift_stats_objects\n" + +[ -n "${STAT_OUTPUT[0]}" ] && [ "${STAT_OUTPUT[0]}" -eq "${STAT_OUTPUT[0]}" ] 2>/dev/null +if [ $? -ne 0 ]; then + printf "objects.value 0\n" + printf "Error: no usable objects value from swift command.\n" 1>&2 + exit 1 +fi + +printf "objects.value ${STAT_OUTPUT[0]}\nobjgrowth.value ${STAT_OUTPUT[0]}\n" + + diff --git a/plugins/openstack_swift/openstack_swift_stats_.pod b/plugins/openstack_swift/openstack_swift_stats_.pod new file mode 100644 index 00000000..432a6cce --- /dev/null +++ b/plugins/openstack_swift/openstack_swift_stats_.pod @@ -0,0 +1,77 @@ +=cut + +=head1 NAME + +openstack_swift_stats_ -- Plugin to monitor size of OpenStack Swift containers + +=head1 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) + +=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. + +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 + +Configuration example for OVH: + +[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}} + +=head1 USAGE + +- Place the plugin in your plugins storage directory (/usr/share/munin/plugins) +- 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) +- 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. +- Add the OS_PASSWORD value for the chosen user. + +=head1 AUTHOR + +Copyright (C) 2020 Sophie Parker (dev@cortices.me) + +=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 \ No newline at end of file From 099d7821d926fa7ebf0c11f499deec4e84548aae Mon Sep 17 00:00:00 2001 From: cortices Date: Sat, 2 Jan 2021 20:31:50 +1100 Subject: [PATCH 2/5] Apply shellcheck recommendations --- plugins/openstack_swift/openstack_swift_stats_ | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/openstack_swift/openstack_swift_stats_ b/plugins/openstack_swift/openstack_swift_stats_ index 90addcff..154e3c31 100755 --- a/plugins/openstack_swift/openstack_swift_stats_ +++ b/plugins/openstack_swift/openstack_swift_stats_ @@ -1,7 +1,7 @@ #!/bin/bash ME="${0##*/}" -CONTAINER=$(printf "$ME" | cut -d'_' -f4 -) +CONTAINER=$(printf "%s" "$ME" | cut -d'_' -f4 -) # printf "$CONTAINER\n" case $1 in @@ -39,31 +39,29 @@ EOM esac IFS=" " -STAT_OUTPUT=( $(swift stat $CONTAINER | awk 'NR>=3&&NR<=4 {print $2}' FS=": " ORS=" ") ) +STAT_OUTPUT=( $(swift stat "$CONTAINER" | awk 'NR>=3&&NR<=4 {print $2}' FS=": " ORS=" ") ) # Size graph printf "multigraph openstack_swift_stats_size\n" # Check value is an integer. -[ -n "${STAT_OUTPUT[1]}" ] && [ "${STAT_OUTPUT[1]}" -eq "${STAT_OUTPUT[1]}" ] 2>/dev/null -if [ $? -ne 0 ]; then +if [ -z "${STAT_OUTPUT[1]}" ] || [ "${STAT_OUTPUT[1]}" != "${STAT_OUTPUT[1]}" ] 2>/dev/null; then printf "size.value 0\n" printf "Error: no usable size value from swift command.\n" 1>&2 exit 1 fi -printf "size.value ${STAT_OUTPUT[1]}\ngrowth.value ${STAT_OUTPUT[1]}\n" +printf "size.value %s\ngrowth.value %s\n" "${STAT_OUTPUT[1]}" "${STAT_OUTPUT[1]}" # Objects graph printf "multigraph openstack_swift_stats_objects\n" -[ -n "${STAT_OUTPUT[0]}" ] && [ "${STAT_OUTPUT[0]}" -eq "${STAT_OUTPUT[0]}" ] 2>/dev/null -if [ $? -ne 0 ]; then +if [ -z "${STAT_OUTPUT[0]}" ] || [ "${STAT_OUTPUT[0]}" != "${STAT_OUTPUT[0]}" ] 2>/dev/null; then printf "objects.value 0\n" printf "Error: no usable objects value from swift command.\n" 1>&2 exit 1 fi -printf "objects.value ${STAT_OUTPUT[0]}\nobjgrowth.value ${STAT_OUTPUT[0]}\n" +printf "objects.value %s\nobjgrowth.value %s\n" "${STAT_OUTPUT[0]}" "${STAT_OUTPUT[0]}" From 4ed6c56f28f06ff3f9811da0d611595ae05d96bf Mon Sep 17 00:00:00 2001 From: s0 <_@s0.is> Date: Thu, 15 Jul 2021 17:52:56 +1000 Subject: [PATCH 3/5] Refactor script to pure POSIX sh compliance. Also includes recommended fixes --- plugins/openstack/openstack_swift_stats_ | 147 ++++++++++++++++++ .../openstack_swift/openstack_swift_stats_ | 67 -------- .../openstack_swift_stats_.pod | 77 --------- 3 files changed, 147 insertions(+), 144 deletions(-) create mode 100755 plugins/openstack/openstack_swift_stats_ delete mode 100755 plugins/openstack_swift/openstack_swift_stats_ delete mode 100644 plugins/openstack_swift/openstack_swift_stats_.pod diff --git a/plugins/openstack/openstack_swift_stats_ b/plugins/openstack/openstack_swift_stats_ new file mode 100755 index 00000000..abe4cc68 --- /dev/null +++ b/plugins/openstack/openstack_swift_stats_ @@ -0,0 +1,147 @@ +#!/bin/sh + +#=begin +# +#=head1 NAME +# +#openstack_swift_stats_ -- Plugin to monitor size of OpenStack Swift containers +# +#=head1 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) +# +#=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. +# +#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 +# +#Configuration example for OVH: +# +#[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}} +# +#=head1 USAGE +# +#- Place the plugin in your plugins storage directory (/usr/share/munin/plugins) +#- 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) +#- 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. +#- Add the OS_PASSWORD value for the chosen user. +# +#=head1 AUTHOR +# +#Copyright (C) 2020 Sophie Parker (dev@cortices.me) +# +#=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 +# +#=end +# + + +# 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 <=3&&NR<=4 {print $2}' FS=": " ORS=" ") ) - -# Size graph -printf "multigraph openstack_swift_stats_size\n" - -# Check value is an integer. -if [ -z "${STAT_OUTPUT[1]}" ] || [ "${STAT_OUTPUT[1]}" != "${STAT_OUTPUT[1]}" ] 2>/dev/null; then - printf "size.value 0\n" - printf "Error: no usable size value from swift command.\n" 1>&2 - exit 1 -fi - -printf "size.value %s\ngrowth.value %s\n" "${STAT_OUTPUT[1]}" "${STAT_OUTPUT[1]}" - -# Objects graph -printf "multigraph openstack_swift_stats_objects\n" - -if [ -z "${STAT_OUTPUT[0]}" ] || [ "${STAT_OUTPUT[0]}" != "${STAT_OUTPUT[0]}" ] 2>/dev/null; then - printf "objects.value 0\n" - printf "Error: no usable objects value from swift command.\n" 1>&2 - exit 1 -fi - -printf "objects.value %s\nobjgrowth.value %s\n" "${STAT_OUTPUT[0]}" "${STAT_OUTPUT[0]}" - - diff --git a/plugins/openstack_swift/openstack_swift_stats_.pod b/plugins/openstack_swift/openstack_swift_stats_.pod deleted file mode 100644 index 432a6cce..00000000 --- a/plugins/openstack_swift/openstack_swift_stats_.pod +++ /dev/null @@ -1,77 +0,0 @@ -=cut - -=head1 NAME - -openstack_swift_stats_ -- Plugin to monitor size of OpenStack Swift containers - -=head1 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) - -=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. - -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 - -Configuration example for OVH: - -[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}} - -=head1 USAGE - -- Place the plugin in your plugins storage directory (/usr/share/munin/plugins) -- 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) -- 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. -- Add the OS_PASSWORD value for the chosen user. - -=head1 AUTHOR - -Copyright (C) 2020 Sophie Parker (dev@cortices.me) - -=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 \ No newline at end of file From e70f572eebfc44a44217f495487a5761bde7911d Mon Sep 17 00:00:00 2001 From: s0 <_@s0.is> Date: Thu, 15 Jul 2021 19:55:24 +1000 Subject: [PATCH 4/5] Fix copy-paste bug where objects graph was never updated. --- plugins/openstack/openstack_swift_stats_ | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/openstack/openstack_swift_stats_ b/plugins/openstack/openstack_swift_stats_ index abe4cc68..070a516b 100755 --- a/plugins/openstack/openstack_swift_stats_ +++ b/plugins/openstack/openstack_swift_stats_ @@ -106,7 +106,7 @@ growth.min 0 multigraph openstack_swift_stats_objects graph_title Swift container object count ($CONTAINER) graph_category cloud -graph_vlabel +graph_vlabel graph_args --base=1000 -l 0 graph_period hour objects.label Objects @@ -142,6 +142,6 @@ printf "multigraph openstack_swift_stats_objects\n" case $OBJECTS_COUNT in (*[!0-9]*|'') printf "U\n";; # Emit magic error value - (*) printf "size.value %s\ngrowth.value %s\n" "$OBJECTS_COUNT" "$OBJECTS_COUNT";; + (*) printf "objects.value %s\nobjgrowth.value %s\n" "$OBJECTS_COUNT" "$OBJECTS_COUNT";; esac From 181f3ed9709fbf3f49eff2339f85438bfd0a23ef Mon Sep 17 00:00:00 2001 From: s0 <_@s0.is> Date: Fri, 16 Jul 2021 19:03:47 +1000 Subject: [PATCH 5/5] Fix pod doc in header of file --- plugins/openstack/openstack_swift_stats_ | 184 +++++++++++++---------- 1 file changed, 106 insertions(+), 78 deletions(-) diff --git a/plugins/openstack/openstack_swift_stats_ b/plugins/openstack/openstack_swift_stats_ index 070a516b..4542e40b 100755 --- a/plugins/openstack/openstack_swift_stats_ +++ b/plugins/openstack/openstack_swift_stats_ @@ -1,83 +1,111 @@ #!/bin/sh -#=begin -# -#=head1 NAME -# -#openstack_swift_stats_ -- Plugin to monitor size of OpenStack Swift containers -# -#=head1 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) -# -#=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. -# -#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 -# -#Configuration example for OVH: -# -#[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}} -# -#=head1 USAGE -# -#- Place the plugin in your plugins storage directory (/usr/share/munin/plugins) -#- 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) -#- 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. -#- Add the OS_PASSWORD value for the chosen user. -# -#=head1 AUTHOR -# -#Copyright (C) 2020 Sophie Parker (dev@cortices.me) -# -#=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 -# -#=end -# +: <<=cut + + +=head1 NAME + +B -- 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 + +
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
+
+ +=end html + +Configuration example for OVH: + +=begin html + +
[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}}
+
+ +=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 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.