root / plugins / nextcloud / nextcloud_ @ 5c983dbc
Historique | Voir | Annoter | Télécharger (7,44 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# shellcheck shell=dash |
| 3 |
|
| 4 |
set -e |
| 5 |
|
| 6 |
: << =cut |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
nextcloud_ - Monitor usage of nextcloud instances |
| 11 |
|
| 12 |
=head1 APPLICABLE SYSTEMS |
| 13 |
|
| 14 |
Nexcloud instances |
| 15 |
|
| 16 |
=head1 CONFIGURATION |
| 17 |
|
| 18 |
Requires installed curl and jq, a command-line json processor. |
| 19 |
|
| 20 |
This is a wildcard plugin. To monitor a nextcloud instance, link |
| 21 |
nextcloud_<nextcloud-domain> to this file. You can even append a port |
| 22 |
(:8443) to the file if needed. For example, |
| 23 |
|
| 24 |
ln -s /usr/share/munin/plugins/nextcloud_ \ |
| 25 |
/etc/munin/plugins/nextcloud_cloud.domain.tld |
| 26 |
|
| 27 |
Set username and password in your munin-node configuration |
| 28 |
|
| 29 |
[nextcloud_cloud.domain.tld] |
| 30 |
env.username <nexcloud_user> |
| 31 |
env.password <nextcloud_password> |
| 32 |
env.api_path <default: /ocs/v2.php/apps/serverinfo/api/v1/info> |
| 33 |
env.scheme <default: https> |
| 34 |
env.timeout <default: 2s> |
| 35 |
env.updates_warning <default: 1> |
| 36 |
|
| 37 |
It's advised to set an app password (for this plugin) in your nextcloud |
| 38 |
instance and not to use the "real" password of your nextcloud user. |
| 39 |
|
| 40 |
=head1 AUTHOR |
| 41 |
|
| 42 |
Copyright (C) 2020 Sebastian L. (https://momou.ch), |
| 43 |
Olivier Mehani <shtrom+munin@ssji.net> |
| 44 |
|
| 45 |
=head1 LICENSE |
| 46 |
|
| 47 |
GPLv2 |
| 48 |
|
| 49 |
=head1 MAGIC MARKERS |
| 50 |
|
| 51 |
#%# family=manual |
| 52 |
#%# capabilities=autoconf |
| 53 |
|
| 54 |
=cut |
| 55 |
|
| 56 |
# shellcheck disable=SC1090 |
| 57 |
. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 58 |
|
| 59 |
if [ "${MUNIN_DEBUG:-0}" = 1 ]; then
|
| 60 |
set -x |
| 61 |
fi |
| 62 |
|
| 63 |
API_PATH="${api_path:-/ocs/v2.php/apps/serverinfo/api/v1/info}?format=json"
|
| 64 |
DOMAIN="${0##*nextcloud_}"
|
| 65 |
SCHEME="${scheme:-https}://"
|
| 66 |
TIMEOUT="${timeout:-2}"
|
| 67 |
UPDATES_WARNING="${updates_warning:-1}"
|
| 68 |
CLEANDOMAIN="$(clean_fieldname "${DOMAIN}")"
|
| 69 |
USERNAME="${username:-}"
|
| 70 |
PASSWORD="${password:-}"
|
| 71 |
|
| 72 |
fetch_url () {
|
| 73 |
curl -s -f -m "${TIMEOUT}" "$@"
|
| 74 |
} |
| 75 |
|
| 76 |
case $1 in |
| 77 |
|
| 78 |
autoconf) |
| 79 |
if [ ! -x "$(command -v curl)" ]; then |
| 80 |
echo "no (curl not found)" |
| 81 |
elif [ ! -x "$(command -v jq)" ]; then |
| 82 |
echo "no (jq not found)" |
| 83 |
else |
| 84 |
fetch_url -I -u "${USERNAME}:${PASSWORD}" -I "${SCHEME}${DOMAIN}${API_PATH}" \
|
| 85 |
| grep -iq "Content-Type: application/json" \ |
| 86 |
&& echo "yes" \ |
| 87 |
|| echo "no (invalid or empty response from nextcloud serverinfo api)" |
| 88 |
fi |
| 89 |
exit 0 |
| 90 |
;; |
| 91 |
config) |
| 92 |
|
| 93 |
cat << EOM |
| 94 |
multigraph nextcloud_users_${CLEANDOMAIN}
|
| 95 |
graph_title Nextcloud users on ${DOMAIN}
|
| 96 |
graph_args --base 1000 -l 0 |
| 97 |
graph_printf %.0lf |
| 98 |
graph_vlabel connected users |
| 99 |
graph_info number of connected user |
| 100 |
graph_category cloud |
| 101 |
last5minutes.label last 5 minutes |
| 102 |
last5minutes.info users connected in the last 5 minutes |
| 103 |
last5minutes.min 0 |
| 104 |
last1hour.label last hour |
| 105 |
last1hour.info users connected in the last hour |
| 106 |
last1hour.min 0 |
| 107 |
last24hours.label last 24 hours |
| 108 |
last24hours.info users connected in the last 24 hours |
| 109 |
last24hours.min 0 |
| 110 |
num_users.label number of users |
| 111 |
num_users.info total number of users |
| 112 |
num_users.min 0 |
| 113 |
multigraph nextcloud_files_${CLEANDOMAIN}
|
| 114 |
graph_title Nextcloud files on ${DOMAIN}
|
| 115 |
graph_args --base 1000 -l 0 |
| 116 |
graph_printf %.0lf |
| 117 |
graph_vlabel number of files |
| 118 |
graph_info number of files |
| 119 |
graph_category cloud |
| 120 |
num_files.label number of files |
| 121 |
num_files.info current number of files |
| 122 |
num_files.min 0 |
| 123 |
multigraph nextcloud_shares_${CLEANDOMAIN}
|
| 124 |
graph_title Nextcloud shares on ${DOMAIN}
|
| 125 |
graph_args --base 1000 -l 0 |
| 126 |
graph_printf %.0lf |
| 127 |
graph_vlabel number of shares |
| 128 |
graph_info number of shares |
| 129 |
graph_category cloud |
| 130 |
num_shares.label total number of shares |
| 131 |
num_shares.info current over all total of shares |
| 132 |
num_shares.min 0 |
| 133 |
num_shares_user.label user shares |
| 134 |
num_shares_user.info current total of user shares |
| 135 |
num_shares_user.min 0 |
| 136 |
num_shares_groups.label group shares |
| 137 |
num_shares_groups.info current total of group shares |
| 138 |
num_shares_groups.min 0 |
| 139 |
num_shares_link.label link shares |
| 140 |
num_shares_link.info current total of link shares |
| 141 |
num_shares_link.min 0 |
| 142 |
num_shares_mail.label mail shares |
| 143 |
num_shares_mail.info current total of mail shares |
| 144 |
num_shares_mail.min 0 |
| 145 |
num_shares_room.label room shares |
| 146 |
num_shares_room.info current total of room shares |
| 147 |
num_shares_room.min 0 |
| 148 |
num_shares_link_no_password.label link shares without password protection |
| 149 |
num_shares_link_no_password.info current total of link shares without password protection |
| 150 |
num_shares_link_no_password.min 0 |
| 151 |
num_fed_shares_sent.label federated shares sent |
| 152 |
num_fed_shares_sent.info current total of federated shares sent |
| 153 |
num_fed_shares_sent.min 0 |
| 154 |
num_fed_shares_received.label federated shares received |
| 155 |
num_fed_shares_received.info current total of federated shares received |
| 156 |
num_fed_shares_received.min 0 |
| 157 |
multigraph nextcloud_dbsize_${CLEANDOMAIN}
|
| 158 |
graph_title Nextcloud database size on ${DOMAIN}
|
| 159 |
graph_args --base 1024 -l 0 |
| 160 |
graph_vlabel size in bytes |
| 161 |
graph_info database database size in bytes |
| 162 |
graph_category cloud |
| 163 |
db_size.label database size in bytes |
| 164 |
db_size.info database size in bytes |
| 165 |
db_size.draw AREA |
| 166 |
db_size.min 0 |
| 167 |
multigraph nextcloud_storages_${CLEANDOMAIN}
|
| 168 |
graph_title Nextcloud storages on ${DOMAIN}
|
| 169 |
graph_args --base 1000 -l 0 |
| 170 |
graph_printf %.0lf |
| 171 |
graph_vlabel number |
| 172 |
graph_info number of storages |
| 173 |
graph_category cloud |
| 174 |
num_storages.label total number of storages |
| 175 |
num_storages.info current total of storages |
| 176 |
num_storages.min 0 |
| 177 |
num_storages_local.label number of local storages |
| 178 |
num_storages_local.info current number of local storages |
| 179 |
num_storages_local.min 0 |
| 180 |
num_storages_home.label number of home storages |
| 181 |
num_storages_home.info current number of home storages |
| 182 |
num_storages_home.min 0 |
| 183 |
num_storages_other.label number of other storages |
| 184 |
num_storages_other.info current number of other storages |
| 185 |
num_storages_other.min 0 |
| 186 |
multigraph nextcloud_apps_${CLEANDOMAIN}
|
| 187 |
graph_title Nextcloud apps on ${DOMAIN}
|
| 188 |
graph_args --base 1000 -l 0 |
| 189 |
graph_printf %.0lf |
| 190 |
graph_vlabel apps |
| 191 |
graph_info number of installed and updatable apps |
| 192 |
graph_category cloud |
| 193 |
num_updates_available.label available app updates |
| 194 |
num_updates_available.info number of available app updates |
| 195 |
num_updates_available.min 0 |
| 196 |
num_updates_available.warning ${UPDATES_WARNING}
|
| 197 |
num_installed.label installed apps |
| 198 |
num_installed.info number of installed apps |
| 199 |
num_installed.min 0 |
| 200 |
EOM |
| 201 |
exit 0 |
| 202 |
;; |
| 203 |
|
| 204 |
esac |
| 205 |
|
| 206 |
|
| 207 |
# users |
| 208 |
fetch_url -u "${USERNAME}:${PASSWORD}" "${SCHEME}${DOMAIN}${API_PATH}" \
|
| 209 |
| sed 's/\\/\\\\/g' \ |
| 210 |
| jq -r '.ocs.data |
| 211 |
| @text " |
| 212 |
multigraph nextcloud_users_'"${CLEANDOMAIN}"'
|
| 213 |
last5minutes.value \(.activeUsers.last5minutes) |
| 214 |
last1hour.value \(.activeUsers.last1hour) |
| 215 |
last24hours.value \(.activeUsers.last24hours) |
| 216 |
num_users.value \(.nextcloud.storage.num_users) |
| 217 |
|
| 218 |
multigraph nextcloud_files_'"${CLEANDOMAIN}"'
|
| 219 |
num_files.value \(.nextcloud.storage.num_files) |
| 220 |
|
| 221 |
multigraph nextcloud_storages_'"${CLEANDOMAIN}"'
|
| 222 |
num_storages.value \(.nextcloud.storage.num_storages) |
| 223 |
num_storages_local.value \(.nextcloud.storage.num_storages_local) |
| 224 |
num_storages_home.value \(.nextcloud.storage.num_storages_home) |
| 225 |
num_storages_other.value \(.nextcloud.storage.num_storages_other) |
| 226 |
|
| 227 |
multigraph nextcloud_shares_'"${CLEANDOMAIN}"'
|
| 228 |
num_shares.value \(.nextcloud.shares.num_shares) |
| 229 |
num_shares_user.value \(.nextcloud.shares.num_shares_user) |
| 230 |
num_shares_groups.value \(.nextcloud.shares.num_shares_groups) |
| 231 |
num_shares_link.value \(.nextcloud.shares.num_shares_link) |
| 232 |
num_shares_mail.value \(.nextcloud.shares.num_shares_mail) |
| 233 |
num_shares_room.value \(.nextcloud.shares.num_shares_room) |
| 234 |
num_shares_link_no_password.value \(.nextcloud.shares.num_shares_link_no_password) |
| 235 |
num_fed_shares_sent.value \(.nextcloud.shares.num_fed_shares_sent) |
| 236 |
num_fed_shares_received.value \(.nextcloud.shares.num_fed_shares_received) |
| 237 |
|
| 238 |
multigraph nextcloud_dbsize_'"${CLEANDOMAIN}"'
|
| 239 |
db_size.value \(.server.database.size) |
| 240 |
|
| 241 |
multigraph nextcloud_apps_'"${CLEANDOMAIN}"'
|
| 242 |
num_installed.value \(.nextcloud.system.apps.num_installed) |
| 243 |
num_updates_available.value \(.nextcloud.system.apps.num_updates_available) |
| 244 |
"' \ |
| 245 |
| sed 's/ null$/ U/' |
