美文网首页
docker | 从零开始搭建prometheus+Grafan

docker | 从零开始搭建prometheus+Grafan

作者: 炒面Z | 来源:发表于2020-06-30 10:42 被阅读0次

Grafana成品效果图

image.png

定义

  • Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB)。Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本。
  • grafana 是一款采用 go 语言编写的开源应用,主要用于大规模指标数据的可视化展现,是网络架构和应用分析中最流行的时序数据展示工具,目前支持绝大部分常用的时序数据库。
  • node-exporter 是采集服务器层面的运行指标,包括机器的loadavg、filesystem、meminfo等基础监控,类似于传统主机监控维度的zabbix-agent。

1.docker拉取镜像

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

2.docker模式运行他们

  • node-exporter
docker run -d \
--name node-exporter \
  --net="host" \
   --pid="host" \
   -v "/:/host:ro,rslave" \
   prom/node-exporter \
   --path.rootfs /host
  • prometheus
    配置文件目录在映射在宿主机目录 /opt/prometheus,新建 prometheus.yml
docker run -d \
--name prometheus \
-p 9090:9090 \
-v /opt/prometheus/:/etc/prometheus/ \
prom/prometheus
  • grafana
docker run -d -p 3000:3000 --name=grafana -v /etc/localtime:/etc/localtime grafana/grafana

如果端口冲突,使用 netstate 命令查看端口被哪个进程占用,改端口或者使用kill -9 PID 杀掉占用进程

3. 配置 prometheus.yml

文件位置: /opt/prometheus/prometheus.yml

global:
  scrape_interval:     10s
  evaluation_interval: 10s

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

  - job_name: linux
    static_configs:
      - targets: ['localhost:9100','其他电脑IP:9100']

4.grafana 配置仪表盘

grafana dashboards 仪表盘模板市场: https://grafana.com/grafana/dashboards

  • 访问 grafana http://IP:3000/, 默认账号密码是admin/admin, 然后重置密码后进入主页面
  • 使用grafana 的仪表盘模板导入ID=8919的仪表盘 ,点击 import导入即成功 (docker监控模板推荐 8321)


    image.png
    image.png

参考: https://yasongxu.gitbook.io/container-monitor/

相关文章

网友评论

      本文标题:docker | 从零开始搭建prometheus+Grafan

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