1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

Merge pull request #1433 from brknkfr/synapse_fix

[synapse_] Ignore puppet users of bridges (last_seen_ts is null)
This commit is contained in:
Kenyon Ralph 2024-04-30 12:32:25 -07:00 committed by GitHub
commit 2328b39d28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -74,7 +74,7 @@ AUTH_TOKEN="${auth_token:-}"
INTERVAL="${interval:-300}" INTERVAL="${interval:-300}"
PORT="${port:-443}" PORT="${port:-443}"
ADMIN_API_PATH="${admin_api_path:-/_synapse/admin}" ADMIN_API_PATH="${admin_api_path:-/_synapse/admin}"
QUERY_LIMIT="${query_limit:-1000}" QUERY_LIMIT="${query_limit:-10000}"
HOMESERVER="${0##*synapse_}" HOMESERVER="${0##*synapse_}"
SCHEME="${scheme:-https}://" SCHEME="${scheme:-https}://"
TIMEOUT="${timeout:-2}" TIMEOUT="${timeout:-2}"
@ -175,11 +175,13 @@ REPORTS=$(fetch_url -H "Authorization: Bearer ${AUTH_TOKEN}" "${SCHEME}${HOMESER
echo multigraph synapse_users_"${CLEANHOMESERVER}" echo multigraph synapse_users_"${CLEANHOMESERVER}"
if USERS="$(echo "$USERS" | jq -r)"; then if USERS="$(echo "$USERS" | jq -r)"; then
total="$(echo "$USERS" | jq -r .total)" total="$(echo "$USERS" | jq -r .total)"
puppets="$(echo "$USERS" | grep -c '"last_seen_ts": null')"
bots="$(echo "$USERS" | grep -c '"user_type": "bot"')" bots="$(echo "$USERS" | grep -c '"user_type": "bot"')"
total_registered=$(( total - bots )) virtual_users=$(( puppets + bots ))
total_registered=$(( total - virtual_users ))
echo total_registered.value "$total_registered" echo total_registered.value "$total_registered"
active="$(echo "$USERS" | grep -c '"deactivated": 0')" active="$(echo "$USERS" | grep -c '"deactivated": 0')"
active_users=$(( active - bots )) active_users=$(( active - virtual_users ))
echo active_users.value "$active_users" echo active_users.value "$active_users"
echo bots.value "$bots" echo bots.value "$bots"
# Convert to miliseconds # Convert to miliseconds
@ -189,7 +191,7 @@ if USERS="$(echo "$USERS" | jq -r)"; then
last_seen_times_ms=$(echo "$USERS" | grep -E "\"last_seen_ts\": [0-9]+") last_seen_times_ms=$(echo "$USERS" | grep -E "\"last_seen_ts\": [0-9]+")
online="$(echo "$last_seen_times_ms" | awk -v "count=0" -F": " '$2 > "'$time_interval_ago'" {count++} END {print count}')" online="$(echo "$last_seen_times_ms" | awk -v "count=0" -F": " '$2 > "'$time_interval_ago'" {count++} END {print count}')"
online_users=$(( online - bots )) online_users=$(( online - bots ))
echo online_users.value "$bots" echo online_users.value "$online_users"
echo deactivated_users.value "$(echo "$USERS" | grep -c '"deactivated": 1')" echo deactivated_users.value "$(echo "$USERS" | grep -c '"deactivated": 1')"
echo erased_users.value "$(echo "$USERS" | grep -c '"erased": true')" echo erased_users.value "$(echo "$USERS" | grep -c '"erased": true')"
else else
@ -217,10 +219,9 @@ else
echo "rooms_total.value U" echo "rooms_total.value U"
fi fi
echo multigraph synapse_reports_"${CLEANHOMESERVER}" echo multigraph synapse_reports_"${CLEANHOMESERVER}"
if [ "$REPORTS" -eq "$REPORTS" ]; then if [ -n "$REPORTS" ] && [ "$REPORTS" -eq "$REPORTS" ]; then
echo event_reports.value "$REPORTS" echo event_reports.value "$REPORTS"
else else
echo "event_reports.value U" echo "event_reports.value U"
fi fi