欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Prometheus安装

程序员文章站 2022-03-15 18:13:50
...

安装go环境变量

#下载go 
https://golang.org/dl/

#解压
tar -C /usr/local  -zxf go1.15.5.linux-amd64.tar.gz

#配置环境变量
vim  /etc/profile
export PATH=$PATH:/usr/local/go/bin

#环境变量生效
source  /etc/profile

#查看go版本
go  version




安装prometheus服务端

#下载 
https://prometheus.io/download/

#解压
tar -zxf prometheus-2.22.2.linux-amd64.tar.gz

启动
cd prometheus
./prometheus 

打开自带监控页面
http://xx.xx.xx.xx:9090/targets




安装prometheus客户端exporter

下载页面提供了很多的exporter
https://prometheus.io/download/

第三方exporter
https://prometheus.io/docs/instrumenting/exporters/

安装node_exporter(服务器指标)

#解压
tar -zxf  node_exporter-1.0.1.linux-amd64.tar.gz

nohup  ./node_exporter --web.listen-address=:30010 &
# --web.listen-address 指定端口,node_exporter默认端口9100

修改prometheus 配置文件prometheus.yml

global:
  scrape_interval:     15s # 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 is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'server'
    static_configs:
    - targets: ['192.168.1.101:30010','192.168.1.102:30010']
      labels:
        env: prod
        
  - job_name: 'oracle'
    static_configs:
      - targets: ['192.168.88.11:9161']
    scrape_interval: 14400s  #独立抓取间隔
    scrape_timeout: 600s     #独立超时时间
    

这一部分就是新加的

  - job_name: 'server'
    static_configs:
    - targets: ['192.168.1.101:30010','192.168.1.102:30010']
      labels:
        env: prod

重启prometheus 后,进入监控页 http://xx.xx.xx.xx:9090/targets 查看




安装grafana(prometheus 的图形展示)

#下载并安装
https://grafana.com/grafana/download

#启动,并设置开机启动
systemctl daemon-reload
systemctl start grafana-server
systemctl enable grafana-server

#默认端口3000,默认用户和密码是admin
http://xx.xx.xx.xx:3000

进入后,点击add datasource,选中Prometheus 2.0 Stats后,就可以看到监控面板

官网上有很多大神提供的漂亮的监控页面
https://grafana.com/grafana/dashboards

每个都有自己的dashboard ID
Prometheus安装

Prometheus安装

相关标签: 运维