利用Ansible Playbook批量部署node_exporter
之前有翻译过一系列Grafana配置Graphite的文章。传送门
在用过Prometheus之后,发现Prometheus配合Grafana也是天造的一对,以设的一双。
对于服务器基础指标监控而言,Prometheus通过node_exporter来收集数据做为数据源,提供了各种与硬件和内核相关的详细指标。
下面分享一个我正在使用的Ansible Playbook,用于批量部署node_exporter到多个目标主机。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| - hosts: yourservers user: root gather_facts: false vars: - user: "prometheus" - group: "prometheus" - node_exporter_package: "node_exporter-0.16.0.linux-amd64"
tasks: - group: name={{ group}} state=present
- name: Add user prometheus user: name={{ user }} shell=/sbin/nologin
- file: path=/usr/local/prometheus owner={{ user}} group={{ group }} mode=750 state=directory
- name: Sync files copy: src={{ item.src }} dest={{ item.dest }} owner={{ user}} group={{ group }} with_items: - {src: "node_exporter.service", dest: "/usr/lib/systemd/system"}
- name: Unpack package unarchive: src={{ node_exporter_package }}.tar.gz dest=/usr/local/prometheus owner={{ user }} group={{ group }} creates=/usr/local/prometheus/node_exporter
- name: Rename the path command: mv /usr/local/prometheus/{{ node_exporter_package }} /usr/local/prometheus/node_exporter creates=/usr/local/prometheus/node_exporter
- file: path=/usr/local/prometheus/node_exporter owner={{ user}} group={{ group }} mode=750
- name: Start service prometheus, if not running service: name: node_exporter.service state: started
|
注意:软件采用的是提前下载至本地然后同步到目标主机的方式,也是线上部署最为稳妥的方式。
Grafana美图赏析: