官网地址:https://prometheus.io/download/
安装prometheus:
wget https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.linux-386.tar.gz #找一个最新版的和自己系统吻合的版本
tar -xvf prometheus-2.26.0.linux-386.tar.gz -C /usr/local/
cd /usr/local/
mv prometheus-2.26.0.linux-386 prometheus
启停脚本
[Unit]
Description=Prometheus
[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=data/prometheus --web.enable-lifecycle --storage.tsdb.retention.time=2y
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl start prometheus
systemctl enable prometheus
global:
scrape_interval: 30s # 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.
scrape_timeout: 15s
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']
利用prometheus监控其他主机需要在被监控的主机上面安装exporter,先安装一个node_exporter进行监控
wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
tar -xvf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.1.2.linux-amd64 node_exporter
启停脚本
[Unit]
Description=node_export
[Service]
ExecStart=/usr/local/node_exporter/node_exporter --web.listen-address=:9100 --collector.systemd --collector.systemd.unit-whitelist="(ssh|docker|rsyslog|redis-server).service" --collector.textfile.directory=/usr/local/node_exporter/node_exporter/textfile.collected
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl start node_exporter
systemctl enable node_exporter
- job_name: 'CICD'
static_configs:
- targets: ['192.168.1.160:8100']
labels:
app: gitlab
nodename: gitlab
role: git
- targets: ['192.168.1.161:9100']
labels:
app: jenkins
nodename: jenkins
role: git
- targets: ['192.168.1.169:9100']
labels:
app: nexus
nodename: nexus
role: git
- targets: ['192.168.1.166:9100']
labels:
app: sonarqube
nodename: sonarqube
role: git
- targets: ['192.168.1.183:9100']
labels:
app: verdaccio
nodename: verdaccio
role: git
- job_name: 'service'
static_configs:
- targets: ['192.168.1.62:9100']
labels:
app: kvm1
nodename: kvm1
role: service
- targets: ['192.168.1.61:9100']
labels:
app: kvm2
nodename: kvm2
role: service
systemctl restart prometheus
安装grafana:
下载地址:https://grafana.com/grafana/download
直接下载rpm包进行yum安装
ip:3000访问grafana就可以了,配置prometheus的数据源请自行百度,这里就不做详细介绍了,很简单!!!
https://grafana.com/grafana/dashboards这里推荐一个grafana模板下载地址
建议使用8919这个模板