新增部署Prometheus监控工具脚本;更新README.md文件

This commit is contained in:
huty 2023-12-12 16:08:29 +08:00 committed by huty
parent 32e4e8070b
commit 30c8ad0f9a
98 changed files with 4591 additions and 2 deletions

View File

@ -1,3 +1,92 @@
# ansible_tools # Ansible 示例
## prometheus
使用 ansible 部署 Prometheus 监控组件
<br/>
ansible 脚本工具 **参数说明:**
`e` :配置文件/配置项
`cmd`
- `install` :安装
   - `remove` :卸载
`t` Tag标签
- `all` :全部服务
- `server` Prometheus Server 相关服务Prometheus Server、Grafana、Alertmanager、Prometheus Alert、Prometheus Webhook Dingtalk、Loki
- `exporter` Prometheus Exporter 相关服务Node Exporter、CAdvisor、Mysqld Exporter、Mongodb Exporter、Redis Exporter、Rabbitmq Exporter、Rocketmq Exporter、Elasticsearch Exporter、Zookeeper Exporter、JMX Exporter、Nginx Prometheus Exporter、Blackbox Exporter、Grafana Promtail
- `dockerce` Docker 服务
- `node` Prometheus Node Exporter
- `docker` Prometheus CAdvisor
- `mysql` Prometheus Mysqld Exporter
- `mongodb` Prometheus Mongodb Exporter
- `redis` Prometheus Redis Exporter
- `rabbitmq` Prometheus Rabbitmq Exporter
- `rocketmq` Prometheus Rocketmq Exporter
- `elasticsearch` Prometheus Elasticsearch Exporter
- `zookeeper` Prometheus Zookeeper Exporter
- `jmx` Prometheus JMX Exporter
- `nginx` Nginx Prometheus Exporter
  - `blackbox` Prometheus Blackbox Exporter
  - `promtail` Grafana Promtail
