docker 搭建prometheusgranfana

宝剑锋从磨砺出,梅花香自苦寒来。这篇文章主要讲述docker 搭建prometheusgranfana相关的知识,希望能为你提供帮助。
一、docker prometheus安装
docker版本

[root@k03 ~]# docker -v Docker version 20.10.8, build 3967b7d

下载镜像
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

访问url:9100/metrics,有数据显示
docker 搭建prometheusgranfana

文章图片

启动prome
mkdir /data/prometheus cd /data/prometheus/ # [root@k03 prometheus]# cat prometheus.yml global: scrape_interval:60s evaluation_interval: 60sscrape_configs: - job_name: prometheus static_configs: - targets: [\'localhost:9090\'] labels: instance: prometheus- job_name: linux#jobname唯一 static_configs:#静态发现列表 - targets: [\'192.168.1.63:9100\']#本机ip地址,可配置多个ip:port并且以,分隔 labels:#打标签,便于归类发现 instance: localhost

执行docker run启动
docker run-d -p 9090:9090 -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

访问url
http://192.168.1.63:9090/graph http://192.168.1.63:9090/targets

docker 搭建prometheusgranfana

文章图片

docker 搭建prometheusgranfana

文章图片

二、docker grafana 安装
创建granfana存储目录
mkdir -p /data/grafana-data chmod 777 /data/grafana-data 如果目录不加权限,报错:mkdir: can\'t create directory \'/var/lib/grafana/plugins\': Permission denied

docker启动grafana
docker run -d \\ -p 3000:3000 \\ --name=grafana \\ -v /data/grafana-data:/var/lib/grafana \\ grafana/grafana

访问grafana
http://192.168.1.63:3000 admin/admin 登陆,首次登陆提示修改密码

添加数据源
docker 搭建prometheusgranfana

文章图片

docker 搭建prometheusgranfana

文章图片

添加成功
docker 搭建prometheusgranfana

文章图片

返回首页添加数据
导入监控模板
docker 搭建prometheusgranfana

文章图片

docker 搭建prometheusgranfana

文章图片

如下:
docker 搭建prometheusgranfana

文章图片

三、添加多台主机
ansible 多台主机部署node-exporter
ansible中的hosts配置,etcd和k8s [etcd] 192.168.1.61 192.168.1.62 192.168.1.63 [k8s] 192.168.1.31 192.168.1.32 192.168.1.81 192.168.1.82# playbook脚本用于安装docker exportervim node-exporter_install.yml --- - hosts: k8s tasks: - name: "node-exporter install" shell: docker pull prom/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-exporteransible-playbook node-exporter_install.yml#配置文件加入主机 vim /data/prometheus/prometheus.yml global: scrape_interval:60s evaluation_interval: 60sscrape_configs: - job_name: prometheus static_configs: - targets: [\'localhost:9090\'] labels: instance: prometheus- job_name: linux static_configs: - targets: [\'192.168.1.63:9100\'] labels: instance: localhost - job_name: 1.31 static_configs: - targets: [\'192.168.1.31:9100\'] labels: instance: km01 - job_name: 1.32 static_configs: - targets: [\'192.168.1.32:9100\'] labels: instance: km02 - job_name: 1.81 static_configs: - targets: [\'192.168.1.81:9100\'] labels: instance: node01 - job_name: 1.82 static_configs: - targets: [\'192.168.1.82:9100\'] labels: instance: node02 #重启 docker container ls docker restart cde3c91bbf62#通过api查询监控主机是否上线 [root@km01 ~]# curl \'http://192.168.1.63:9090/api/v1/query?query=up\' | python -m json.tool | grep -A 1 "up" % Total% Received % XferdAverage SpeedTimeTimeTimeCurrent DloadUploadTotalSpentLeftSpeed 10061810061800237k0 --:--:-- --:--:-- --:--:--301k "__name__": "up", "instance": "km01", -- "__name__": "up", "instance": "km02", -- "__name__": "up", "instance": "localhost", -- "__name__": "up", "instance": "node01", -- "__name__": "up", "instance": "node02", -- "__name__": "up", "instance": "prometheus",------------------------ #target显示主机状态 http://192.168.1.63:9090/targets #http api详情 https://prometheus.io/docs/prometheus/latest/querying/api/#expression-query-result-formats -----------------------------------------

docker 搭建prometheusgranfana

文章图片

【docker 搭建prometheusgranfana】#推荐模板id
https://www.jianshu.com/p/367d52fe1171

    推荐阅读