美文网首页
grafana+prometheus

grafana+prometheus

作者: Jack0111 | 来源:发表于2021-05-10 19:25 被阅读0次

Docker安装之后最重要的一步就是要切换Docker镜像源!!!切记一定要切换,不然后面Pull镜像时会卡到爆(我一度怀疑我网络出问题了,切换镜像源之后快到飞起!)

这里切换镜像源可以切换阿里镜像源,切换方法:

在/etc/docker中创建daemon.json(如果没有则直接创建!)

sudo vim /etc/docker/daemon.json

文件中直接输入:

{

"registry-mirrors":["https://y0qd3iq.mirror.aliyuncs.com"]

}

保存退出,重启Docker即可!

Pull镜像

安装Prometheus和Grafana首先要安装node-exporter,该镜像相当于一个收集器!

因此搭建Prometheus、Grafana需要安装的镜像为:

node-exporter

prometheus

grafana

因此分别执行:

docker pull prom/node-exporter

docker pull prom/prometheus

docker pull prom/grafana

安装node-exporter

拉取成功之后首先启动node-exporter

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

然后通过sudo docker ps,查看是否启动成功!

启动成功访问:http://localhost:9100/metrics

若看到输出以上信息则node-exporter安装成功!

安装Prometheus

首先创建Prometheus的配置文件

sudo mkdir /opt/prometheus

cd /opt/prometheus/

sudo vim prometheus.yml

创建之后文件中写入Prometheus的相关配置,

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: ['本机ip:9100']

        labels: 

        instance: localhost

启动Prometheus

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

启动成功之后通过sudo docker ps查看状态

然后浏览器访问:http://localhost:9090/graph和http://localhost:9090/targets

访问http://localhost:9090/targets时会看到Prometheus监控状态。

两个状态都是UP表明Prometheus监控状态正常!

安装Grafana

Prometheus安装就绪之后,需要安装Grafana展示监控数据UI,通过Grafana来实现。

首先创建文件夹:sudo mkdir /opt/grafana-storage

然后修改该文件夹的权限:sudo chmod 777 -R /opt/grafana-storage

启动Grafana:sudo docker run -d -p 3000:3000 --name=grafana -v /opt/grafana-storage/:/var/lib/grafana grafana/grafana

启动成功之后访问:http://localhost:3000

Grafana的默认帐号密码都是admin,登录之后需要设置新密码!

进入Grafana之后界面如下:

然后选择Add your first data source。

选择Promethues进行配置

这里输入本机ip:9090。然后save & Test

全部显示为绿色证明创建成功!

最后创建dashboard,在Query中选择刚才创建的data source,然后在Metrics中输入cpu(或者选择Metrics进行选择想要进行输出的指标),选择指标之后shift+enter进行启动。在表格中会输出为UI图!

相关文章

网友评论

      本文标题:grafana+prometheus

      本文链接:https://www.haomeiwen.com/subject/hvoidltx.html