使用及安装 Prometheus
安装 Prometheus
$ wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
$ tar -zxvf prometheus-2.30.3.linux-amd64.tar.gz -C /usr/local/
$ cd /usr/local
$ mv prometheus-2.8.1.linux-amd64/ prometheus
至此 Prometheus安装完毕
启动 Prometheus
$ cd /usr/local/prometheus
$ nohup ./prometheus > prometheus.log 2>&1 &
查验:
浏览器访问:IP:9090(注意防火墙)
安装 Grafana
$ wget https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm
$ rpm -ivh grafana-5.4.2-1.x86_64.rpm
安装插件
$ grafana-cli plugins install grafana-piechart-panel
$ systemctl start grafana-server
查验:
浏览器访问:IP:3000(注意防火墙) 用户: admin 密码:admin
Grafana 配置 Prometheus
Grafana配置界面
Configuration---> Add data source---> 选择Prometheus ---> Save & Test(如果Prometheus和Grafana不在同一机器上则需要修改HTTP/URL) --->
配置监视
监视 linux 系统
1.系统埋点
被监视机:
$ wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz
$ tar -xvf node_exporter-0.16.0.linux-amd64.tar.gz
$ cd node_exporter-0.16.0.linux-amd64
$ nohup ./node_exporter --web.listen-address=":9100"
验证:
浏览器: 被监视机IP:端口/metrics
2.Prometheus配置
Prometheus主机:
$ cd /usr/local/prometheus
$ vim prometheus.yml
在scrape_configs:下追加:
- job_name: "172.16.63.21" # 自定义名字
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["172.16.63.21:9200"] # 被监视机器的IP和端口
$ 重启prometheus
3.导入Grafana-dashborad
登入Grafana--->create--->import--->Grafana.com Dashboard--->https://grafana.com/grafana/dashboards/<根据需求去网页上选择相关的编号>--->load
监视 MySQL 系统
1.系统埋点
被监视机:
在数据库中创建一个用来监视的用户
mysql> flush privileges;
mysql> grant select,replication client,process ON \*.\* to 'mysql_monitor'@'localhost' identified by '123';
$ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
$ tar -xvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
$ cd mysqld_exporter-0.12.1.linux-amd64
$ cat >>my.cnf<<EOF
[client]
user=mysql_monitor
password=123
EOF
$ nohup ./mysqld_exporter --config.my-cnf=my.cnf --web.listen-address=":9300" &
验证:
浏览器: 被监视机IP:端口/metrics
2.Prometheus配置
Prometheus主机:
$ cd /usr/local/prometheus
$ vim prometheus.yml
在scrape_configs:下追加:
- job_name: "mysql" # 自定义名字
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["172.16.63.21:9300"] # 被监视机器的IP和端口
$ 重启prometheus
3.导入Grafana-dashborad
登入Grafana--->create--->import--->Grafana.com Dashboard--->https://grafana.com/grafana/dashboards/7362--->load
监视 Postgres 系统
1.系统埋点
被监视机:
$ wget https://github.com/prometheus-community/postgres_exporter/releases/download/v0.10.0/postgres_exporter-0.10.0.linux-amd64.tar.gz
$ export PATH=/home/postgres/pgsql/bin:$PATH # 根据实际情况修改
$ export DATA_SOURCE_NAME="user=postgres host=localhost password=postgres port=5432 dbname=postgres sslmode=disable" # 根据实际情况修改
$ nohup ./postgres_exporter --web.listen-address=":9187" >/dev/null 2>&1 &
验证:
浏览器: 被监视机IP:端口/metrics
2.Prometheus配置
Prometheus主机:
$ cd /usr/local/prometheus
$ vim prometheus.yml
在scrape_configs:下追加:
- job_name: "postgres" # 自定义名字
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["172.16.63.21:9187"] # 被监视机器的IP和端口
$ 重启prometheus
3.导入Grafana-dashborad
登入Grafana--->create--->import--->Grafana.com Dashboard--->https://grafana.com/grafana/dashboards/9628--->load
监视 JAVA 服务
1.确保jar服务已经埋点
验证:
浏览器: 172.16.63.21:15010/actuator/prometheus
2.Prometheus配置
Prometheus主机:
$ cd /usr/local/prometheus
$ vim prometheus.yml
在scrape_configs:下追加:
- job_name: "gateway" # 自定义名字
metrics_path: /actuator/prometheus
# scheme defaults to 'http'.
static_configs:
- targets: ["172.16.63.21:15010"] # 被监视机器的IP和端口
$ 重启prometheus
3.导入Grafana-dashborad
登入Grafana--->create--->import--->Grafana.com Dashboard--->https://grafana.com/grafana/dashboards/4701--->load