Prometheus监控各系统

使用及安装 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: "192.168.63.21"    # 自定义名字
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ["192.168.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: ["192.168.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: ["192.168.63.21:9187"] # 被监视机器的IP和端口
$ 重启prometheus

3.导入Grafana-dashborad
登入Grafana--->create--->import--->Grafana.com Dashboard--->https://grafana.com/grafana/dashboards/9628--->load

监视 JAVA 服务

1.确保jar服务已经埋点
验证:
浏览器: 192.168.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: ["192.168.63.21:15010"] # 被监视机器的IP和端口
$ 重启prometheus

3.导入Grafana-dashborad
登入Grafana--->create--->import--->Grafana.com Dashboard--->https://grafana.com/grafana/dashboards/4701--->load
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值