mirror of
https://gitlab.archlinux.org/archlinux/infrastructure.git
synced 2026-09-19 14:49:14 +02:00
The idea of this is to allow us to graph the number of packages per repository in grafana just like we're already doing in the archive exporter.
47 lines
1.3 KiB
Bash
47 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
set -o errexit
|
|
set -o nounset
|
|
|
|
if (( $# != 1 )); then
|
|
echo "Missing textcollector directory argument"
|
|
exit 1
|
|
fi
|
|
|
|
TEXTFILE_COLLECTOR_DIR=${1}
|
|
REPOS_DIR=/srv/ftp
|
|
PROM_FILE=$TEXTFILE_COLLECTOR_DIR/repository.prom
|
|
|
|
TMP_FILE=$PROM_FILE.$$
|
|
[ -e $TMP_FILE ] && rm -f $TMP_FILE
|
|
|
|
trap "rm -f $TMP_FILE" EXIT
|
|
|
|
echo "# HELP repository_directory_size_bytes repository directory size in bytes" >> $TMP_FILE
|
|
echo "# TYPE repository_directory_size_bytes gauge" >> $TMP_FILE
|
|
|
|
for dir in $REPOS_DIR/*; do
|
|
# All Arch repositories should have an os dir, this excludes the archive and other non repo dirs.
|
|
if [ -d "$dir/os" ]; then
|
|
reponame=$(basename $dir)
|
|
directory_size=$(du -Lsb ${dir} | awk '{ print $1 }')
|
|
|
|
echo "repository_directory_size_bytes{name=\"${reponame}\"} $directory_size" >> $TMP_FILE
|
|
fi
|
|
done
|
|
|
|
echo "# HELP repository_directory_packages_total number of packages in repository" >> $TMP_FILE
|
|
echo "# TYPE repository_directory_packages_total gauge" >> $TMP_FILE
|
|
|
|
for dir in $REPOS_DIR/*; do
|
|
# All Arch repositories should have an os dir, this excludes the archive and other non repo dirs.
|
|
if [ -d "$dir/os" ]; then
|
|
reponame=$(basename $dir)
|
|
packages_total=$(find ${dir} -name '*.pkg.tar.zst' | wc -l)
|
|
|
|
echo "repository_directory_packages_total{name=\"${reponame}\"} $packages_total" >> $TMP_FILE
|
|
fi
|
|
done
|
|
|
|
mv -f $TMP_FILE $PROM_FILE
|