Prometheus + InfluxDB + MySQL + Grafna
参考链接:
https://blog.rj-bai.com/post/158.html
全局端口说明:
Prometheus默认端口:9090 Grafana默认端口:3000 node_exporter默认端口:9104 mysqld_exporter默认端口:9100 alertmanager默认端口:9093 InfluxDB默认端口:8086
本文包含以下部分:
1.安装prometheus 2.安装node_exporter、mysqld_exporter 3.配置prometheus获取node_exporter与mysqld_exporter数据 4.安装Grafana 5.导入Grafana官网模板,对数据基本呈现 6.将prometheus数据存放到外部存储influxDB,而非自带tsdb 7.简单配置alertmanager
1.安装配置prometheus
1.1 下载prometheus
https://prometheus.io/download/
tar -zxf prometheus-2.19.2.linux-amd64.tar.gz -C /usr/local ln -s /usr/local/prometheus-2.19.2.linux-amd64 /usr/local/prometheus
1.2 启动prometheus,配置开机自启动
# cat > /usr/lib/systemd/system/prometheus.service <<EOF [Unit] Description=prometheus server daemon [Service] Restart=on-failure ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml [Install] WantedBy=multi-user.target EOF # systemctl daemon-reload && systemctl start prometheus.service
1.3 配置基于文件发现
# vi prometheus.yml global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: rule_files: scrape_configs: - job_name: 'prometheus' # 这个目录下的所有主机监控,将会归集到job为prometheus的标签下,要单独设置,需要修改此配置文件单独设置。 file_sd_configs: - files: ['/usr/local/prometheus/files_sd_configs/*.yml'] refresh_interval: 5s - job_name: 'nodes' file_sd_configs: - files: ['/usr/local/prometheus/nodes_sd_configs/*.yml'] refresh_interval: 5s
# 配置本机
# cd files_sd_configs/ # vi localhost.yml - targets: ['localhost:9090'] labels: name: czh02
# 利用kill -hup 发送signal hup热更新程序,使程序热加载配置文件
# ps aux | grep prometheus.yml | grep -v grep | awk {'print $2'} | xargs kill -hup
2. 安装grafana
2.1 下载安装
# grafana主配置文件在/usr/local/grafana-7.1.0/conf目录下,default.ini可以配置grafana数据目录
# http或https以及使用sqllite还是mysql/postgresql