基于saltstack配置管理方式:prometheus的自启动配置
cat init.sls
/usr/local/prometheus/prometheus.yml:
file.managed:
- source: salt://200_111/prometheus/prometheus.yml
prometheus_server_service_script:
file:
- managed
- name: /etc/systemd/system/prometheus.service
# - user: root
# - group: root
- contents: |
[Unit]
Description=prometheus
After=syslog.target network.target
[Service]
Type=simple
RemainAfterExit=no
WorkingDirectory=/usr/local/prometheus
#User=prometheus
#Group=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --log.level=info
SyslogIdentifier=prometheus
[Install]
WantedBy=multi-user.target
prometheus_server_service:
service:
- running
- name: prometheus
- enable: True
- watch:
- file: prometheus_server_service_script
- file: /usr/local/prometheus/prometheus.yml
consul自动发现prometheus配置文件
cat prometheus.yml
# my global config
global:
scrape_interval: 10s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
eval(10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically eval(.*),(.*),(.*),(.*),$'
target_label: 'exporter'
replacement: $1
- source_labels: ["__meta_consul_service"]
target_label: "env"
- source_labels: ["__meta_consul_service_id"]
target_label: "name"
- source_labels: ["__meta_consul_service_address"]
target_label: "ip"
- job_name: 'DEV'
consul_sd_configs:
- server: '192.168.200.111:8500'
services: ['DEV']
relabel_configs:
- source_labels: ["__meta_consul_tags"]
regex: '^,(.*),(.*),(.*),(.*),$'
target_label: 'exporter'
replacement: $1
- source_labels: ["__meta_consul_service"]
target_label: "env"
- source_labels: ["__meta_consul_service_id"]
target_label: "name"
- source_labels: ["__meta_consul_service_address"]
target_label: "ip"
- job_name: 'SIT'
consul_sd_configs:
- server: '192.168.200.111:8500'
services: ['SIT']
relabel_configs:
- source_labels: ["__meta_consul_tags"]
regex: '^,(.*),(.*),(.*),(.*),$'
target_label: 'exporter'
replacement: $1
- source_labels: ["__meta_consul_service"]
target_label: "env"
- source_labels: ["__meta_consul_service_id"]
target_label: "name"
- source_labels: ["__meta_consul_service_address"]
target_label: "ip"
- job_name: 'PDEV'
consul_sd_configs:
- server: '192.168.200.111:8500'
services: ['PDEV']
relabel_configs:
- source_labels: ["__meta_consul_tags"]
regex: '^,(.*),(.*),(.*),(.*),$'
target_label: 'exporter'
replacement: $1
- source_labels: ["__meta_consul_service"]
target_label: "env"
- source_labels: ["__meta_consul_service_id"]
target_label: "name"
- source_labels: ["__meta_consul_service_address"]
target_label: "ip"
node exporter 自启动配置
cat /etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
Type=simple
#User=prometheus
#Group=prometheus
#Nice=-5
ExecStart=/usr/local/bin/node_exporter \
--no-collector.arp \
--no-collector.nfs \
--no-collector.wifi \
--no-collector.ipvs \
--no-collector.mdadm \
--no-collector.zfs \
--no-collector.infiniband \
--web.listen-address=0.0.0.0:9100
SyslogIdentifier=node_exporter
Restart=always
[Install]
WantedBy=multi-user.target