node-exporter+prometheus+grafana

Posted yintian908

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node-exporter+prometheus+grafana相关的知识,希望对你有一定的参考价值。

1 系统安装docker


yum install -y docker
systemctl enable docker
systemctl start docker

2 下载镜像包:


docker pull prom/prometheus
docker pull prom/node-exporter
docker pull grafana/grafana

 

3启动node-exporter


3.1 启动镜像


docker run -d -p 9100:9100 -v /proc:/host/proc:ro -v /sys:/host/sys:ro -v /:/rootfs:ro --net=host prom/node-exporter

注:

  1. 试过以其他端口启动,不成功。
  2. 由于node-exporter是需要采集服务器的信息,所以,docker的net模式为 --net=host,意思是 docker使用的网络实际上和宿主机一样。


3.2 登陆

 

 

http://ipserver:9100/metrics

4 启动prometheus


4.1 新建目录prometheus,编辑配置文件prometheus.yml,内容如下


global:
scrape_interval: 60s
evaluation_interval: 60s

scrape_configs:
- job_name: prometheus
static_configs:
- targets: [‘localhost:9090‘]
labels:
instance: prometheus

- job_name: linux
static_configs:
- targets: [‘ipserver:9100‘] --这个是需要监控的linux服务器的地址
labels:
instance: localhost


4.2 启动prometheus


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

 

4.3 登陆url

 

 

http://ipserver:19090/graph http://ipserver:19090/status


5 安装grafana


5.1 新建空文件夹/opt/grafana-storage


      mkdir /opt/grafana-storage
      chmod 777 -R /opt/grafana-storage

5.2 启动grafana


docker run -d -p 13000:3000 --name=grafana -v /opt/grafana-storage:/var/lib/grafana grafana/grafana


5.3 登陆url
    http://ipserver:13000/login

   ######错误######
  启动grafana容器出错的话,
  GF_PATHS_DATA=‘/var/lib/grafana‘ is not writable.
  You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later
  mkdir: cannot create directory ‘/var/lib/grafana/plugins‘: Permission denied

  ---------解决办法:chmod 777 -R /opt/grafana-storage

以上是关于node-exporter+prometheus+grafana的主要内容,如果未能解决你的问题,请参考以下文章

[prometheus]部署node-exporter

prometheus node-exporter安装

prometheus node-exporter增加新的自定义监控项

Prometheus+node-exporter

是否可以运行 Prometheus 和 Grafana docker 容器但使用安装在主机中的 node-exporter?

最新版Prometheus+Grafana+node-exporter炫酷界面