Skip to Content

数据可视化平台折腾记

Posted on 2 mins read

缘起

Tony Bai 的一篇博文看到了他基于 statsD、graphite 搭建的一个 Go Runtime metrics 平台,非常的赞,受益匪浅;一图胜千言,数据可视化在实际应用中有着举足轻重的意义,所以有必要折腾一套自己定制化的展现平台。

Tony 博文中是在服务器直接安装的,但是这些工具类的服务,总觉得希望走产品化的方向,一来方便随时使用,二来工具主要是使用,不研究细节实现的东西,折腾环境太浪费时间。所以我希望直接 Docker 打个包,能用即可。基于这个出发点,我在 docker hub 大致搜索了下,不少这方面的项目,结合 GitHub 的检索结果调研取舍后,选定了 github.com/kamon-io/docker-grafana-graphite 作为我折腾的基础。下面记录整个过程。

Mac Docker

Docker 刚出来的时候,我就在 Mac 上折腾过,当时的感觉,太繁琐,尤其是还需要基于 Virtualbox,安装后运行各种不方便,所以当时又果断切回到虚拟机环境,没在继续折腾,这些年 Docker 不论是在微服务架构,还是各平台支持方面都日趋的完善,所以回过头来开始基于 Docker 搞。

经过这些年的发展,Mac Docker 已相对比较完善,并且运行方便,pkg 直接安装启动。

使用 Docker 项目

Docker 发布的项目,一般会有这么几个部分:

  1. Dockfile

基于 Dockfile 来 build Docker 镜像

git clone https://github.com/kamon-io/docker-grafana-graphite.git
cd docker-grafana-graphite
docker build -t idevz-graphite .

过程中会由于依赖包安装的问题,包下载超时等导致 build 失败,如果是比较活跃的 Docker 项目,一般都可以运行得通,所以多次尝试 build 即可创建镜像。

然后基于 compose 来运行 Docker 服务,运行起来后可以执行命令,如果遇到运行过程中有异常,这时需要登录到 Docker 服务中去排查,

docker exec -it kamon-grafana-dashboard /bin/bash

比如检查 supervisor 运行日志: /var/log/supervisor

Error: Sync-request requires node version 0.12 or later.  If you need to use it with an older version of node
you can `npm install sync-request@2.2.0`, which was the last version to support older versions of node.
    at doRequest (/usr/local/lib/node_modules/wizzy/node_modules/sync-request/index.js:15:11)
    at /usr/local/lib/node_modules/wizzy/src/remote/grafana/exportSrv.js:388:20
    at arrayEach (/usr/local/lib/node_modules/wizzy/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/usr/local/lib/node_modules/wizzy/node_modules/lodash/lodash.js:9359:14)
    at Request.saveHandler [as _callback] (/usr/local/lib/node_modules/wizzy/src/remote/grafana/exportSrv.js:370:5)
    at Request.self.callback (/usr/local/lib/node_modules/wizzy/node_modules/request/request.js:188:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/usr/local/lib/node_modules/wizzy/node_modules/request/request.js:1171:10)
    at Request.EventEmitter.emit (events.js:95:17)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/wizzy/node_modules/request/request.js:1091:12)

排查完相应的错误后,使用 supervisorctl 来管理运行中的 supervisor(/usr/bin/supervisord),比如

root@12eb31acff9a:/var/log/supervisor# supervisorctl
carbon-cache                     RUNNING    pid 14, uptime 5:10:04
export-datasources-and-dashboards RUNNING    pid 16230, uptime 0:00:05
grafana-webapp                   RUNNING    pid 9, uptime 5:10:04
graphite-webapp                  RUNNING    pid 12, uptime 5:10:04
nginx                            RUNNING    pid 13, uptime 5:10:04
statsd                           RUNNING    pid 10, uptime 5:10:04
supervisor> carbon-cache restart
*** Unknown syntax: carbon-cache restart
supervisor> restart carbon-cache
carbon-cache: stopped
carbon-cache: started
supervisor>

http://liyangliang.me/posts/2015/06/using-supervisor/

问题

 /Volumes/g/idevz/code/docker/docker-grafana-graphite/ [master*] docker-compose up -d
Recreating 33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_kamon-grafana-dashboard ...
Recreating 33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_kamon-grafana-dashboard ... error

ERROR: for 33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_33f16a168ff3_kamon-grafana-dashboard  no such image: sha256:75abbea27e68bc19c2720cc4864395ae036abcf02563511eba26776476cdd1f1: No such image: sha256:75abbea27e68bc19c2720cc4864395ae036abcf02563511eba26776476cdd1f1

ERROR: for grafana_graphite  no such image: sha256:75abbea27e68bc19c2720cc4864395ae036abcf02563511eba26776476cdd1f1: No such image: sha256:75abbea27e68bc19c2720cc4864395ae036abcf02563511eba26776476cdd1f1
ERROR: Encountered errors while bringing up the project.

解决

直接运行 https://github.com/docker/compose/issues/1113

 /Volumes/g/idevz/code/docker/docker-grafana-graphite/ [master*] docker run -v ~/docker/data/graphite/data/whisper:/opt/graphite/storage/whisper -v ~/docker/data/graphite/data/grafana:/opt/grafana/data -v ~/docker/data/graphite/log/graphite:/opt/graphite/storage/log -p 80:80 -p 81:81 -p 8125:8125/udp -p 8126:8126 -p 2003:2003 -it idevz-graphite /bin/sh

然后 docker ps docker stop loving_benz

然后 docker-compose up -d 即可

comments powered by Disqus