<br/>
**安装:**
**安装全部组件:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=install -t all
```
**仅安装 server 相关组件:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=install -t server
```
**仅安装 exporter 相关组件:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=install -t exporter
```
**安装自定义组件:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=install -t 组件名称(名单见上方说明)
```
示例:安装 server 和 node exporter、cadvisor、blackbox exporter、promtail
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=install -t server,node,docker,blackbox,promtail
```
**仅安装 Docker 服务:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=install -t dockerce
```
**卸载:**
**卸载全部组件:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=remove -t all
```
**仅卸载 server 相关组件:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=remove -t server
```
**仅卸载 exporter 相关组件:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=remove -t exporter
```
**卸载自定义组件:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=remove -t 组件名称(名单见上方说明)
```
示例:卸载 server 和 node exporter、cadvisor、blackbox exporter、promtail
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=remove -t server,node,docker,blackbox,promtail
```
**卸载 Docker 服务:**
```shell
ansible-playbook /etc/ansible/roles/role.yml -e @/etc/ansible/roles/conf/extend.yml -e cmd=remove -t dockerce
```
**注意:**
1. 当前仅测试部署 Server 相关、Node Exporter、cAdvisor
2. Prometheus Alert、Prometheus Mongodb Exporter、Prometheus Rocketmq Exporter、Prometheus JMX Exporter、Prometheus Zookeeper Exporter 仅支持 x86_64 架构处理器,故当服务器 CPU 架构不为 x86_64 时对应的服务不会安装tag 也无效。
3. 当主机已经安装 Docker 服务时,需要先创建对应的 Docker 网络,然后再执行脚本
```bash
docker network create Docker网络名称 --subnet Docker网络网段
```
示例如下:
```bash
docker network create --driver bridge --opt encrypted:'true' --subnet 10.21.22.0/24 prometheus
```

87
prometheus/hosts Normal file
View File

@ -0,0 +1,87 @@
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
# Ex 1: Ungrouped hosts, specify before any group headers.
## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10
# Ex 2: A collection of hosts belonging to the 'webservers' group
## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110
# If you have multiple hosts following a pattern you can specify
# them like this:
## www[001:006].example.com
# Ex 3: A collection of database servers in the 'dbservers' group
## [dbservers]
##
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57
# Here's another example of host ranges, this time there are no
# leading 0s:
## db-[99:101]-node.example.com
[dockerce]
127.0.0.1
[server]
127.0.0.1
[node]
127.0.0.1
[docker]
127.0.0.1
[blackbox]
127.0.0.1
[mysql]
127.0.0.1
[mongodb]
127.0.0.1
[redis]
127.0.0.1
[rabbitmq]
127.0.0.1
[rocketmq]
127.0.0.1
[elasticsearch]
127.0.0.1
[zookeeper]
127.0.0.1
[jmx]
127.0.0.1
[nginx]
127.0.0.1
[promtail]
127.0.0.1

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,71 @@
---
# 校验 Alertmanager 是否安装
- name: '<{{ cmd | upper }}> | 校验 Alertmanager 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Alertmanager
- block:
- name: '<{{ cmd | upper }}> | 创建 Alertmanager 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ alertmanager.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 安装 Alertmanager'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ alertmanager.dir.main }}/docker-compose.yml'
- src: conf/alertmanager.yml.j2
dest: '{{ alertmanager.dir.conf }}/alertmanager.yml'
- name: '<{{ cmd | upper }}> | 初始化 Alertmanager 模板文件'
copy:
src: '{{ item }}'
dest: '{{ alertmanager.dir.template }}'
with_fileglob: 'files/template/*'
- name: '<{{ cmd | upper }}> | 启动 Alertmanager 容器'
shell: |
. /etc/profile
chown -R 65534.65534 {{ alertmanager.dir.conf }} {{ alertmanager.dir.template }}
cd {{ alertmanager.dir.main }}
docker-compose down
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 Alertmanager 服务启动'
wait_for:
port: '{{ alertmanager.port }}'
- name: '<{{ cmd | upper }}> | 创建 Alertmanager 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- alertmanager.enable
# 卸载 Alertmanager
- block:
- name: '<{{ cmd | upper }}> | 卸载 Alertmanager'
shell: |
. /etc/profile
cd {{ alertmanager.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Alertmanager 相关文件'
shell: |
rm -rf {{ alertmanager.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- alertmanager.enable

View File

@ -0,0 +1,42 @@
global:
resolve_timeout: 5m
route:
group_by: ['env','app','type','name']
group_wait: 30s
group_interval: 30s
repeat_interval: 1h
receiver: 'dingtalk'
{% if prometheus_alert.enable %}
routes:
- receiver: 'message'
continue: true
match:
severity: emergency
- receiver: 'dingtalk'
continue: true
match_re:
severity: critical|warning
{% endif %}
receivers:
{% if prometheus_alert.enable %}
- name: 'dingtalk'
webhook_configs:
- url: 'http://{{ groups.server.0 }}:{{ prometheus_alert.port }}/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=https://oapi.dingtalk.com/robot/send?access_token={{ alert.dingtalk.access_token }}'
- name: 'message'
webhook_configs:
- url: 'http://{{ groups.server.0 }}:{{ prometheus_alert.port }}/prometheusalert?type={{ alert.message.type }}dx&tpl=prometheus-dx&phone={{ alert.message.phone }}'
{% elif prometheus_webhook_dingtalk.enable -%}
- name: 'dingtalk'
webhook_configs:
- url: 'http://{{ groups.server.0 }}:{{ prometheus_webhook_dingtalk.port }}/dingtalk/webhook_legacy/send'
send_resolved: true
{% endif %}
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['env','app','type','name']

View File

@ -0,0 +1,21 @@
version: "3.9"
services:
alertmanager:
image: {{ alertmanager.image }}
container_name: {{ docker.network.name }}-alertmanager
hostname: alertmanager
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ alertmanager.dir.conf }}/alertmanager.yml:/etc/alertmanager/alertmanager.yml
- {{ alertmanager.dir.template }}:/etc/alertmanager/template
networks:
- {{ docker.network.name }}
ports:
- {{ alertmanager.port }}:9093
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,63 @@
---
# 校验 Blackbox Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Blackbox Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Blackbox Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Blackbox Exporter 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ blackbox_exporter.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 安装 Blackbox Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ blackbox_exporter.dir.main }}/docker-compose.yml'
- src: conf/blackbox.yml.j2
dest: '{{ blackbox_exporter.dir.conf }}/blackbox.yml'
- name: '<{{ cmd | upper }}> | 启动 Blackbox Exporter 容器'
shell: |
. /etc/profile
chown -R 65534.65534 {{ blackbox_exporter.dir.conf }}
cd {{ blackbox_exporter.dir.main }}
docker-compose down
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 Blackbox Exporter 服务启动'
wait_for:
port: '{{ blackbox_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Blackbox Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Blackbox Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Blackbox Exporter'
shell: |
. /etc/profile
cd {{ blackbox_exporter.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Blackbox Exporter 相关文件'
shell: |
rm -rf {{ blackbox_exporter.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,50 @@
modules:
http_2xx:
prober: http
timeout: 10s
http_post_2xx:
prober: http
http:
method: POST
tcp_connect:
prober: tcp
pop3s_banner:
prober: tcp
tcp:
query_response:
- expect: "^+OK"
tls: true
tls_config:
insecure_skip_verify: false
grpc:
prober: grpc
grpc:
tls: true
preferred_ip_protocol: "ip4"
grpc_plain:
prober: grpc
grpc:
tls: false
service: "service1"
ssh_banner:
prober: tcp
tcp:
query_response:
- expect: "^SSH-2.0-"
- send: "SSH-2.0-blackbox-ssh-check"
irc_banner:
prober: tcp
tcp:
query_response:
- send: "NICK prober"
- send: "USER prober prober prober :prober"
- expect: "PING :([^ ]+)"
send: "PONG ${1}"
- expect: "^:[^ ]+ 001"
icmp:
prober: icmp
icmp_ttl5:
prober: icmp
timeout: 5s
icmp:
ttl: 5

View File

@ -0,0 +1,22 @@
version: "3.9"
services:
blackbox-exporter:
image: {{ blackbox_exporter.image }}
container_name: {{ docker.network.name }}-blackbox-exporter
hostname: blackbox-exporter
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ blackbox_exporter.dir.conf }}/blackbox.yml:/etc/blackbox_exporter/config/blackbox.yml:ro
networks:
- {{ docker.network.name }}
ports:
- {{ blackbox_exporter.port }}:9115
environment:
- config.file=/etc/blackbox_exporter/config/blackbox.yml
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,65 @@
---
# 校验 cAdvisor 是否安装
- name: '<{{ cmd | upper }}> | 校验 cAdvisor 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 cAdvisor
- block:
- name: '<{{ cmd | upper }}> | 创建 cAdvisor 相关目录'
file:
path: '{{ cadvisor.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 cAdvisor'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ cadvisor.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 配置部署主机'
shell: |
mount -o remount,rw '/sys/fs/cgroup'
sudo ln -s /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuacct,cpu
ignore_errors: true
- name: '<{{ cmd | upper }}> | 启动 cAdvisor 容器'
shell: |
. /etc/profile
cd {{ cadvisor.dir }}
docker-compose down
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 cAdvisor 服务启动'
wait_for:
port: '{{ cadvisor.port }}'
- name: '<{{ cmd | upper }}> | 创建 cAdvisor 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 cAdvisor
- block:
- name: '<{{ cmd | upper }}> | 卸载 cAdvisor'
shell: |
. /etc/profile
cd {{ cadvisor.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 cAdvisor 相关文件'
shell: |
rm -rf {{ cadvisor.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,24 @@
version: "3.9"
services:
cadvisor:
image: {{ cadvisor.image }}
container_name: {{ docker.network.name }}-cadvisor
hostname: cadvisor
restart: always
privileged: true
volumes:
- /etc/localtime:/etc/localtime:ro
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
networks:
- {{ docker.network.name }}
ports:
- {{ cadvisor.port }}:8080
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

Binary file not shown.

View File

@ -0,0 +1,408 @@
---
# 部署目录(部署时会在此目录下生成各服务的子目录)
base_dir: /opt
# Docker 配置
docker:
## Docker Engine 安装包名称
package: docker-24.0.7.tgz
## Docker 部署目录
dir:
### 主目录
main: '{{ base_dir }}/docker'
### 可执行文件目录
bin: '{{ base_dir }}/docker/bin'
### 数据目录
data: '{{ base_dir }}/docker/data'
## 部署 Prometheus 相关组件时使用的网络
network:
name: prometheus
subnet: 10.21.22.0/24
# Prometheus Server 配置
prometheus:
## 镜像
image: prom/prometheus:v2.48.0
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/prometheus'
### 配置文件目录
conf: '{{ base_dir }}/prometheus/conf'
### 告警规则文件目录
rules: '{{ base_dir }}/prometheus/rules'
### 数据目录
data: '{{ base_dir }}/prometheus/data'
## 端口号
port: 9090
# Grafana 配置
grafana:
## 是否部署 Grafana
enable: true
## 镜像
image: grafana/grafana:10.2.2
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/grafana'
### 配置文件目录
conf: '{{ base_dir }}/grafana/conf'
### 数据目录
data: '{{ base_dir }}/grafana/data'
## 端口号
port: 3000
# Alertmanager 配置
alertmanager:
## 是否部署 Alertmanager
enable: true
## 镜像
image: prom/alertmanager:v0.26.0
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/alertmanager'
### 配置文件目录
conf: '{{ base_dir }}/alertmanager/conf'
### 模板目录
template: '{{ base_dir }}/alertmanager/template'
## 端口号
port: 9093
# Prometheus Alert 配置 Prometheus Alert 和 Prometheus Webhook Dingtalk 只能开启其中一个,不能同时开启)
prometheus_alert:
## 是否启用 Prometheus Alert
enable: true
## 镜像
image: feiyu563/prometheus-alert:v4.9
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/prometheus-alert'
### 配置文件目录
conf: '{{ base_dir }}/prometheus-alert/conf'
### 数据库目录
db: '{{ base_dir }}/prometheus-alert/db'
### 数据文件目录
logs: '{{ base_dir }}/prometheus-alert/logs'
## 端口号
port: 9080 #8080
## 用户名
user: 'admin'
## 密码
password: '123456'
## 标题
title: 'PrometheusAlert'
## 访问 URL
url: 'https://alert.hty1024.com'
# Prometheus Webhook Dingtalk 配置 Prometheus Alert 和 Prometheus Webhook Dingtalk 只能开启其中一个,不能同时开启)
prometheus_webhook_dingtalk:
## 是否启用 Prometheus Webhook Dingtalk
enable: false
## 镜像
image: timonwong/prometheus-webhook-dingtalk:v2.1.0
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/prometheus-webhook-dingtalk'
### 配置文件目录
conf: '{{ base_dir }}/prometheus-webhook-dingtalk/conf'
### 模板文件目录
template: '{{ base_dir }}/prometheus-webhook-dingtalk/template'
## 端口号
port: 9060 #8060
# 告警配置
alert:
## 钉钉机器人
dingtalk:
access_token: '123456789'
## 短信
message:
type: 'tx'
phone: '12300001111'
### 注意:部署完成之后,需要手动将 prometheus-webhook-dingtalk/conf/config.yml 文件的 “【【” 替换为 “{{”,将 “】】” 替换为 “}}”
title: '【【 template "legacy.title" . 】】'
text: '【【 template "email.to.message" . 】】'
# Loki 配置
loki:
## 是否启用 Loki
enable: true
## 镜像
image: grafana/loki:2.9.2
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/loki'
### 配置文件目录
conf: '{{ base_dir }}/loki/conf'
## 端口号
port: 3100
# Node Exporter 配置
node_exporter:
## 是否启用 Node Exporter
enable: true
## 镜像
image: prom/node-exporter:v1.7.0
## 部署目录
dir: '{{ base_dir }}/exporter/node-exporter'
## 端口号
port: 9100
# CAdvisor 配置
cadvisor:
## 是否启用 CAdvisor
enable: true
## 镜像
image: zcube/cadvisor:v0.45.0
## 部署目录
dir: '{{ base_dir }}/exporter/cadvisor'
## 端口号
port: 9180 #8088
# Blackbox Exporter 配置
blackbox_exporter:
## 是否启用 Blackbox Exporter
enable: true
## 镜像
image: prom/blackbox-exporter:v0.24.0
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/exporter/blackbox'
### 配置文件目录
conf: '{{ base_dir }}/exporter/blackbox/conf'
## 端口号
port: 9115
## 探测 URL
targets:
- https://hty1024.com
- https://www.hty1024.com
- https://wiki.hty1024.com
- https://git.hty1024.com
# Mysqld Exporter 配置
mysqld_exporter:
## 镜像
image: prom/mysqld-exporter:v0.15.0
## 部署目录
dir: '{{ base_dir }}/exporter/mysqld-exporter'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### Mysqld Exporter 端口号
port: 9104
### MySQL URL
url: 127.0.0.1:3306
### MySQL 用户名
user: exporter
### MySQL 密码
password: 123456
### MySQL 数据库
database:
- host: 192.168.1.1
port: 9104
url: 192.168.1.1
user: exporter
password: 123456
database:
# MongoDB Exporter 配置
mongodb_exporter:
## 镜像
image: bitnami/mongodb-exporter:0.40.0
## 部署目录
dir: '{{ base_dir }}/exporter/mongodb-exporter'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### MongoDB Exporter 端口号
port: 9126
### MongoDB URL
url: 127.0.0.1:27017
- host: 192.168.1.1
port: 9126
url: 192.168.1.1:27017
# Redis Exporter 配置
redis_exporter:
## 镜像
image: oliver006/redis_exporter:v1.55.0
## 部署目录
dir: '{{ base_dir }}/exporter/redis-exporter'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### Redis Exporter 端口号
port: 9121
### Redis URL
url: 127.0.0.1:6379
### Redis 密码
password: 123456
- host: 192.168.1.1
port: 9121
url: 127.0.0.1:6379
password: 123456
# Rabbitmq Exporter 配置
rabbitmq_exporter:
## 镜像
image: kbudde/rabbitmq-exporter:1.0.0-RC19
## 部署目录
dir: '{{ base_dir }}/exporter/rabbitmq-exporter'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### Rabbitmq Exporter 端口号
port: 9419
### RabbitMQ URL
url: 127.0.0.1:15672
### RabbitMQ 用户名
user: root
### RabbitMQ 密码
password: 123456
- host: 192.168.1.1
port: 9419
url: 127.0.0.1:15672
user: root
password: 123456
# Rocketmq Exporter 配置
rocketmq_exporter:
## 镜像
image: bitnami/java:1.8.392-9
## jar 包名称
jar: rocketmq-exporter-0.0.2-SNAPSHOT.jar
## 部署目录
dir: '{{ base_dir }}/exporter/rocketmq-exporter'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### Rocketmq Exporter 端口号
port: 5557
### Rocketmq URL
url: 127.0.0.1:9876
### Rocketmq 版本号
version: V4_9_4
- host: 192.168.1.1
port: 5557
url: 127.0.0.1:9876
version: V4_9_4
# Elasticsearch Exporter 配置
elasticsearch_exporter:
## 镜像
image: prometheuscommunity/elasticsearch-exporter:v1.6.0
## 部署目录
dir: '{{ base_dir }}/exporter/elasticsearch-exporter'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### Elasticsearch Exporter 端口号
port: 9114
### Elasticsearch URL
url: 127.0.0.1:9200
- host: 192.168.1.1
port: 9114
url: 127.0.0.1:9200
# Zookeeper Exporter 配置
zookeeper_exporter:
## 镜像
image: dabealu/zookeeper-exporter:v0.1.13
## 部署目录
dir: '{{ base_dir }}/exporter/zookeeper-exporter'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### Zookeeper Exporter 端口号
port: 9141
### Zookeeper URL
url: 127.0.0.1:2181
- host: 192.168.1.1
port: 9141
url: 127.0.0.1:2181
# JMX Exporter 配置
jmx_exporter:
## 运行模式( javaagentJava Agent 模式运行httpserverHTTP Server 模式运行)
model: httpserver
## 镜像
image: bitnami/java:1.8.392-9
## jar 包名称
jar: jmx_prometheus_httpserver-0.17.2.jar
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/exporter/jmx-exporter'
### 配置文件目录
conf: '{{ base_dir }}/exporter/jmx-exporter/conf'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### JMX Exporter 端口号
port: 9151
### JMX Exporter URL
url: localhost:8080
- host: 192.168.1.1
port: 9151
url: localhost:8080
# Nginx Prometheus Exporter 配置
nginx_prometheus_exporter:
## 镜像
image: nginx/nginx-prometheus-exporter:0.11.0
## 部署目录
dir: '{{ base_dir }}/exporter/nginx-prometheus-exporter'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### Nginx Prometheus Exporter 端口号
port: 9113
### Nginx URL
url: http://127.0.0.1/nginx_status
- host: 192.168.1.1
port: 9113
url: http://127.0.0.1/nginx_status
# Promtail 配置
promtail:
## 镜像
image: grafana/promtail:2.9.2
## 部署目录
dir:
### 主目录
main: '{{ base_dir }}/exporter/promtail'
### 配置文件目录
conf: '{{ base_dir }}/exporter/promtail/conf'
## 采集节点
nodes:
### 主机
- host: 127.0.0.1
### Promtail 端口号
port: 9188
### 需要收集的日志目录
targets:
#### 名称
- name: system
#### 路径
path: /var/log
- host: 192.168.1.1
port: 9188
targets:
- name: system
path: /var/log

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,159 @@
---
# 校验 Docker Engine 是否安装
- name: '<{{ cmd | upper }}> | 校验 Docker Engine 是否安装'
shell: |
. /etc/profile
docker info
register: docker_ret
ignore_errors: true
# 校验 Docker Compose 是否安装
- name: '<{{ cmd | upper }}> | 校验 Docker Compose 是否安装'
shell: |
. /etc/profile
docker-compose version
register: compose_ret
ignore_errors: true
# 安装 Docker Engine
- block:
- name: '<{{ cmd | upper }}> | 编辑 ~/.bashrc 文件环境变量'
blockinfile:
path: ~/.bashrc
block: |
export DOCKER_HOME={{ docker.dir.bin }}
export PATH=$PATH:$DOCKER_HOME
marker: '#{mark} DOCKER Environment'
insertbefore: 'BOF'
- name: '<{{ cmd | upper }}> | 编辑 /etc/profile 文件环境变量'
blockinfile:
path: /etc/profile
block: |
export DOCKER_HOME={{ docker.dir.bin }}
export PATH=$PATH:$DOCKER_HOME
marker: '#{mark} DOCKER Environment'
insertafter: 'EOF'
- name: '<{{ cmd | upper }}> | 创建 Docker 用户组'
shell:
groupadd -r docker
ignore_errors: yes
- name: '<{{ cmd | upper }}> | 创建 Docker 相关目录并更新系统配置'
shell: |
source /etc/profile
mkdir -p {{ docker.dir.main }}
mkdir -p {{ docker.dir.bin }}
mkdir -p {{ docker.dir.data }}
mkdir -p /etc/docker
if [[ -e /etc/docker/daemon.json ]];then
cp /etc/docker/daemon.json /etc/docker/daemon.json.bak
fi
modprobe br_netfilter
echo 'net.bridge.bridge-nf-call-ip6tables = 1' > /etc/sysctl.d/docker.conf
echo 'net.bridge.bridge-nf-call-iptables = 1' >> /etc/sysctl.d/docker.conf
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.d/docker.conf
sysctl --system
- name: '<{{ cmd | upper }}> | 安装 Docker Engine'
unarchive:
src: 'files/{{ ansible_architecture }}/{{ docker.package }}'
dest: '{{ docker.dir.bin }}'
mode: 0755
# extra_opts:
# - --strip-components 1
- name: '<{{ cmd | upper }}> | 删除 Docker 临时文件'
shell: |
mv {{ docker.dir.bin }}/docker {{ docker.dir.bin }}/docker-tmp
mv -f {{ docker.dir.bin }}/docker-tmp/* {{ docker.dir.bin }}
rm -rf {{ docker.dir.bin }}/docker-tmp
- name: '<{{ cmd | upper }}> | 初始化 Docker 相关配置文件'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
group: docker
loop:
- src: docker.service.j2
dest: /lib/systemd/system/docker.service
- src: docker.socket.j2
dest: /lib/systemd/system/docker.socket
- src: daemon.json.j2
dest: /etc/docker/daemon.json
- name: '<{{ cmd | upper }}> | 启动 Docker 服务'
systemd:
daemon_reload: yes
state: restarted
name: docker.service
enabled: yes
- name: '<{{ cmd | upper }}> | 创建 Docker 网络'
shell: |
. /etc/profile
if docker network ls | grep -q {{ docker.network.name }} ; then
docker network ls
else
docker network create {{ docker.network.name }} --subnet {{ docker.network.subnet }}
fi
- name: '<{{ cmd | upper }}> | 添加 Docker 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- docker_ret.failed
- cmd == "install"
# 安装 Docker Compose
- block:
- name: '<{{ cmd | upper }}> | 安装 Docker Compose'
copy:
src: files/{{ ansible_architecture }}/docker-compose
dest: '{{ docker.dir.bin }}/docker-compose'
mode: 0755
when:
- compose_ret.failed
- cmd == "install"
# 卸载 Docker Compose 和 Docker Engine
- block:
- name: '<{{ cmd | upper }}> | 删除 Docker 网络'
shell: |
docker network rm {{ docker.network.name }}
- name: '<{{ cmd | upper }}> | 停止 Docker 服务'
systemd:
state: stopped
name: docker.service
enabled: no
- name: '<{{ cmd | upper }}> | 清除 Docker 环境变量'
blockinfile:
path: '{{ item }}'
marker: '#{mark} DOCKER Environment'
state: absent
backup: yes
loop:
- ~/.bashrc
- /etc/profile
- name: '<{{ cmd | upper }}> | 卸载 Docker Engine 和 Docker Compose'
file:
path: '{{ item }}'
state: absent
loop:
- /lib/systemd/system/docker.service
- /lib/systemd/system/docker.socket
- '{{ docker.dir.bin }}'
- '{{ docker.dir.data }}'
- '{{ flag }}'
when:
- cmd == "remove"
- not docker_ret.failed

View File

@ -0,0 +1,16 @@
{
"exec-opts" : ["native.cgroupdriver=systemd"],
"log-level": "warn",
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "5"
},
"registry-mirrors": [
"https://dockerproxy.com",
"https://hub-mirror.c.163.com"
],
"bip": "10.21.21.1/24",
"data-root": "{{ docker.dir.data }}",
"live-restore": true
}

View File

@ -0,0 +1,36 @@
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
Requires=docker.socket
[Service]
Type=notify
Environment=PATH={{ docker.dir.bin }}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart={{ docker.dir.bin }}/dockerd -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,13 @@
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,59 @@
---
# 校验 Elasticsearch Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Elasticsearch Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Elasticsearch Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Elasticsearch Exporter 相关目录'
file:
path: '{{ elasticsearch_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 Elasticsearch Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ elasticsearch_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Elasticsearch Exporter 容器'
shell: |
. /etc/profile
cd {{ elasticsearch_exporter.dir }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 Elasticsearch Exporter 服务启动'
# wait_for:
# port: '{{ elasticsearch_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Elasticsearch Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Elasticsearch Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Elasticsearch Exporter'
shell: |
. /etc/profile
cd {{ elasticsearch_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Elasticsearch Exporter 相关文件'
shell: |
rm -rf {{ elasticsearch_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,23 @@
version: "3.9"
services:
elasticsearch-exporter:
image: {{ elasticsearch_exporter.image }}
container_name: {{ docker.network.name }}-elasticsearch-exporter
hostname: elasticsearch-exporter
restart: always
networks:
- {{ docker.network.name }}
{% for node in elasticsearch_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:9114
command:
- "--es.uri=http://{{ node.url }}"
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,66 @@
---
# 校验 Grafana 是否安装
- name: '<{{ cmd | upper }}> | 校验 Grafana 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Grafana
- block:
- name: '<{{ cmd | upper }}> | 创建 Grafana 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ grafana.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 安装 Grafana'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ grafana.dir.main }}/docker-compose.yml'
- src: conf/grafana.ini.j2
dest: '{{ grafana.dir.conf }}/grafana.ini'
- name: '<{{ cmd | upper }}> | 启动 Grafana 容器'
shell: |
. /etc/profile
chown -R 472.472 {{ grafana.dir.data }} {{ grafana.dir.conf }}
cd {{ grafana.dir.main }}
docker-compose down
rm -rf data/*
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 Grafana 服务启动'
wait_for:
port: '{{ grafana.port }}'
- name: '<{{ cmd | upper }}> | 创建 Grafana 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- grafana.enable
# 卸载 Grafana
- block:
- name: '<{{ cmd | upper }}> | 卸载 Grafana'
shell: |
. /etc/profile
cd {{ grafana.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Grafana 相关文件'
shell: |
rm -rf {{ grafana.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- grafana.enable

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,19 @@
version: '3'
services:
grafana:
image: {{ grafana.image }}
container_name: {{ docker.network.name }}-grafana
hostname: grafana
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ grafana.dir.conf }}/grafana.ini:/etc/grafana/grafana.ini
- {{ grafana.dir.data }}:/var/lib/grafana
networks:
- {{ docker.network.name }}
ports:
- {{ grafana.port }}:3000
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,69 @@
---
# 校验 JMX Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 JMX Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 JMX Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 JMX Exporter 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ jmx_exporter.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 准备 JMX Exporter Jar 文件'
copy:
src: files/{{ jmx_exporter.jar }}
dest: '{{ jmx_exporter.dir.main }}/{{ jmx_exporter.jar }}'
- name: '<{{ cmd | upper }}> | 安装 JMX Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.{{ jmx_exporter.model }}.j2
dest: '{{ jmx_exporter.dir.main }}/docker-compose.yml'
- src: conf/config.yaml.{{ jmx_exporter.model }}.j2
dest: '{{ jmx_exporter.dir.conf }}/config.yaml'
- name: '<{{ cmd | upper }}> | 启动 JMX Exporter 容器'
shell: |
. /etc/profile
cd {{ jmx_exporter.dir.main }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 JMX Exporter 服务启动'
# wait_for:
# port: '{{ jmx_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 JMX Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- ansible_architecture == "x86_64"
# 卸载 JMX Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 JMX Exporter'
shell: |
. /etc/profile
cd {{ jmx_exporter.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 JMX Exporter 相关文件'
shell: |
rm -rf {{ jmx_exporter.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- - ansible_architecture == "x86_64"

View File

@ -0,0 +1,7 @@
{% for node in jmx_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
hostPort: {{ node.url }}
{% endif %}
{% endfor %}
rules:
- pattern: ".*"

View File

@ -0,0 +1,2 @@
rules:
- pattern: ".*"

View File

@ -0,0 +1,27 @@
version: "3.9"
services:
jmx-exporter:
image: {{ jmx_exporter.image }}
container_name: {{ docker.network.name }}-jmx-exporter
hostname: jmx-exporter
restart: always
privileged: true
networks:
- {{ docker.network.name }}
{% for node in jmx_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:{{ node.port }}
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ jmx_exporter.dir.main }}/{{ jmx_exporter.jar }}:/jmx-exporter/jmx_prometheus_{{ jmx_exporter.model }}-0.17.2.jar
- {{ jmx_exporter.dir.main }}/conf/config.yaml:/jmx-exporter/config.yaml
command: "java -jar /jmx-exporter/jmx_prometheus_{{ jmx_exporter.model }}-0.17.2.jar {{ node.port }} /jmx-exporter/config.yaml"
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,28 @@
version: "3.9"
services:
jmx-exporter:
image: {{ jmx_exporter.image }}
container_name: {{ docker.network.name }}-jmx-exporter
hostname: jmx-exporter
restart: always
privileged: true
networks:
- {{ docker.network.name }}
{% for node in jmx_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:{{ node.port }}
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ jmx_exporter.dir.main }}/{{ jmx_exporter.jar }}:/jmx-exporter/jmx_prometheus_{{ jmx_exporter.model }}-0.17.2.jar
- {{ jmx_exporter.dir.main }}/conf/config.yaml:/jmx-exporter/config.yaml
environment:
- "JAVA_OPTS=-server -Dname=jmxExporterTest -Duser.timezone=GMT+08 -Xms1024m -Xmx2048m -Xss512k -Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -javaagent:/jmx-exporter/jmx_prometheus_{{ jmx_exporter.model }}-0.17.2.jar={{ node.port }}:/jmx-exporter/config.yaml"
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,65 @@
---
# 校验 Loki 是否安装
- name: '<{{ cmd | upper }}> | 校验 Loki 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Loki
- block:
- name: '<{{ cmd | upper }}> | 创建 Loki 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ loki.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 安装 Loki'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ loki.dir.main }}/docker-compose.yml'
- src: conf/loki-config.yaml.j2
dest: '{{ loki.dir.conf }}/loki-config.yaml'
- name: '<{{ cmd | upper }}> | 启动 Loki 容器'
shell: |
. /etc/profile
chown -R 10001.10001 {{ loki.dir.conf }}
cd {{ loki.dir.main }}
docker-compose down
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 Loki 服务启动'
wait_for:
port: '{{ loki.port }}'
- name: '<{{ cmd | upper }}> | 创建 Loki 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- loki.enable
# 卸载 Loki
- block:
- name: '<{{ cmd | upper }}> | 卸载 Loki'
shell: |
. /etc/profile
cd {{ loki.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Loki 相关文件'
shell: |
rm -rf {{ loki.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- loki.enable

View File

@ -0,0 +1,30 @@
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
instance_addr: 127.0.0.1
kvstore:
store: inmemory
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
ruler:
alertmanager_url: http://{{ groups.server.0 }}:{{ alertmanager.port }}

View File

@ -0,0 +1,21 @@
version: "3.9"
services:
loki:
image: {{ loki.image }}
container_name: {{ docker.network.name }}-loki
hostname: loki
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ loki.dir.conf }}/loki-config.yaml:/etc/loki/loki-config.yaml
networks:
- {{ docker.network.name }}
ports:
- {{ loki.port }}:3100
command: "-config.file=/etc/loki/loki-config.yaml"
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,61 @@
---
# 校验 MongoDB Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 MongoDB Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 MongoDB Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 MongoDB Exporter 相关目录'
file:
path: '{{ mongodb_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 MongoDB Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ mongodb_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 MongoDB Exporter 容器'
shell: |
. /etc/profile
cd {{ mongodb_exporter.dir }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 MongoDB Exporter 服务启动'
# wait_for:
# port: '{{ mongodb_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 MongoDB Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- ansible_architecture == "x86_64"
# 卸载 MongoDB Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 MongoDB Exporter'
shell: |
. /etc/profile
cd {{ mongodb_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 MongoDB Exporter 相关文件'
shell: |
rm -rf {{ mongodb_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- ansible_architecture == "x86_64"

View File

@ -0,0 +1,23 @@
version: "3.9"
services:
mongodb-exporter:
image: {{ mongodb_exporter.image }}
container_name: {{ docker.network.name }}-mongodb-exporter
hostname: mongodb-exporter
restart: always
networks:
- {{ docker.network.name }}
{% for node in mongodb_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:9126
command:
- '--mongodb.uri=mongodb://{{ node.url }}'
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,59 @@
---
# 校验 Mysqld Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Mysqld Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Mysqld Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Mysqld Exporter 相关目录'
file:
path: '{{ mysqld_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 Mysqld Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ mysqld_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Mysqld Exporter 容器'
shell: |
. /etc/profile
cd {{ mysqld_exporter.dir }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 Mysqld Exporter 服务启动'
# wait_for:
# port: '{{ mysqld_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Mysqld Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Mysqld Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Mysqld Exporter'
shell: |
. /etc/profile
cd {{ mysqld_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Mysqld Exporter 相关文件'
shell: |
rm -rf {{ mysqld_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,23 @@
version: "3.9"
services:
mysqld-exporter:
image: {{ mysqld_exporter.image }}
container_name: {{ docker.network.name }}-mysqld-exporter
hostname: mysqld-exporter
restart: always
networks:
- {{ docker.network.name }}
{% for node in mysqld_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:9104
environment:
- DATA_SOURCE_NAME={{ node.user }}:{{ node.password }}@({{ node.url }})/{{ node.database }}
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,59 @@
---
# 校验 Nginx Prometheus Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Nginx Prometheus Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Nginx Prometheus Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Nginx Prometheus Exporter 相关目录'
file:
path: '{{ nginx_prometheus_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 Nginx Prometheus Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ nginx_prometheus_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Nginx Prometheus Exporter 容器'
shell: |
. /etc/profile
cd {{ nginx_prometheus_exporter.dir }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 Nginx Prometheus Exporter 服务启动'
# wait_for:
# port: '{{ nginx_prometheus_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Nginx Prometheus Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Nginx Prometheus Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Nginx Prometheus Exporter'
shell: |
. /etc/profile
cd {{ nginx_prometheus_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Nginx Prometheus Exporter 相关文件'
shell: |
rm -rf {{ nginx_prometheus_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,25 @@
version: "3.9"
services:
nginx-prometheus-exporter:
image: {{ nginx_prometheus_exporter.image }}
container_name: {{ docker.network.name }}-nginx-prometheus-exporter
hostname: nginx-prometheus-exporter
restart: always
privileged: true
networks:
- {{ docker.network.name }}
{% for node in nginx_prometheus_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:9113
volumes:
- /etc/localtime:/etc/localtime:ro
command: "-nginx.scrape-uri={{ node.url }}"
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,59 @@
---
# 校验 Node Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Node Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Node Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Node Exporter 相关目录'
file:
path: '{{ node_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 Node Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ node_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Node Exporter 容器'
shell: |
. /etc/profile
cd {{ node_exporter.dir }}
docker-compose down
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 Node Exporter 服务启动'
wait_for:
port: '{{ node_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Node Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Node Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Node Exporter'
shell: |
. /etc/profile
cd {{ node_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Node Exporter 相关文件'
shell: |
rm -rf {{ node_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,19 @@
version: "3.9"
services:
node-exporter:
image: {{ node_exporter.image }}
container_name: {{ docker.network.name }}-node-exporter
hostname: node-exporter
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
networks:
- {{ docker.network.name }}
ports:
- {{ node_exporter.port }}:9100
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,11 @@
groups:
- name: Blackbox
rules:
- alert: Blackbox 连接失败
expr: probe_success == 0
for: 30s
labels:
severity: emergency
annotations:
summary: Blackbox ({{ $labels.instance }}) 连接失败
description: "Blackbox {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,11 @@
groups:
- name: Docker
rules:
- alert: Docker 连接失败
expr: up{type="docker"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: Docker ({{ $labels.instance }}) 连接失败
description: "Docker {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,11 @@
groups:
- name: ElasticSearch
rules:
- alert: ElasticSearch 连接失败
expr: up{type="elasticsearch"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: ElasticSearch ({{ $labels.instance }}) 连接失败
description: "ElasticSearch {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,11 @@
groups:
- name: MongoDB
rules:
- alert: MongoDB 连接失败
expr: up{type="mongodb"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: MongoDB ({{ $labels.instance }}) 连接失败
description: "MongoDB {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,11 @@
groups:
- name: MySQL
rules:
- alert: MySQL 连接失败
expr: up{type="mysql"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: MySQL ({{ $labels.instance }}) 连接失败
description: "MySQL {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,35 @@
groups:
- name: Node
rules:
- alert: 主机连接失败
expr: up{type="node"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: 主机 ({{ $labels.instance }}) 连接失败
description: "主机 {{ $labels.instance }} 连接失败!"
- alert: 主机 CPU 负载过高
expr: sum by (instance) (avg by (mode, instance) (rate(node_cpu_seconds_total{mode!="idle"}[2m]))) > 0.8
for: 0m
labels:
severity: warning
annotations:
summary: 主机 ({{ $labels.instance }}) CPU 负载过高
description: "主机 {{ $labels.instance }} CPU 负载高于 80%!"
- alert: 主机内存不足
expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 20
for: 2m
labels:
severity: warning
annotations:
summary: 主机 ({{ $labels.instance }}) 内存不足
description: "主机 {{ $labels.instance }} 内存剩余不足20%!"
- alert: 主机磁盘不足
expr: (node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes < 20 and ON (instance, device, mountpoint) node_filesystem_readonly == 0
for: 2m
labels:
severity: warning
annotations:
summary: 主机 ({{ $labels.instance }}) 磁盘不足
description: "主机 {{ $labels.instance }} 磁盘剩余不足20%!"

View File

@ -0,0 +1,11 @@
groups:
- name: Prometheus
rules:
- alert: Prometheus 连接失败
expr: up{type="prometheus"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: Prometheus ({{ $labels.instance }}) 连接失败
description: "Prometheus {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,11 @@
groups:
- name: RabbitMQ
rules:
- alert: RabbitMQ 连接失败
expr: up{type="rabbitmq"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: RabbitMQ ({{ $labels.instance }}) 连接失败
description: "RabbitMQ {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,11 @@
groups:
- name: Redis
rules:
- alert: Redis 连接失败
expr: up{type="redis"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: Redis ({{ $labels.instance }}) 连接失败
description: "Redis {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,11 @@
groups:
- name: RocketMQ
rules:
- alert: RocketMQ 连接失败
expr: up{type="rocketmq"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: RocketMQ ({{ $labels.instance }}) 连接失败
description: "RocketMQ {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,11 @@
groups:
- name: Zookeeper
rules:
- alert: Zookeeper 连接失败
expr: up{type="zookeeper"} == 0
for: 30s
labels:
severity: emergency
annotations:
summary: Zookeeper ({{ $labels.instance }}) 连接失败
description: "Zookeeper {{ $labels.instance }} 连接失败!"

View File

@ -0,0 +1,73 @@
---
# 校验 Prometheus Server 是否安装
- name: '<{{ cmd | upper }}> | 校验 Prometheus Server 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 创建 Prometheus Server 安装目录
- block:
- name: '<{{ cmd | upper }}> | 创建 Prometheus Server 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ prometheus.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 安装 Prometheus Server'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ prometheus.dir.main }}/docker-compose.yml'
- src: conf/prometheus.yml.j2
dest: '{{ prometheus.dir.conf }}/prometheus.yml'
- src: reload.sh.j2
dest: '{{ prometheus.dir.main }}/reload.sh'
- name: '<{{ cmd | upper }}> | 初始化 Prometheus Server 告警规则文件'
copy:
src: '{{ item }}'
dest: '{{ prometheus.dir.rules }}'
with_fileglob: 'files/rules/*.yml'
- name: '<{{ cmd | upper }}> | 启动 Prometheus Server 容器'
shell: |
. /etc/profile
chown -R 65534.65534 {{ prometheus.dir.data }} {{ prometheus.dir.conf }} {{ prometheus.dir.rules }}
chmod +x {{ prometheus.dir.main }}/reload.sh
cd {{ prometheus.dir.main }}
docker-compose down
rm -rf data/*
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 Prometheus Server 服务启动'
wait_for:
port: '{{ prometheus.port }}'
- name: '<{{ cmd | upper }}> | 创建 Prometheus Server 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Prometheus Server
- block:
- name: '<{{ cmd | upper }}> | 卸载 Prometheus Server'
shell: |
. /etc/profile
cd {{ prometheus.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Prometheus Server 相关文件'
shell: |
rm -rf {{ prometheus.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,52 @@
# my global config
global:
scrape_interval: 5s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
{% if alertmanager.enable -%}
alerting:
alertmanagers:
- static_configs:
- targets: ['{{ groups.server.0 }}:{{ alertmanager.port }}']
{% endif %}
rule_files:
- "/etc/prometheus/rules/*.yml"
scrape_configs:
{% if blackbox_exporter.enable -%}
## 探针
- job_name: 'blackbox'
metrics_path: /probe
scrape_interval: 30s
params:
module: [http_2xx]
static_configs:
- targets:
{% for target in blackbox_exporter.targets -%}
- {{ target }}
{% endfor %}
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: {{ groups.blackbox.0 }}:{{ blackbox_exporter.port }}
{% endif %}
## 运维环境
### 采集 prometheus 数据
- job_name: 'ops-prometheus'
static_configs:
### 采集目标1
- targets: ['{{ groups.server.0 }}:{{ prometheus.port }}']
labels:
### 环境test测试环境prod正式环境ops运维环境
env: ops
### 应用prometheusPrometheus
app: prometheus
### 资源类型prometheusPrometheusnode节点机器dockerDockermysqlMySQL
type: prometheus
### 名称(采用 app-ip-type 结构)
# name: prometheus-0-1-prometheus

View File

@ -0,0 +1,23 @@
version: "3.9"
services:
prometheus:
image: {{ prometheus.image }}
container_name: {{ docker.network.name }}-prometheus
hostname: prometheus
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ prometheus.dir.conf }}/prometheus.yml:/etc/prometheus/prometheus.yml
- {{ prometheus.dir.rules }}:/etc/prometheus/rules
- {{ prometheus.dir.data }}:/prometheus/data
networks:
- {{ docker.network.name }}
ports:
- {{ prometheus.port }}:9090
command: "--config.file=/etc/prometheus/prometheus.yml --web.enable-lifecycle"
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1 @@
curl http://{{ inventory_hostname }}:{{ prometheus.port }}/-/reload -X POST

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,66 @@
---
# 校验 PrometheusAlert 是否安装
- name: '<{{ cmd | upper }}> | 校验 PrometheusAlert 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 PrometheusAlert
- block:
- name: '<{{ cmd | upper }}> | 创建 PrometheusAlert 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ prometheus_alert.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 安装 PrometheusAlert'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ prometheus_alert.dir.main }}/docker-compose.yml'
- src: conf/app.conf.j2
dest: '{{ prometheus_alert.dir.conf }}/app.conf'
- name: '<{{ cmd | upper }}> | 启动 PrometheusAlert 容器'
shell: |
. /etc/profile
cd {{ prometheus_alert.dir.main }}
docker-compose down
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 PrometheusAlert 服务启动'
wait_for:
port: '{{ prometheus_alert.port }}'
- name: '<{{ cmd | upper }}> | 创建 PrometheusAlert 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- prometheus_alert.enable
- ansible_architecture == "x86_64"
# 卸载 PrometheusAlert
- block:
- name: '<{{ cmd | upper }}> | 卸载 PrometheusAlert'
shell: |
. /etc/profile
cd {{ prometheus_alert.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 PrometheusAlert 相关目录'
shell: |
rm -rf {{ prometheus_alert.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- prometheus_alert.enable
- ansible_architecture == "x86_64"

View File

@ -0,0 +1,268 @@
#---------------------↓全局配置-----------------------
appname = PrometheusAlert
#登录用户名
login_user={{ prometheus_alert.user }}
#登录密码
login_password={{ prometheus_alert.password }}
#监听地址
httpaddr = "0.0.0.0"
#监听端口
httpport = 8080
runmode = dev
#设置代理 proxy = http://123.123.123.123:8080
proxy =
#开启JSON请求
copyrequestbody = true
#告警消息标题
title={{ prometheus_alert.title }}
#链接到告警平台地址
GraylogAlerturl={{ prometheus_alert.url }}
#钉钉告警 告警logo图标地址
logourl=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png
#钉钉告警 恢复logo图标地址
rlogourl=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png
#短信告警级别(等于3就进行短信告警) 告警级别定义 0 信息,1 警告,2 一般严重,3 严重,4 灾难
messagelevel=3
#电话告警级别(等于4就进行语音告警) 告警级别定义 0 信息,1 警告,2 一般严重,3 严重,4 灾难
phonecalllevel=4
#默认拨打号码(页面测试短信和电话功能需要配置此项)
defaultphone={{ alert.message.phone }}
#故障恢复是否启用电话通知0为关闭,1为开启
phonecallresolved=0
#是否前台输出file or console
logtype=file
#日志文件路径
logpath=logs/prometheusalertcenter.log
#转换Prometheus,graylog告警消息的时区为CST时区(如默认已经是CST时区请勿开启)
prometheus_cst_time=0
#数据库驱动支持sqlite3mysql,postgres如使用mysql或postgres请开启db_host,db_port,db_user,db_password,db_name的注释
db_driver=sqlite3
#db_host=127.0.0.1
#db_port=3306
#db_user=root
#db_password=root
#db_name=prometheusalert
#是否开启告警记录 0为关闭,1为开启
AlertRecord=1
#是否开启告警记录定时删除 0为关闭,1为开启
RecordLive=1
#告警记录定时删除周期,单位天
RecordLiveDay=365
# 是否将告警记录写入es70为关闭1为开启
alert_to_es=0
# es地址是[]string
# beego.Appconfig.Strings读取配置为[]string使用";"而不是","
to_es_url=http://localhost:9200
# to_es_url=http://es1:9200;http://es2:9200;http://es3:9200
# es用户和密码
# to_es_user=username
# to_es_pwd=password
#---------------------↓webhook-----------------------
#是否开启钉钉告警通道,可同时开始多个通道0为关闭,1为开启
open-dingding=1
#默认钉钉机器人地址
ddurl=https://oapi.dingtalk.com/robot/send?access_token={{ alert.dingtalk.access_token }}
#是否开启 @所有人(0为关闭,1为开启)
dd_isatall=0
#是否开启微信告警通道,可同时开始多个通道0为关闭,1为开启
open-weixin=0
#默认企业微信机器人地址
wxurl=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx
#是否开启飞书告警通道,可同时开始多个通道0为关闭,1为开启
open-feishu=0
#默认飞书机器人地址
fsurl=https://open.feishu.cn/open-apis/bot/hook/xxxxxxxxx
#---------------------↓腾讯云接口-----------------------
#是否开启腾讯云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-txdx=0
#腾讯云短信接口key
TXY_DX_appkey=xxxxx
#腾讯云短信模版ID 腾讯云短信模版配置可参考 prometheus告警:{1}
TXY_DX_tpl_id=xxxxx
#腾讯云短信sdk app id
TXY_DX_sdkappid=xxxxx
#腾讯云短信签名 根据自己审核通过的签名来填写
TXY_DX_sign=xxxxx
#是否开启腾讯云电话告警通道,可同时开始多个通道0为关闭,1为开启
open-txdh=0
#腾讯云电话接口key
TXY_DH_phonecallappkey=xxxxx
#腾讯云电话模版ID
TXY_DH_phonecalltpl_id=xxxxx
#腾讯云电话sdk app id
TXY_DH_phonecallsdkappid=xxxxx
#---------------------↓华为云接口-----------------------
#是否开启华为云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-hwdx=0
#华为云短信接口key
HWY_DX_APP_Key=xxxxxxxxxxxxxxxxxxxxxx
#华为云短信接口Secret
HWY_DX_APP_Secret=xxxxxxxxxxxxxxxxxxxxxx
#华为云APP接入<E68EA5><E585A5>址(端口接口地址)
HWY_DX_APP_Url=https://rtcsms.cn-north-1.myhuaweicloud.com:10743
#华为云短信模板ID
HWY_DX_Templateid=xxxxxxxxxxxxxxxxxxxxxx
#华为云签名名称,必须是已审核通过的,与模板类型一致的签名名称,按照自己的实际签名填写
HWY_DX_Signature=华为云
#华为云签名通道号
HWY_DX_Sender=xxxxxxxxxx
#---------------------↓阿里云接口-----------------------
#是否开启阿里云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-alydx=0
#阿里云短信主账号AccessKey的ID
ALY_DX_AccessKeyId=xxxxxxxxxxxxxxxxxxxxxx
#阿里云短信接口密钥
ALY_DX_AccessSecret=xxxxxxxxxxxxxxxxxxxxxx
#阿里云短信签名名称
ALY_DX_SignName=阿里云
#阿里云短信模板ID
ALY_DX_Template=xxxxxxxxxxxxxxxxxxxxxx
#是否开启阿里云电话告警通道,可同时开始多个通道0为关闭,1为开启
open-alydh=0
#阿里云电话主账号AccessKey的ID
ALY_DH_AccessKeyId=xxxxxxxxxxxxxxxxxxxxxx
#阿里云电话接口密钥
ALY_DH_AccessSecret=xxxxxxxxxxxxxxxxxxxxxx
#阿里云电话被叫显号,必须是已购买的号码
ALY_DX_CalledShowNumber=xxxxxxxxx
#阿里云电话文本转语音TTS模板ID
ALY_DH_TtsCode=xxxxxxxx
#---------------------↓容联云接口-----------------------
#是否开启容联云电话告警通道,可同时开始多个通道0为关闭,1为开启
open-rlydh=0
#容联云基础接口地址
RLY_URL=https://app.cloopen.com:8883/2013-12-26/Accounts/
#容联云后台SID
RLY_ACCOUNT_SID=xxxxxxxxxxx
#容联云api-token
RLY_ACCOUNT_TOKEN=xxxxxxxxxx
#容联云app_id
RLY_APP_ID=xxxxxxxxxxxxx
#---------------------↓邮件配置-----------------------
#是否开启邮件
open-email=0
#邮件发件服务器地址
Email_host=smtp.qq.com
#邮件发件服务器端口
Email_port=465
#邮件帐号
Email_user=xxxxxxx@qq.com
#邮件密码
Email_password=xxxxxx
#邮件标题
Email_title=运维告警
#默认发送邮箱
Default_emails=xxxxx@qq.com,xxxxx@qq.com
#---------------------↓七陌云接口-----------------------
#是否开启七陌短信告警通道,可同时开始多个通道0为关闭,1为开启
open-7moordx=0
#七陌账户ID
7MOOR_ACCOUNT_ID=Nxxx
#七陌账户APISecret
7MOOR_ACCOUNT_APISECRET=xxx
#七陌账户短信模板编号
7MOOR_DX_TEMPLATENUM=n
#注意七陌短信变量这里只用一个var1在代码里写死了。
#-----------
#是否开启七陌webcall语音通知告警通道,可同时开始多个通道0为关闭,1为开启
open-7moordh=0
#请在七陌平台添加虚拟服务号、文本节点
#七陌账户webcall的虚拟服务号
7MOOR_WEBCALL_SERVICENO=xxx
# 文本节点里被替换的变量我配置的是text。如果被替换的变量不是text请修改此配置
7MOOR_WEBCALL_VOICE_VAR=text
#---------------------↓telegram接口-----------------------
#是否开启telegram告警通道,可同时开始多个通道0为关闭,1为开启
open-tg=0
#tg机器人token
TG_TOKEN=xxxxx
#tg消息模式 个人消息或者频道消息 0为关闭(推送给个人)1为开启(推送给频道)
TG_MODE_CHAN=0
#tg用户ID
TG_USERID=xxxxx
#tg频道name或者id, 频道name需要以@开始
TG_CHANNAME=xxxxx
#tg api地址, 可以配置为代理地址
#TG_API_PROXY="https://api.telegram.org/bot%s/%s"
#---------------------↓workwechat接口-----------------------
#是否开启workwechat告警通道,可同时开始多个通道0为关闭,1为开启
open-workwechat=0
# 企业ID
WorkWechat_CropID=xxxxx
# 应用ID
WorkWechat_AgentID=xxxx
# 应用secret
WorkWechat_AgentSecret=xxxx
# 接受用户
WorkWechat_ToUser="zhangsan|lisi"
# 接受部门
WorkWechat_ToParty="ops|dev"
# 接受标签
WorkWechat_ToTag=""
# 消息类型, 暂时只支持markdown
# WorkWechat_Msgtype = "markdown"
#---------------------↓百度云接口-----------------------
#是否开启百度云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-baidudx=0
#百度云短信接口AK(ACCESS_KEY_ID)
BDY_DX_AK=xxxxx
#百度云短信接口SK(SECRET_ACCESS_KEY)
BDY_DX_SK=xxxxx
#百度云短信ENDPOINTENDPOINT参数需要用指定区域的域名来进行定义如服务所在区域为北京则为
BDY_DX_ENDPOINT=http://smsv3.bj.baidubce.com
#百度云短信模版ID,根据自己审核通过的模版来填写(模版支持一个参数code如prometheus告警:{code})
BDY_DX_TEMPLATE_ID=xxxxx
#百度云短信签名ID根据自己审核通过的签名来填写
TXY_DX_SIGNATURE_ID=xxxxx
#---------------------↓百度Hi(如流)-----------------------
#是否开启百度Hi(如流)告警通道,可同时开始多个通道0为关闭,1为开启
open-ruliu=0
#默认百度Hi(如流)机器人地址
BDRL_URL=https://api.im.baidu.com/api/msg/groupmsgsend?access_token=xxxxxxxxxxxxxx
#百度Hi(如流)群ID
BDRL_ID=123456
#---------------------↓bark接口-----------------------
#是否开启telegram告警通道,可同时开始多个通道0为关闭,1为开启
open-bark=0
#bark默认地址, 建议自行部署bark-server
BARK_URL=https://api.day.app
#bark key, 多个key使用分割
BARK_KEYS=xxxxx
# 复制, 推荐开启
BARK_COPY=1
# 历史记录保存,推荐开启
BARK_ARCHIVE=1
# 消息分组
BARK_GROUP=PrometheusAlert
#---------------------↓语音播报-----------------------
#语音播报需要配合语音播报插件才能使用
#是否开启语音播报通道,0为关闭,1为开启
open-voice=1
VOICE_IP=127.0.0.1
VOICE_PORT=9999
#---------------------↓飞书机器人应用-----------------------
#是否开启feishuapp告警通道,可同时开始多个通道0为关闭,1为开启
open-feishuapp=1
# APPID
FEISHU_APPID=cli_xxxxxxxxxxxxx
# APPSECRET
FEISHU_APPSECRET=xxxxxxxxxxxxxxxxxxxxxx
# 可填飞书 用户open_id、user_id、union_ids、部门open_department_id
AT_USER_ID="xxxxxxxx"

View File

@ -0,0 +1,22 @@
version: "3.9"
services:
prometheus-alert:
image: {{ prometheus_alert.image }}
container_name: {{ docker.network.name }}-prometheus-alert
hostname: prometheus-alert
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ prometheus_alert.dir.conf }}:/app/conf
- {{ prometheus_alert.dir.db }}:/app/db
- {{ prometheus_alert.dir.logs }}:/app/logs
networks:
- {{ docker.network.name }}
ports:
- {{ prometheus_alert.port }}:8080
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,40 @@
{{ define "email.to.message" }}
{{- if gt (len .Alerts.Firing) 0 -}}
{{- range $index, $alert := .Alerts -}}
========= **监控告警** =========
**告警程序:** Alertmanager
**告警类型:** {{ $alert.Labels.alertname }}
**告警级别:** {{ $alert.Labels.severity }} 级
**告警状态:** {{ .Status }}
**故障主机:** {{ $alert.Labels.instance }} {{ $alert.Labels.device }}
**告警主题:** {{ .Annotations.summary }}
**告警详情:** {{ $alert.Annotations.message }}{{ $alert.Annotations.description}}
**主机标签:** {{ range .Labels.SortedPairs }} </br> [ {{ .Name }}: {{ .Value | markdown | html }} ]
{{- end }} </br>
**故障时间:** {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
========= = end = =========
{{- end }}
{{- end }}
{{- if gt (len .Alerts.Resolved) 0 -}}
{{- range $index, $alert := .Alerts -}}
========= 告警恢复 =========
**告警程序:** Alertmanager
**告警类型:** {{ .Labels.alertname }}
**告警级别:** {{ $alert.Labels.severity }} 级
**告警状态:** {{ .Status }}
**告警主机:** {{ .Labels.instance }}
**告警主题:** {{ $alert.Annotations.summary }}
**告警详情:** {{ $alert.Annotations.message }}{{ $alert.Annotations.description}}
**故障时间:** {{ ($alert.StartsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
**恢复时间:** {{ ($alert.EndsAt.Add 28800e9).Format "2006-01-02 15:04:05" }}
========= = **end** = =========
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,70 @@
---
# 校验 PrometheusWebhookDingtalk 是否安装
- name: '<{{ cmd | upper }}> | 校验 PrometheusWebhookDingtalk 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 PrometheusWebhookDingtalk
- block:
- name: '<{{ cmd | upper }}> | 创建 PrometheusWebhookDingtalk 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ prometheus_webhook_dingtalk.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 安装 PrometheusWebhookDingtalk'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ prometheus_webhook_dingtalk.dir.main }}/docker-compose.yml'
- src: conf/config.yml.j2
dest: '{{ prometheus_webhook_dingtalk.dir.conf }}/config.yml'
- name: '<{{ cmd | upper }}> | 初始化 PrometheusWebhookDingtalk 告警模板文件'
copy:
src: '{{ item }}'
dest: '{{ prometheus_webhook_dingtalk.dir.template }}'
with_fileglob: 'files/template/*'
- name: '<{{ cmd | upper }}> | 启动 PrometheusWebhookDingtalk 容器'
shell: |
. /etc/profile
cd {{ prometheus_webhook_dingtalk.dir.main }}
docker-compose down
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 PrometheusWebhookDingtalk 服务启动'
wait_for:
port: '{{ prometheus_webhook_dingtalk.port }}'
- name: '<{{ cmd | upper }}> | 创建 PrometheusWebhookDingtalk 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- prometheus_webhook_dingtalk.enable
# 卸载 PrometheusWebhookDingtalk
- block:
- name: '<{{ cmd | upper }}> | 卸载 PrometheusWebhookDingtalk'
shell: |
. /etc/profile
cd {{ prometheus_webhook_dingtalk.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 PrometheusWebhookDingtalk 相关文件'
shell: |
rm -rf {{ prometheus_webhook_dingtalk.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- prometheus_webhook_dingtalk.enable

View File

@ -0,0 +1,35 @@
## Request timeout
# timeout: 5s
## Uncomment following line in order to write template from scratch (be careful!)
#no_builtin_template: true
## Customizable templates path
#templates:
# - contrib/templates/legacy/template.tmpl
templates:
- /etc/prometheus-webhook-dingtalk/templates/legacy/template.tmpl
## Targets, previously was known as "profiles"
targets:
webhook1:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
# secret for signature
secret: SEC000000000000000000000
webhook2:
url: https://oapi.dingtalk.com/robot/send?access_token={{ alert.dingtalk.access_token }}
webhook_legacy:
url: https://oapi.dingtalk.com/robot/send?access_token={{ alert.dingtalk.access_token }}
# Customize template content
message:
# Use legacy template
title: '{{ alert.message.title }}'
text: '{{ alert.message.text }}'
webhook_mention_all:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
mention:
all: true
webhook_mention_users:
url: https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxx
mention:
mobiles: ['156xxxx8827', '189xxxx8325']

View File

@ -0,0 +1,23 @@
version: "3.9"
services:
prometheus-webhook-dingtalk:
image: {{ prometheus_webhook_dingtalk.image }}
container_name: {{ docker.network.name }}-prometheus-webhook-dingtalk
hostname: prometheus-webhook-dingtalk
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- {{ prometheus_webhook_dingtalk.dir.conf }}/config.yml:/etc/prometheus-webhook-dingtalk/config.yml
- {{ prometheus_webhook_dingtalk.dir.template }}/template.tmpl:/etc/prometheus-webhook-dingtalk/templates/legacy/template.tmpl
networks:
- {{ docker.network.name }}
ports:
- {{ prometheus_webhook_dingtalk.port }}:8060
environment:
- config.file=/etc/prometheus-webhook-dingtalk/config.yml
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,62 @@
---
# 校验 Promtail 是否安装
- name: '<{{ cmd | upper }}> | 校验 Promtail 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Promtail
- block:
- name: '<{{ cmd | upper }}> | 创建 Promtail 相关目录'
file:
path: '{{ item.value }}'
state: directory
loop: '{{ promtail.dir | dict2items }}'
- name: '<{{ cmd | upper }}> | 安装 Promtail'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ promtail.dir.main }}/docker-compose.yml'
- src: conf/promtail-config.yaml.j2
dest: '{{ promtail.dir.conf }}/promtail-config.yaml'
- name: '<{{ cmd | upper }}> | 启动 Promtail 容器'
shell: |
. /etc/profile
cd {{ promtail.dir.main }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 Promtail 服务启动'
# wait_for:
# port: '{{ promtail.port }}'
- name: '<{{ cmd | upper }}> | 创建 Promtail 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Promtail
- block:
- name: '<{{ cmd | upper }}> | 卸载 Promtail'
shell: |
. /etc/profile
cd {{ promtail.dir.main }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Promtail 相关文件'
shell: |
rm -rf {{ promtail.dir.main }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,24 @@
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://{{ groups.server.0 }}:{{ loki.port }}/loki/api/v1/push
scrape_configs:
{% for node in promtail.nodes -%}
{% if node.host == inventory_hostname -%}
{% for target in node.targets -%}
- job_name: {{ target.name }}
static_configs:
- targets:
- localhost
labels:
job: {{ target.name }}
__path__: {{ target.path }}/*log
{% endfor %}
{% endif %}
{% endfor %}

View File

@ -0,0 +1,27 @@
version: "3.9"
services:
promtail:
image: {{ promtail.image }}
container_name: {{ docker.network.name }}-promtail
hostname: promtail
restart: always
networks:
- {{ docker.network.name }}
{% for node in promtail.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:9080
volumes:
- {{ promtail.dir.conf }}/promtail-config.yaml:/etc/promtail/promtail-config.yaml
{% for target in node.targets -%}
- {{ target.path }}:{{ target.path }}
{% endfor %}
{% endif %}
{% endfor %}
command: "-config.file=/etc/promtail/promtail-config.yaml"
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,59 @@
---
# 校验 Rabbitmq Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Rabbitmq Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Rabbitmq Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Rabbitmq Exporter 相关目录'
file:
path: '{{ rabbitmq_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 Rabbitmq Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ rabbitmq_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Rabbitmq Exporter 容器'
shell: |
. /etc/profile
cd {{ rabbitmq_exporter.dir }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 Rabbitmq Exporter 服务启动'
# wait_for:
# port: '{{ rabbitmq_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Rabbitmq Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Rabbitmq Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Rabbitmq Exporter'
shell: |
. /etc/profile
cd {{ rabbitmq_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Rabbitmq Exporter 相关文件'
shell: |
rm -rf {{ rabbitmq_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,25 @@
version: "3.9"
services:
rabbitmq-exporter:
image: {{ rabbitmq_exporter.image }}
container_name: {{ docker.network.name }}-rabbitmq-exporter
hostname: rabbitmq-exporter
restart: always
networks:
- {{ docker.network.name }}
{% for node in rabbitmq_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:9419
environment:
- RABBIT_URL=http://{{ node.url }}
- RABBIT_USER={{ node.user }}
- RABBIT_PASSWORD={{ node.password }}
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,59 @@
---
# 校验 Redis Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Redis Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Redis Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Redis Exporter 相关目录'
file:
path: '{{ redis_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 Redis Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ redis_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Redis Exporter 容器'
shell: |
. /etc/profile
cd {{ redis_exporter.dir }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 Redis Exporter 服务启动'
# wait_for:
# port: '{{ redis_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Redis Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Redis Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Redis Exporter'
shell: |
. /etc/profile
cd {{ redis_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Redis Exporter 相关文件'
shell: |
rm -rf {{ redis_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists

View File

@ -0,0 +1,24 @@
version: "3.9"
services:
redis-exporter:
image: {{ redis_exporter.image }}
container_name: {{ docker.network.name }}-redis-exporter
hostname: redis-exporter
restart: always
networks:
- {{ docker.network.name }}
{% for node in redis_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:9121
command:
- '-redis.addr={{ node.url }}'
- '-redis.password={{ node.password }}'
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,66 @@
---
# 校验 Rocketmq Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Rocketmq Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Rocketmq Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Rocketmq Exporter 相关目录'
file:
path: '{{ rocketmq_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 准备 Rocketmq Exporter Jar 包'
copy:
src: files/{{ rocketmq_exporter.jar }}
dest: '{{ rocketmq_exporter.dir }}/{{ rocketmq_exporter.jar }}'
- name: '<{{ cmd | upper }}> | 安装 Rocketmq Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ rocketmq_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Rocketmq Exporter 容器'
shell: |
. /etc/profile
cd {{ rocketmq_exporter.dir }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 Rocketmq Exporter 服务启动'
# wait_for:
# port: '{{ rocketmq_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Rocketmq Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- ansible_architecture == "x86_64"
# 卸载 Rocketmq Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Rocketmq Exporter'
shell: |
. /etc/profile
cd {{ rocketmq_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Rocketmq Exporter 相关文件'
shell: |
rm -rf {{ rocketmq_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- ansible_architecture == "x86_64"

View File

@ -0,0 +1,24 @@
version: "3.9"
services:
rocketmq-exporter:
image: {{ rocketmq_exporter.image }}
container_name: {{ docker.network.name }}-rocketmq-exporter
hostname: rocketmq-exporter
restart: always
networks:
- {{ docker.network.name }}
{% for node in rocketmq_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:5557
volumes:
- {{ rocketmq_exporter.dir }}/{{ rocketmq_exporter.jar }}:/rocketmq-exporter/rocketmq-exporter-0.0.2-SNAPSHOT.jar
command: "java -jar /rocketmq-exporter/rocketmq-exporter-0.0.2-SNAPSHOT.jar --rocketmq.config.namesrvAddr=http://{{ node.url }} --rocketmq.config.rocketmqVersion={{ node.version }}"
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}

198
prometheus/roles/role.yml Normal file
View File

@ -0,0 +1,198 @@
# 安装 Docker Engine
- hosts: dockerce
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- server
- exporter
- node
- docker
- mysql
- mongodb
- redis
- rabbitmq
- rocketmq
- elasticsearch
- zookeeper
- jmx
- nginx
- blackbox
- promtail
- dockerce
roles:
- role: docker
when: cmd == "install"
# 部署 Prometheus 服务端相关组件
- hosts: server
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- server
roles:
- role: prometheus
- role: grafana
- role: alertmanager
- role: prometheus_alert
- role: prometheus_webhook_dingtalk
- role: loki
# 部署 Prometheus Node Exporter 组件
- hosts: node
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- node
roles:
- role: node_exporter
# 部署 cAdvisor 组件
- hosts: docker
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- docker
roles:
- role: cadvisor
# 部署 Prometheus Blackbox Exporter 组件
- hosts: blackbox
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- blackbox
roles:
- role: blackbox_exporter
# 部署 Prometheus Mysqld Exporter 组件
- hosts: mysql
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- mysql
roles:
- role: mysqld_exporter
# 部署 Prometheus MongoDB Exporter 组件
- hosts: mongodb
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- mongodb
roles:
- role: mongodb_exporter
# 部署 Prometheus Redis Exporter 组件
- hosts: redis
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- redis
roles:
- role: redis_exporter
# 部署 Prometheus RabbitMQ Exporter 组件
- hosts: rabbitmq
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- rabbitmq
roles:
- role: rabbitmq_exporter
# 部署 Prometheus RocketMQ Exporter 组件
- hosts: rocketmq
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- rocketmq
roles:
- role: rocketmq_exporter
# 部署 Prometheus ElasticSearch Exporter 组件
- hosts: elasticsearch
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- elasticsearch
roles:
- role: elasticsearch_exporter
# 部署 Prometheus Zookeeper Exporter 组件
- hosts: zookeeper
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- zookeeper
roles:
- role: zookeeper_exporter
# 部署 Prometheus JMX Exporter 组件
- hosts: jmx
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- jmx
roles:
- role: jmx_exporter
# 部署 Prometheus Nginx Exporter 组件
- hosts: nginx
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- nginx
roles:
- role: nginx_prometheus_exporter
# 部署 Promtail 组件
- hosts: promtail
remote_user: root
become: yes
gather_facts: yes
tags:
- all
- exporter
- promtail
roles:
- role: promtail

View File

@ -0,0 +1,2 @@
---
flag: ~/.flag/{{ role_name }}

View File

@ -0,0 +1,61 @@
---
# 校验 Zookeeper Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Zookeeper Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Zookeeper Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Zookeeper Exporter 相关目录'
file:
path: '{{ zookeeper_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 Zookeeper Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ zookeeper_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Zookeeper Exporter 容器'
shell: |
. /etc/profile
cd {{ zookeeper_exporter.dir }}
docker-compose down
docker-compose up -d
# - name: '<{{ cmd | upper }}> | 等待 Zookeeper Exporter 服务启动'
# wait_for:
# port: '{{ zookeeper_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Zookeeper Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
- ansible_architecture == "x86_64"
# 卸载 Zookeeper Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Zookeeper Exporter'
shell: |
. /etc/profile
cd {{ zookeeper_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Zookeeper Exporter 相关文件'
shell: |
rm -rf {{ zookeeper_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists
- ansible_architecture == "x86_64"

View File

@ -0,0 +1,22 @@
version: "3.9"
services:
zookeeper-exporter:
image: {{ zookeeper_exporter.image }}
container_name: {{ docker.network.name }}-zookeeper-exporter
hostname: zookeeper-exporter
restart: always
networks:
- {{ docker.network.name }}
{% for node in zookeeper_exporter.nodes -%}
{% if node.host == inventory_hostname -%}
ports:
- {{ node.port }}:9141
command: "--zk-hosts='{{ node.url }}' --timeout=5"
{% endif %}
{% endfor %}
networks:
{{ docker.network.name }}:
external: true
name: {{ docker.network.name }}