CentOS 7安装 prometheus+grafana

安装prometheus-1.8.2.linux-amd64

访问地址http://x.x.x.122:9090/targets
启动

nohup ./prometheus -config.file=prometheus.yml &
nohup ./prometheus -storage.local.retention 8760h0m0s  &  保存1年的数据
-storage.local.retention 360h0m0s   历史数据存储多久,默认15天。

安装node_exporter

版本匹配主要是node_exporter(不要用最新版)
https://github.com/prometheus/node_exporter/releases/download/0.11.0/node_exporter-0.11.0.linux-amd64.tar.gz
注意:最新版只有node_memory_MemTotal_bytes而没有node_memory_MemTotal

nohup ./node_exporter &

安装grafana

wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.2.0-1.x86_64.rpm
sudo yum install initscripts fontconfig -y
sudo rpm -Uvh grafana-4.2.0-1.x86_64.rpm

启动服务service grafana-server start
grafana访问页面http://localhost:3000 ,默认账号、密码admin/admin
dashboards(Grafana)仪表盘模板

git clone https://github.com/percona/grafana-dashboards.git
cp -r grafana-dashboards/dashboards /var/lib/grafana/dashboards

编辑Grafana配置文件

vi /etc/grafana/grafana.ini
[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards

修改端口号

http_port = 3333
root_url = http://localhost:3333

重启service grafana-server restart

mysql监控部署

在需要监控的mysql上安装 node_exporter和 mysqld_exporter
https://prometheus.io/download/
下载node_exporter(启动后端口为9100)
node_exporter访问地址 http://x.x.x.122:9100/metrics
监听121服务器(只需在121安装node_exporter打开9100端口)

vim /home/tools/prometheus-1.8.2.linux-amd64/prometheus.yml
......
  - job_name: linux24
    static_configs:
      - targets: ['x.x.x.x:3564']
        labels:
          instance: linux24
  - job_name: linux121
    static_configs:
      - targets: ['x..x.x:9100']
        labels:
          instance: linux121        
  - job_name: mongo121
    static_configs:
      - targets: ['x.x.x.121:9001']
        labels:
          instance: mongo121
  - job_name: linux122
    static_configs:
      - targets: ['x.x.x.122:9100']
        labels:
          instance: linux122

mongodb监控部署

查看当前centos的GO版本
go version
下载安装mongodb_exporter

go get github.com/dcu/mongodb_exporter
cd $GOPATH/src/github.com/dcu/mongodb_exporter
make build

启动 登录到mongodb server
mongodb授权

db.getSiblingDB("admin").createUser({
    user: "mongodb_exporter",
    pwd: "xxx",
    roles: [
        { role: "clusterMonitor", db: "admin" },
        { role: "read", db: "local" }
    ]
})

export MONGODB_URL=mongodb://mongodb_exporter:[email protected]:27017
./mongodb_exporter

监听mongodb

查看端口占用

netstat -anp|grep 9100

mongodb所在服务器 安装 node_exporter ,mongodb_exporter

git clone https://github.com/percona/mongodb_exporter.git
https://packages.debian.org/stretch/prometheus-mongodb-exporter

启动 登录到mongodb server.

./mongodb_exporter -mongodb.uri mongodb://name:[email protected]:27017/sddata

该方式已过时

./mongodb_exporter-linux-amd64 -mongodb.uri mongodb://name:[email protected]:27017/sddata

你可能感兴趣的:(prometheus,grafana,centos7)