Added shared memory check
This commit is contained in:
parent
51b6fe3ff8
commit
bd531dd416
3 changed files with 46 additions and 2 deletions
|
|
@ -96,6 +96,7 @@ need_soft:
|
|||
- zoxide
|
||||
- logrotate
|
||||
- cron
|
||||
- lynx
|
||||
smtp_host:
|
||||
smtp_port:
|
||||
smtp_user:
|
||||
|
|
|
|||
27
roles/node_exporter_install/files/collect-shm-metrics.sh
Normal file
27
roles/node_exporter_install/files/collect-shm-metrics.sh
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
OUTPUT="/var/lib/node_exporter/textfile_collector/shm_usage.prom"
|
||||
TMP=$(mktemp)
|
||||
|
||||
echo "# HELP container_shm_usage_bytes Shared memory usage in bytes" > $TMP
|
||||
echo "# TYPE container_shm_usage_bytes gauge" >> $TMP
|
||||
echo "# HELP container_shm_size_bytes Shared memory total size in bytes" >> $TMP
|
||||
echo "# TYPE container_shm_size_bytes gauge" >> $TMP
|
||||
|
||||
while IFS= read -r line; do
|
||||
pid=$(echo "$line" | awk '{print $1}')
|
||||
container=$(echo "$line" | awk '{print $2}' | tr -d '/')
|
||||
|
||||
if [ "$pid" = "0" ] || [ -z "$pid" ]; then continue; fi
|
||||
|
||||
df_out=$(nsenter -t "$pid" -m df -B1 /dev/shm 2>/dev/null | tail -1)
|
||||
total=$(echo "$df_out" | awk '{print $2}')
|
||||
used=$(echo "$df_out" | awk '{print $3}')
|
||||
|
||||
if [ -n "$used" ] && [ -n "$total" ]; then
|
||||
echo "container_shm_usage_bytes{name=\"$container\"} $used" >> $TMP
|
||||
echo "container_shm_size_bytes{name=\"$container\"} $total" >> $TMP
|
||||
fi
|
||||
done < <(docker ps -q | xargs docker inspect --format '{{.State.Pid}} {{.Name}}' 2>/dev/null)
|
||||
|
||||
mv $TMP $OUTPUT
|
||||
chmod 644 $OUTPUT
|
||||
|
|
@ -20,8 +20,7 @@
|
|||
dest: "{{ node_exporter_install_node_exporter_bin_path }}"
|
||||
mode: '0755'
|
||||
remote_src: true
|
||||
when:
|
||||
- node_exporter_download_check is changed or node_exporter_version_check.stdout | length == 0
|
||||
when: node_exporter_download_check is changed or node_exporter_version_check.stdout | length == 0
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
|
||||
- name: Create node_exporter group (optional fixed GID)
|
||||
|
|
@ -73,6 +72,23 @@
|
|||
user: root
|
||||
when: inventory_hostname is match("^PTAF")
|
||||
|
||||
- name: Copy script shared memory check
|
||||
ansible.builtin.copy:
|
||||
src: files/collect-shm-metrics.sh
|
||||
dest: /usr/local/bin/collect-shm-metrics.sh
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0744'
|
||||
when: inventory_hostname is match("^PTAF")
|
||||
|
||||
- name: Create cron job for shared memory check
|
||||
ansible.builtin.cron:
|
||||
name: "Collect Docker shared memory check"
|
||||
minute: "*/1"
|
||||
job: "/usr/local/bin/collect-shm-metrics.sh"
|
||||
user: root
|
||||
when: inventory_hostname is match("^PTAF")
|
||||
|
||||
- name: Copy script for docker CPU check
|
||||
ansible.builtin.copy:
|
||||
src: files/docker-cpu-metrics.sh
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue