基于Docker搭建Prometheus+Grafana

部署系统:Centos 7.2以上

安装docker

yum  -y install docker
systemctl   start docker

下载prometheus和grafana镜像包

Docker pull  prom/node-exporter

Docker pull  prom/Prometheus

Docker pull  grafana/grafana

启动node-exporter

docker run -d -p 9100:9100 \

  -v "/proc:/host/proc:ro" \

  -v "/sys:/host/sys:ro" \

  -v "/:/rootfs:ro" \

  --net="host" \

  prom/node-exporter

查看9100端口是否启动
基于Docker搭建Prometheus+Grafana_第1张图片

netstat -anpt 

可以通过端口进行访问(如有防火墙请开启9100端口)

http://IP:9100/metrics

启动prometheus
新建目录prometheus,编辑配置文件prometheus.yml

mkdir /opt/Prometheus

cd /opt/Prometheus
vim Prometheus.yml

global:

  scrape_interval:     60s

  evaluation_interval: 60s

scrape_configs:

  - job_name: prometheus

    static_configs:

      - targets: ['localhost:9090']    #将localhost改为本机IP

        labels:

          instance: prometheus

  - job_name: linux

    static_configs:

      - targets: ['81.68.76.*:9100']  #将localhost改为本机IP,端口不变

        labels:

          instance: localhost

启动prometheus

docker run -d -p 9090:9090 -v /opt/Prometheus/Prometheus.yml:/etc/Prometheus/Prometheus.yml prom/prometheus

查看9090端口是否启动(如有防火墙请开启9090端口)
基于Docker搭建Prometheus+Grafana_第2张图片

访问url

http://IP:9090/graph

启动grafana

mkdir  /opt/Grafana-storage
chmod 777 -R  /opt/Grafana-storage
docker run -d -p 3000:3000 --name=Grafana -v /opt/Grafana-storage:/var/lib/Grafana grafana/grafana

查看3000端口是否启动(如有防火墙请开启3000端口)
基于Docker搭建Prometheus+Grafana_第3张图片
访问url

http://IP:3000

默认用户名admin 默认密码admin

添加数据源基于Docker搭建Prometheus+Grafana_第4张图片

开启模板

基于Docker搭建Prometheus+Grafana_第5张图片

选择模板

基于Docker搭建Prometheus+Grafana_第6张图片

查看数据

基于Docker搭建Prometheus+Grafana_第7张图片

你可能感兴趣的:(基于Docker搭建Prometheus+Grafana)