Skip to content

Instantly share code, notes, and snippets.

@leapar
Last active October 11, 2016 04:35
Show Gist options
  • Save leapar/71e8eab2093718944cf33e48de469b8b to your computer and use it in GitHub Desktop.
Save leapar/71e8eab2093718944cf33e48de469b8b to your computer and use it in GitHub Desktop.
datadag云监控macosx

江湖救急,花了两天时间帮同事配了一套监控系统原型,刚好公司配了台mac一体机(16g)的用来测试一把。

#监控平台选型

  1. datadog探针(大牛选的)
  2. opentsdb数据存储(大牛选的)
  3. grafana数据展示(个人喜欢go,所以采用这个)
  4. php数据转接(个人喜欢php,进行数据转接打印比java c++省无数工作量)

##datadog探针安装 到datadog官网下载各系统的安装程序,例如windows是ddagent-cli.msi。安装完成以后把dd_url修改一下: dd_url: http://172.29.225.25:82 25是我的php服务器windows,探针也安装在这台机器上 109上面是mac一体机,安装opentsdb grafana

##opentsdb安装

brew install opentsdb

##grafana安装

brew install grafana

##php代码 php代码是为了模拟成datadog的服务器,把探针采集的数据存储到自己的opentsdb数据库中。 http://172.29.225.109:4242 是opentsdb的服务器。

        $data = file_get_contents('php://input');
        $data = zlib_decode ($data);
        $metrics = \GuzzleHttp\json_decode($data);

        $metrics = $metrics->metrics;
        if(empty($metrics)) {
            return;
        }

        $arrPost = array();
        foreach($metrics as $metric) {
            $sub = new \stdClass();
            $sub->metric = $metric[0];
            $sub->timestamp = $metric[1];
            $sub->value = $metric[2];
            $sub->tags = new \stdClass();//$metric[3];
            $sub->tags->host = "localhost";
            array_push( $arrPost ,$sub);
        }

        $client = new Client();
        $response = $client->request('POST', 'http://172.29.225.109:4242/api/put', [
            'json' => $arrPost
        ]);

##启动服务

brew services start hbase
brew services start opentsdb
brew services start grafana
启动探针dataagent
/usr/local/opt/opentsdb/bin/start-tsdb.sh 
or
#!/bin/sh
exec "/usr/local/opt/opentsdb/bin/tsdb" tsd \
  --config="/usr/local/etc/opentsdb/opentsdb.conf" \
  --staticroot="/usr/local/opt/opentsdb/share/opentsdb/static/" \
  --cachedir="/usr/local/var/cache/opentsdb" \
  --port=4242 \
  --zkquorum=localhost:2181 \
  --zkbasedir=/hbase \
  --auto-metric \
  "$@"

##配置grafana视图 http://172.29.225.109:3000 账号密码都是admin 到data source里面,添加:

type = opentsdb
url = http://172.29.225.109:4242
version 2.2

你要的东西就有了。如果自己想要一套监控系统,自己按上面的配置,只要编写代码24行,当然也可以用Zabbix、Nagios 还有 StatsD。 还是那句话,放开你的思路,你能做的绝对有人已经做得很好了,调查问题一定要周边知识点体系先摸清楚,最后选择你能搞定的。 伪造datadog服务器,这已经是多年培养的条件反射,其实变态点,数据自己都不要存储,展示也可以直接从datadog上面拉。

##进阶 后面把datadog的接口全部做成微服务,采用kong当网关,nginx代理,用consul进行服务的发现以及服务的监控检查。基本上就相当牛逼了,有没有更牛逼点的? 当然有,直接在kong中写插件,或者直接到openstry里面用lua写插件,把php那套代码全部替换掉,性能杠杠。

最后剩下的就是cdn跟运维大牛的事情了,当然加入docker会更好维护。

##mark 下个阶段,有时间写点react-native的实战教程,孤掌难鸣,公司推动是不太现实,跟微服务一样。但是个人的技术布局里面绝对不能少。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment