Prometheus+Grafana监控

安装exporter

# 下载node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz


# 解压安装
tar zxf node_exporter-0.18.1.linux-amd64.tar.gz 

mv node_exporter-0.18.1.linux-amd64 /usr/local/node_exporte


# 启动
/usr/local/node_exporte/node_exporter &
--web.listen-address=":9100"  //指定node_export监听端口
--web.telemetry-path="/metrics"  //获取metrics的url
--log.level="info"   //设置日志级别
--log.format="logger:stderr"  //日志格式

安装prometheus

# 下载prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz

# 解压安装
tar -zxf prometheus-2.10.0.linux-amd64.tar.gz

mv prometheus-2.10.0.linux-amd64 /usr/local/prometheus

配置prometheus

vim /usr/local/prometheus/prometheus.yml
# my global config
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:
           - 192.168.2.5:9093


# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
   - "/usr/local/prometheus/rules/*.yml"
  # - "first_rules.yml"
  # - "second_rules.yml"


# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"
    static_configs:
      - targets: ["192.168.2.5:9090"]
  - job_name: "node"
    static_configs:
      - targets: ["192.168.2.5:9091","192.168.2.6:9091","192.168.2.7:9091"]


# 启动prometheus
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
--web.listen-address=:9090
--web.enable-lifecycle   //加此参数可实现热重启      

curl -XPOST http://127.0.0.1:9090/-/reload  //此命令进行热重启   

安装Grafana

wget https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.3.3.linux-amd64.tar.gz


yum -y install initscripts urw-fonts

rpm -Uvh grafana-5.4.2-1.x86_64.rpm 

启动Grafana

systemctl start grafana-server
# 修改如下
- job_name: 'node'
  static_configs:
  - targets: ['localhost:9100']

访问grafana页面配置http:IP:3000
默认用户密码都是admin