基于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 \\
--storage.tsdb.retention=90d
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
prometheus配置文件
cat prometheus.yml
# my global config
global:
scrape_interval: 10s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 10s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'Prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'TEST'
static_configs:
- targets: ['192.168.200.150:9104']
labels:
release: 5.7
- job_name: 'BASE'
consul_sd_configs:
- server: '192.168.200.111:8500'
services: ['BASE']
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: '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