root / plugins / nextcloud / nextcloud_ @ 3b478bab
Historique | Voir | Annoter | Télécharger (7,36 ko)
| 1 | 33af56af | Sebastian L | #!/bin/sh |
|---|---|---|---|
| 2 | 12cb1134 | Olivier Mehani | # shellcheck shell=dash |
| 3 | 33af56af | Sebastian L | |
| 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 | cd759e2f | Olivier Mehani | nextcloud_<nextcloud-domain> to this file. You can even append a port |
| 22 | 33af56af | Sebastian L | (: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 | cd759e2f | Olivier Mehani | [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 | 33af56af | Sebastian L | |
| 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 | cd759e2f | Olivier Mehani | Copyright (C) 2020 Sebastian L. (https://momou.ch), |
| 43 | Olivier Mehani <shtrom+munin@ssji.net> |
||
| 44 | 33af56af | Sebastian L | |
| 45 | =head1 LICENSE |
||
| 46 | |||
| 47 | GPLv2 |
||
| 48 | |||
| 49 | =head1 MAGIC MARKERS |
||
| 50 | |||
| 51 | #%# family=manual |
||
| 52 | #%# capabilities=autoconf |
||
| 53 | |||
| 54 | =cut |
||
| 55 | |||
| 56 | 195a733d | Olivier Mehani | # shellcheck disable=SC1090 |
| 57 | 33af56af | Sebastian L | . "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 58 | |||
| 59 | 195a733d | Olivier Mehani | 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 | 33af56af | Sebastian L | DOMAIN="${0##*nextcloud_}"
|
| 65 | f47fddf3 | Olivier Mehani | SCHEME="${scheme:-https}://"
|
| 66 | 195a733d | Olivier Mehani | TIMEOUT="${timeout:-2}"
|
| 67 | 12cb1134 | Olivier Mehani | UPDATES_WARNING="${updates_warning:-1}"
|
| 68 | cd759e2f | Olivier Mehani | CLEANDOMAIN="$(clean_fieldname "${DOMAIN}")"
|
| 69 | 33af56af | Sebastian L | USERNAME="${username:-}"
|
| 70 | PASSWORD="${password:-}"
|
||
| 71 | |||
| 72 | a7d44887 | Olivier Mehani | fetch_url () {
|
| 73 | curl -s -f -m "${TIMEOUT}" "$@"
|
||
| 74 | 33af56af | Sebastian L | } |
| 75 | |||
| 76 | case $1 in |
||
| 77 | |||
| 78 | autoconf) |
||
| 79 | f47fddf3 | Olivier Mehani | if [ ! -x "$(command -v curl)" ]; then |
| 80 | echo "no (curl not found)" |
||
| 81 | elif [ ! -x "$(command -v jq)" ]; then |
||
| 82 | 3b478bab | Olivier Mehani | echo "no (jq not found)" |
| 83 | f47fddf3 | Olivier Mehani | else |
| 84 | cd759e2f | Olivier Mehani | fetch_url -I -u "${USERNAME}:${PASSWORD}" -I "${SCHEME}${DOMAIN}${API_PATH}" \
|
| 85 | a7d44887 | Olivier Mehani | | grep -iq "Content-Type: application/json" \ |
| 86 | f47fddf3 | Olivier Mehani | && echo "yes" \ |
| 87 | cd759e2f | Olivier Mehani | || echo "no (invalid or empty response from nextcloud serverinfo api)" |
| 88 | f47fddf3 | Olivier Mehani | fi |
| 89 | exit 0 |
||
| 90 | ;; |
||
| 91 | 33af56af | Sebastian L | config) |
| 92 | |||
| 93 | cat << EOM |
||
| 94 | cd759e2f | Olivier Mehani | multigraph nextcloud_users_${CLEANDOMAIN}
|
| 95 | graph_title Nextcloud users on ${DOMAIN}
|
||
| 96 | 33af56af | Sebastian L | 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 | cd759e2f | Olivier Mehani | multigraph nextcloud_files_${CLEANDOMAIN}
|
| 114 | graph_title Nextcloud files on ${DOMAIN}
|
||
| 115 | 33af56af | Sebastian L | 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 | cd759e2f | Olivier Mehani | multigraph nextcloud_shares_${CLEANDOMAIN}
|
| 124 | graph_title Nextcloud shares on ${DOMAIN}
|
||
| 125 | 33af56af | Sebastian L | 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 | cd759e2f | Olivier Mehani | multigraph nextcloud_dbsize_${CLEANDOMAIN}
|
| 158 | graph_title Nextcloud database size on ${DOMAIN}
|
||
| 159 | 33af56af | Sebastian L | 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 | cd759e2f | Olivier Mehani | multigraph nextcloud_storages_${CLEANDOMAIN}
|
| 168 | graph_title Nextcloud storages on ${DOMAIN}
|
||
| 169 | 33af56af | Sebastian L | 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 | cd759e2f | Olivier Mehani | multigraph nextcloud_apps_${CLEANDOMAIN}
|
| 187 | graph_title Nextcloud apps on ${DOMAIN}
|
||
| 188 | 33af56af | Sebastian L | 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 | 12cb1134 | Olivier Mehani | num_updates_available.warning ${UPDATES_WARNING}
|
| 197 | 33af56af | Sebastian L | 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 | DBSIZE=$(echo "$JSONSTATS" | jq -cr ".server.database.size") |
||
| 207 | |||
| 208 | # users |
||
| 209 | cd759e2f | Olivier Mehani | fetch_url -u "${USERNAME}:${PASSWORD}" "${SCHEME}${DOMAIN}${API_PATH}" \
|
| 210 | | sed 's/\\/\\\\/g' \ |
||
| 211 | | jq -r '.ocs.data |
||
| 212 | | @text " |
||
| 213 | multigraph nextcloud_users_'${CLEANDOMAIN}'
|
||
| 214 | last5minutes \(.activeUsers.last5minutes) |
||
| 215 | last1hour \(.activeUsers.last1hour) |
||
| 216 | last24hours \(.activeUsers.last24hours) |
||
| 217 | num_users \(.nextcloud.storage.num_users) |
||
| 218 | |||
| 219 | multigraph nextcloud_files_'${CLEANDOMAIN}'
|
||
| 220 | num_files \(.nextcloud.storage.num_files) |
||
| 221 | |||
| 222 | multigraph nextcloud_storages_'${CLEANDOMAIN}'
|
||
| 223 | num_storages \(.nextcloud.storage.num_storages) |
||
| 224 | num_storages_local \(.nextcloud.storage.num_storages_local) |
||
| 225 | num_storages_home \(.nextcloud.storage.num_storages_home) |
||
| 226 | num_storages_other \(.nextcloud.storage.num_storages_other) |
||
| 227 | |||
| 228 | multigraph nextcloud_shares_'${CLEANDOMAIN}'
|
||
| 229 | num_shares \(.nextcloud.shares.num_shares) |
||
| 230 | num_shares_user \(.nextcloud.shares.num_shares_user) |
||
| 231 | num_shares_groups \(.nextcloud.shares.num_shares_groups) |
||
| 232 | num_shares_link \(.nextcloud.shares.num_shares_link) |
||
| 233 | num_shares_mail \(.nextcloud.shares.num_shares_mail) |
||
| 234 | num_shares_room \(.nextcloud.shares.num_shares_room) |
||
| 235 | num_shares_link_no_password \(.nextcloud.shares.num_shares_link_no_password) |
||
| 236 | num_fed_shares_sent \(.nextcloud.shares.num_fed_shares_sent) |
||
| 237 | num_fed_shares_received \(.nextcloud.shares.num_fed_shares_received) |
||
| 238 | |||
| 239 | multigraph nextcloud_dbsize_'${CLEANDOMAIN}'
|
||
| 240 | db_size \(.server.database.size) |
||
| 241 | |||
| 242 | multigraph nextcloud_apps_'${CLEANDOMAIN}'
|
||
| 243 | num_installed \(.nextcloud.system.apps.num_installed) |
||
| 244 | num_updates_available \(.nextcloud.system.apps.num_updates_available) |
||
| 245 | "' \ |
||
| 246 | | sed 's/ null$/ U/' |
