Skip to content

Instantly share code, notes, and snippets.

@mqu
Last active October 25, 2021 10:19
Show Gist options
  • Save mqu/0c35035d034b0bf282ae03ce47cd54a8 to your computer and use it in GitHub Desktop.
Save mqu/0c35035d034b0bf282ae03ce47cd54a8 to your computer and use it in GitHub Desktop.
telegraf / disk usage / gitlab

Report disk usage for gitlab (omnibus installation) into influx database.

  • it will report report registry and git size in Mo.
  • data will be available at "telegraf/size/[registry,git]

provided files :

  • /etc/sudo.d/telegraf : need to run sudo du external command
  • /etc/telegraf/telegraf.d/inputs.exec-disk-usage.conf : main script managed by telegraf ; need to restart telegraf
  • /etc/telegraf/telegraf.d/scripts/exec-disk-usage is the script computing disk usage and reporting to telegraf computed size in influx format.
#/bin/bash
# location : /etc/telegraf/telegraf.d/scripts/exec-disk-usage
name=$1
dir=$2
# compute size un Mo
size=$(sudo ionice -c 3 /usr/bin/du -sm $dir | cut -f 1)
# data_format=influx
printf "size,unit=mo %s=%di" $name $size
# location : /etc/telegraf/telegraf.d/inputs.exec-disk-usage.conf
[[inputs.exec]]
## Commands array
commands = [
"/bin/bash /etc/telegraf/telegraf.d/scripts/exec-disk-usage registry /var/opt/gitlab/gitlab-rails/shared/registry" ,
"/bin/bash /etc/telegraf/telegraf.d/scripts/exec-disk-usage artifacts /var/opt/gitlab/gitlab-rails/shared/artifacts" ,
"/bin/bash /etc/telegraf/telegraf.d/scripts/exec-disk-usage proxy /var/opt/gitlab/gitlab-rails/shared/dependency_proxy" ,
"/bin/bash /etc/telegraf/telegraf.d/scripts/exec-disk-usage packages /var/opt/gitlab/gitlab-rails/shared/packages" ,
"/bin/bash /etc/telegraf/telegraf.d/scripts/exec-disk-usage uploads /var/opt/gitlab/gitlab-rails/uploads" ,
"/bin/bash /etc/telegraf/telegraf.d/scripts/exec-disk-usage pages /var/opt/gitlab/gitlab-rails/shared/pages" ,
"/bin/bash /etc/telegraf/telegraf.d/scripts/exec-disk-usage builds /var/opt/gitlab/gitlab-ci/builds" ,
"/bin/bash /etc/telegraf/telegraf.d/scripts/exec-disk-usage git /var/opt/gitlab/git-data/"
]
## Timeout for each command to complete.
timeout = "30s"
data_format = "influx"
interval = "8h"
name_override = "size"
# test : telegraf --config /etc/telegraf/telegraf.d/inputs.exec-registry-disk-usage.conf --test
# sudo config
# root@gitlab:/etc/telegraf/telegraf.d# cat /etc/sudoers.d/telegraf
# telegraf ALL = (root) NOPASSWD: /usr/bin/du
# location : /etc/sudo.d/telegraf
# User telegraf and admin can exect /usr/bin/du as root without passwd
telegraf ALL = (root) NOPASSWD: /usr/bin/du
@mqu
Copy link
Author

mqu commented May 2, 2019

added artifacts directory.

@mqu
Copy link
Author

mqu commented Oct 25, 2021

added

  • builds, pages, uploads, proxy, packages directories
  • ionice on du job
  • fixed comment typo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment