Commit 96d5efcf authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

Merge branch 'aur-exporter' into 'master'

prometheus_exporters: Add AUR exporter

Closes #323

See merge request !375
parents 867d42ba 1c929a0b
Pipeline #7303 passed with stage
in 50 seconds
......@@ -17,7 +17,7 @@ remote_write:
- url: https://{{ prometheus_domain }}:9090/api/v1/write
write_relabel_configs:
- source_labels: [__name__]
regex: "archive_directory_size_bytes|archive_total_packages|rebuilderd_results|rebuilderd_workers|rebuilderd_queue_length|repository_directory_size_bytes"
regex: "archive_directory_size_bytes|archive_total_packages|rebuilderd_results|rebuilderd_workers|rebuilderd_queue_length|repository_directory_size_bytes|aur_.+"
action: keep
basic_auth:
username: {{ vault_prometheus_user }}
......
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
if (( $# != 1 )); then
echo "Missing textcollector directory argument"
exit 1
fi
TEXTFILE_COLLECTOR_DIR=${1}
PROM_FILE=$TEXTFILE_COLLECTOR_DIR/pacman.prom
TMP_FILE=$PROM_FILE.$$
[ -e $TMP_FILE ] && rm -f $TMP_FILE
trap "rm -f $TMP_FILE" EXIT
stats="$(curl --silent --show-error --fail --max-time 10 --user-agent "aur-textcollector (https://gitlab.archlinux.org/archlinux/infrastructure)" https://aur.archlinux.org/ | hq ".stat-desc + td" text)"
packages="$(sed -n -e 1p <<< "${stats}")"
orphan_packages="$(sed -n -e 2p <<< "${stats}")"
not_updated_packages="$(sed -n -e 6p <<< "${stats}")"
# This is not 100% accurate
packages="$((packages-orphan_packages-not_updated_packages))"
users="$(sed -n -e 7p <<< "${stats}")"
trusted_users="$(sed -n -e 8p <<< "${stats}")"
users="$((users-trusted_users))"
echo "# HELP aur_packages number of packages" >> $TMP_FILE
echo "# TYPE aur_packages gauge" >> $TMP_FILE
echo "aur_packages{state=\"updated\"} $packages" >> $TMP_FILE
echo "aur_packages{state=\"orphan\"} $orphan_packages" >> $TMP_FILE
echo "aur_packages{state=\"not_updated\"} $not_updated_packages" >> $TMP_FILE
echo "# HELP aur_users number of users" >> $TMP_FILE
echo "# TYPE aur_users gauge" >> $TMP_FILE
echo "aur_users{type=\"user\"} $users" >> $TMP_FILE
echo "aur_users{type=\"tu\"} $trusted_users" >> $TMP_FILE
mv -f $TMP_FILE $PROM_FILE
---
- name: install prometheus-node-exporter
pacman: name=prometheus-node-exporter,arch-audit,pacman-contrib,jq state=present
pacman: name=prometheus-node-exporter,arch-audit,pacman-contrib,jq,hq state=present
- name: install prometheus-blackbox-exporter
pacman: name=prometheus-blackbox-exporter state=present
......@@ -57,6 +57,7 @@
- archive-textcollector.sh
- repository-textcollector.sh
- btrfs-textcollector.sh
- aur-textcollector.sh
- name: install arch textcollector service
template: src=prometheus-arch-textcollector.service.j2 dest=/etc/systemd/system/prometheus-arch-textcollector.service owner=root group=root mode=644
......@@ -135,6 +136,14 @@
systemd: name=prometheus-btrfs-textcollector.timer enabled=yes daemon_reload=yes state=started
when: filesystem == "btrfs"
- name: install aur textcollector timer
template: src=prometheus-aur-textcollector.timer.j2 dest=/etc/systemd/system/prometheus-btrfs-textcollector.timer owner=root group=root mode=644
when: "'prometheus' in group_names"
- name: enable and start prometheus aur textcollector timer
systemd: name=prometheus-aur-textcollector.timer enabled=yes daemon_reload=yes state=started
when: "'prometheus' in group_names"
- name: enable prometheus-node-exporter service
systemd: name=prometheus-node-exporter enabled=yes daemon_reload=yes state=started
......
[Unit]
Description=Prometheus Arch Exporter
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
User=node_exporter
ExecStart=/usr/local/bin/aur-textcollector.sh {{ prometheus_textfile_dir }}
NoNewPrivileges=true
LockPersonality=true
CapabilityBoundingSet=
UMask=077
PrivateDevices=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths={{ prometheus_textfile_dir }}
MemoryDenyWriteExecute=true
RemoveIPC=true
RestrictRealtime=true
RestrictNamespaces=true
RestrictSUIDSGID=true
RestrictAddressFamilies=~AF_NETLINK
RestrictAddressFamilies=~AF_PACKET
ProtectHostname=true
ProtectControlGroups=true
ProtectKernelLogs=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectClock=true
SystemCallArchitectures=native
[Unit]
Description=Prometheus Arch Exporter TextCollector Timer
[Timer]
OnUnitActiveSec=5m
[Install]
WantedBy=timers.target
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment