今天要在 app 的容器裡安插我們的 agent,我們要裝的是 Telegraf 和 Node Exporter
具體來說我們會新增兩個 role 來做這兩件事
新增的 role 內容大概如下
# roles/install_telegraf/tasks/main.yml
---
- name: Install telegraf
apt:
deb: https://dl.influxdata.com/telegraf/releases/telegraf_1.15.3-1_amd64.deb
tags:
- telegraf
- name: Copy telegraf.conf into target machine
copy:
src: telegraf.conf
dest: /etc/telegraf/telegraf.conf
owner: root
group: root
mode: '0644'
tags:
- telegraf
- name: Enable and start telegraf
systemd:
name: telegraf
enabled: yes
state: started
tags:
- telegraf
# roles/install_node_exporter/tasks/main.yml
---
- name: Copy node_exporter to /usr/local/bin
copy:
src: node_exporter
dest: /usr/local/bin/node_exporter
owner: root
group: root
mode: '0755'
tags:
- node_exporter
- name: Install systemd service file
copy:
src: node_exporter.service
dest: /etc/systemd/system/node_exporter.service
owner: root
group: root
tags:
- node_exporter
- name: Systemd daemon-reload
systemd:
daemon_reload: yes
tags:
- node_exporter
- name: Enable and start node_exporter
systemd:
name: node_exporter
state: started
enabled: yes
tags:
- node_exporter
在進行新的設定前,要先執行 terraform destroy
,不然 Terraform 會爛掉
這部分是 Proxmox provider 的問題,好像暫時無解
設定好後,記得回到 TSDB 的機器裡調整 Prometheus 的設定,讓 Prometheus 對 app 裡的 node exporter 拉資料
最後,在 Grafana 內設定/匯入面板,我們就能看到我們的機器狀態了!