上一篇介绍的Prometheus的安装,比较简单。node_exporter安装也比较简单,但是我们要考虑这个 客户端是非常多的,为例后期模板和数据查看更具体做出以下规划:
- 使用ansible-playbook 推送安装
- Prometheus使用consul做客户端发现
- 根据项目、环境、应用类型、部署方式作为标签推送到consul
- 启动方式使用supervisor管理
下面就请跟着作者一起做
ansible-playbook目录:
cat defaults/main.yaml
这一部分也可以放在group_vars下面统一管理
supervisord: /etc/supervisord.dexporter: /opt/node_exporternode_service: node_exporterconsul_register: http://172.20.20.224:8500/v1/catalog/register
cat handlers/main.yaml
---- name: restart supervisord service: name=supervisord state=restarted
cat tasks/main.yaml
推送consul信息 也可使用ansible自带的consul模块,我这里使用的是文本加api的方式
---- name: create {{ node_service }} conf template: src=consul_linux_metric.json.j2 dest=/opt/linux_metric.json register: status- name: register {{ node_service }} shell: curl -X PUT -T {{ status.dest }} {{ consul_register }} && rm -f /opt/linux_metric.json when: status.changed == true- name: mkdir {{ exporter }} file: path={{ exporter }} state=directory mode=755- name: copy {{ node_service }} copy: src={{ node_service }} dest={{ exporter }}/{{ node_service }} mode=755 - name: create node_exporter supervisord config template: src=supervisor_node_exporter.conf.j2 dest={{ supervisord }}/supervisor_node_exporter.conf notify: restart supervisord when: ansible_distribution_major_version == "7"- name: create node_exporter supervisord config template: src=supervisord2.conf.j2 dest=/etc/supervisord.conf notify: restart supervisord when: ansible_distribution_major_version == "6"
cat templates/consul_linux_metric.json.j2
{ "Datacenter": "ssic-1