diff --git a/roles/osd/defaults/main.yml b/roles/osd/defaults/main.yml index 9c74769..9eaec8e 100644 --- a/roles/osd/defaults/main.yml +++ b/roles/osd/defaults/main.yml @@ -19,3 +19,5 @@ ceph_osd_osds_group: "{{ ceph_osd_group | default('cephs') }}" # Filesystem ID ceph_mon_fsid: "{{ ceph_fsid }}" cephadm_image: "quay.io/ceph/ceph:v{{ ceph_version | default('18.2.1') }}" + +ceph_bluestore_frag_collect: true diff --git a/roles/osd/tasks/main.yml b/roles/osd/tasks/main.yml index 8b4d4fc..852e0c7 100644 --- a/roles/osd/tasks/main.yml +++ b/roles/osd/tasks/main.yml @@ -126,3 +126,28 @@ ansible.builtin.include_tasks: check-osds.yml when: - inventory_hostname == groups[ceph_osd_osds_group] | last + +- name: Prepare Cronjob script for collect Bluestore fragmentation score + when: ceph_bluestore_frag_collect + ansible.builtin.copy: + src: "bs-frag-score.sh.j2" + dest: "/var/lib/cron/bs-frag-score.sh" + owner: root + group: root + mode: u+rwx,g=,o= + +- name: Prepare Cronjob script for collect Bluestore fragmentation score + when: ceph_bluestore_frag_collect + ansible.builtin.templates: + src: "prom-bs-frag-score-collector.sh.j2" + dest: "/var/lib/cron/prom-bs-frag-score-collector.sh" + owner: root + group: root + mode: u+rwx,g=,o= + +- name: Setup Cron job collect Bluestore fragmentation score for Prometheus + when: ceph_bluestore_frag_collect + ansible.builtin.cron: + name: "collect bluestore fragmentation score" + minute: "1" + job: "/var/lib/cron/prom-bs-frag-score-collector.sh" diff --git a/roles/osd/templates/bs-frag-score.sh.j2 b/roles/osd/templates/bs-frag-score.sh.j2 new file mode 100644 index 0000000..c433e3d --- /dev/null +++ b/roles/osd/templates/bs-frag-score.sh.j2 @@ -0,0 +1,4 @@ +#!/bin/bash +# {{ ansible_managed }} + +ceph-volume lvm list|grep "osd id" |grep -o [0-9]*| xargs -i sh -c 'echo bluestore_allocator_score_block{osd=osd.{}} $(ceph daemon osd.{} bluestore allocator score block | grep fragmentation_rating|cut -d ':' -f2) $(date +%s)' diff --git a/roles/osd/templates/prom-bs-frag-score-collector.sh.j2 b/roles/osd/templates/prom-bs-frag-score-collector.sh.j2 new file mode 100644 index 0000000..5fb33cb --- /dev/null +++ b/roles/osd/templates/prom-bs-frag-score-collector.sh.j2 @@ -0,0 +1,15 @@ +#!/bin/bash +# {{ ansible_managed }} + +export TMPFILE=/tmp/bluestore_allocator_score_block.prom.$$ +osd_path=$(find /var/lib/ceph/{{ ceph_mon_fsid }}/ -type d -name "osd.*"| head -n 1) +if [ -z $osd_path ]; then + cephadm --image "{{ cephadm_image }}" shell --fsid "{{ ceph_mon_fsid }}" \ + --config "$osd_path/config" \ + -m /var/lib/cron/bs-frag-score.sh -- ./mnt/bs-frag-score.sh > TMPFILE +else + cephadm --image "{{ cephadm_image }}" shell --fsid "{{ ceph_mon_fsid }}" \ + -m /var/lib/cron/bs-frag-score.sh -- ./mnt/bs-frag-score.sh > TMPFILE +fi + +mv $TMPFILE /tmp/bluestore_allocator_score_block.prom