From 65ee95c018288827242f2efd2088db83e9c14822 Mon Sep 17 00:00:00 2001 From: pitchum Date: Sun, 8 Mar 2020 13:05:15 +0100 Subject: [PATCH] Add scripts used for activity reporting. --- rapport_activite/rapport_activites.sh | 43 +++++++++++++++++++++++++++ rapport_activite/update_ticket.sh | 41 +++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100755 rapport_activite/rapport_activites.sh create mode 100755 rapport_activite/update_ticket.sh diff --git a/rapport_activite/rapport_activites.sh b/rapport_activite/rapport_activites.sh new file mode 100755 index 0000000..d4f4d28 --- /dev/null +++ b/rapport_activite/rapport_activites.sh @@ -0,0 +1,43 @@ +#! /bin/bash + +main() { + echo "h2. ## Global info" + echo "" + echo "* Total accounts: $(sudo -u ejabberd ejabberdctl registered_users chapril.org | egrep -v -e 'r\.giskard' -e '(lisa|bart)\.simpson' | wc -l)" + echo "* Total messages stored (MAM): $(count_archived_messages) " +# echo "Active users: $(sudo -u ejabberd ejabberdctl connected_users_number)" + echo "" + echo "h2. ## HTTP upload storage:" + echo "" + echo "* User quota: $(get_hard_quota)M" + echo "* Total disk usage: $(du -sh /srv/ejabberd/chapril.org/upload/ | awk '{print $1}')" + per_account_storage_usage +# echo "s2s outgoing connections: $(sudo -u ejabberd ejabberdctl incoming_s2s_number)" +# echo "s2s incoming connections: $(sudo -u ejabberd ejabberdctl outgoing_s2s_number)" +} + +get_hard_quota() { + grep hard_quota /etc/ejabberd/ejabberd.yml -A2 | grep all | sed -r 's/^\s*-\s([0-9]+).*/\1/' +} + +per_account_storage_usage() { + STORAGE_DIR="/srv/ejabberd/chapril.org/upload/" + # TODO Directories to ignore because they are used for tests accounts (bart and lisa simpsons) + IGNORE_DIRS="35eae3ddc83d72e4d3fad3160a400db688d7d936 9be859c77649f33d207cbe0d74a126b2fd31cb33" + + echo "Per user disk usage:" + tmp="$(du -sh ${STORAGE_DIR}* | sort -hr | awk '{print $1}')" + echo "** Max: "$(echo "${tmp}" | head -n 1) +# echo " Min: "$(echo "${tmp}" | tail -n 1) + + subfolders_count=$(find ${STORAGE_DIR} -mindepth 1 -maxdepth 1 -type d | wc -l) + total_size=$(du -s ${STORAGE_DIR} | awk '{print $1}') + avg=$(((${total_size} / 1024) / ${subfolders_count})) + echo "** Avg: ${avg}M" +} + +count_archived_messages() { + psql -U ejabberd -h localhost ejabberd -c "select count(*) from archive where peer not like 'irc%' and username not in ('r.giskard', 'lisa.simpson', 'bart.simpson')" -t | grep -v '^$' | awk '{print $1}' +} + +main diff --git a/rapport_activite/update_ticket.sh b/rapport_activite/update_ticket.sh new file mode 100755 index 0000000..ef72499 --- /dev/null +++ b/rapport_activite/update_ticket.sh @@ -0,0 +1,41 @@ +#! /bin/bash + +REDMINE_BASE_URL="https://agir.april.org" +API_KEY="4d724eb3e51600b6f9aff26360a5430f76ad4dd9" +TICKET_ID=4047 + +main() { + post_report +} + +post_report() { + datafile=$(mktemp /tmp/report_stats_$(date +%Y-%m-%d_%H%M)_XXXX.json) + cat < "${datafile}" +{ + "issue": { + "notes": "$(/usr/local/bin/rapport_activites.sh | sed -z 's/\n/\\n/g')" + } +} +EOF + + curl -s \ + -H "Content-Type: application/json" \ + -H "X-Redmine-API-Key: ${API_KEY}" \ + -X PUT --data-binary "@${datafile}" \ + "${REDMINE_BASE_URL}/issues/${TICKET_ID}.json" + rm "${datafile}" +} + +# debug function +last_comment_date() { + curl -H "X-Redmine-API-Key: ${API_KEY}" -s "${REDMINE_BASE_URL}/issues/${TICKET_ID}.json?include=journals" \ + | jq '.issue.journals | last | .created_on' +} + +# debug function +list() { + curl -H "X-Redmine-API-Key: ${API_KEY}" -s "${REDMINE_BASE_URL}/issues/${TICKET_ID}.json?include=journals" \ + | jq '.issue.journals[] | [.user.name, .notes]' +} + +main