微服务kong之Datadog

微服务的监控

当我们采用的微服务架构,享受其带来好处的同时,随之而来也伴随着一些“副作用“,其中之一就是如何有效地监控这些服务。

Kong可以通过datadog plugin把指定API请求统计数据转发到datadog服务器,从而可以通过datadog统一管理API的监控数据。

配置datadog

  • 什么是datadog?

    datadog是一个跨操作系统,应用,服务的数据监控和分析Saas平台。1

  • 什么是datadog agent?

    datadog为各种接入对象,提供了不同的集成方式。其中有一部分的集成需要依赖于datadog agent来完成,datadog agent是一个运行在主机上的软件,它会忠实地不断收集数据,然后发送到datadog服务器。datadog plugin依赖于agent。2

  • Mac下安装本地datadog agent
通过此链接注册datadog,获取apikey
https://app.datadoghq.com/account/settings#agent/mac
  • 安装脚本:
$ DD_API_KEY=dfa9fe73452b9768fbbeb8ec5305a5c2 bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/osx/install.sh)"
  • 启动datadog agent 3
$ /usr/local/bin/datadog-agent start

给API安装datadog plugin

curl -X POST http://localhost:8001/apis/yichicloud/plugins \
    --data "name=datadog" \
    --data "config.host=127.0.0.1" \
    --data "config.port=8125" \
    --data "config.timeout=5000"
安装成功返回

{"api_id":"5d88e0cd-8af9-441e-9b37-e3ce0a0391c3",
"id":"270b902c-f743-4145-88ce-8907931d6d60",
"created_at":1469765673000,
"enabled":true,
"name":"datadog",
"config":{"host":"127.0.0.1",
		"timeout":1000,
		"metrics":["request_count",
					"latency",
					"request_size",
					"status_count",
					"response_size",
					"unique_users",
					"request_per_user"],
		"port":8125
		}
}

监控矩阵:

再次访问

curl -i -X GET \
  --url http://localhost:8000/ \
  --header 'Host: yichicloud.com'

datadog plugin会给datadog服务器发送如下监控矩阵 4

打开datadog metric后台,可以看到监控数据: https://app.datadoghq.com/metric/explorer

以上

  1. https://www.datadoghq.com/product/integrations/ 

  2. https://help.datadoghq.com/hc/en-us/articles/203034929-What-is-the-Datadog-Agent-What-resources-does-it-consume 

  3. http://docs.datadoghq.com/guides/basic_agent_usage/osx/ 

  4. https://getkong.org/plugins/datadog/