Kong Gateway - 20 基于网关服务的分析&监视(Analytics &Monitoring Datadog)

https://docs.datadoghq.com/agent/

https://docs.datadoghq.com/

Datadog只是一个客户端,只有14天的试用期,每台服务器专业版15美元/月,企业版23美元/月,不便宜,没想深入研究

Configure a Service in Kong
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/ \
--data 'name=country' \
--data 'url=http://contoso.com/v1/countries'

HTTP/1.1 201 Created
Date: Sun, 20 May 2018 14:57:52 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "host": "contoso.com", 
    "created_at": 1526799472, 
    "connect_timeout": 60000, 
    "id": "13658bbd-b529-48d2-9f52-457827adece6", 
    "protocol": "http", 
    "name": "country", 
    "read_timeout": 60000, 
    "port": 80, 
    "path": "/v1/countries", 
    "updated_at": 1526799472, 
    "retries": 5, 
    "write_timeout": 60000
}
Add a Route to expose the Service
URL Format http://localhost:8001/services/{name of servie}/routes
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/routes \
--data 'paths[]=/v1/countries'
HTTP/1.1 201 Created
Date: Sun, 20 May 2018 14:58:12 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1526799492, 
    "strip_path": true, 
    "hosts": null, 
    "preserve_host": false, 
    "regex_priority": 0, 
    "updated_at": 1526799492, 
    "paths": [
        "/v1/countries"
    ], 
    "service": {
        "id": "13658bbd-b529-48d2-9f52-457827adece6"
    }, 
    "methods": null, 
    "protocols": [
        "http", 
        "https"
    ], 
    "id": "f7c8fdb6-5f65-46e3-b3e8-9ad8c8a03c13"   // {route_id} = id
}
Enabling the CORS plugin for a Service
URL Format http://localhost:8001/services/{name of servie}/plugins
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/plugins \
--data "name=cors"  \
--data "config.origins=http://contoso.com" \
--data "config.methods=GET, POST" \
--data "config.headers=Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Auth-Token" \
--data "config.exposed_headers=X-Auth-Token" \
--data "config.credentials=true" \
--data "config.max_age=3600"
HTTP/1.1 201 Created
Date: Sun, 20 May 2018 14:58:44 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1526828324000, 
    "config": {
        "methods": [
            "GET", 
            "POST"
        ], 
        "exposed_headers": [
            "X-Auth-Token"
        ], 
        "max_age": 3600, 
        "headers": [
            "Accept", 
            "Accept-Version", 
            "Content-Length", 
            "Content-MD5", 
            "Content-Type", 
            "Date", 
            "X-Auth-Token"
        ], 
        "credentials": true, 
        "origins": [
            "http://contoso.com"
        ], 
        "preflight_continue": false
    }, 
    "id": "98aec35c-0ade-46d3-aacc-e0e9041df903", 
    "enabled": true, 
    "service_id": "13658bbd-b529-48d2-9f52-457827adece6", 
    "name": "cors"
}
Enabling the CORS plugin for a Route
URL Format http://localhost:8001/routes/{route_id}/plugins
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/routes/f7c8fdb6-5f65-46e3-b3e8-9ad8c8a03c13/plugins \
--data "name=cors"  \
--data "config.origins=http://contoso.com" \
--data "config.methods=GET, POST" \
--data "config.headers=Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Auth-Token" \
--data "config.exposed_headers=X-Auth-Token" \
--data "config.credentials=true" \
--data "config.max_age=3600"
HTTP/1.1 201 Created
Date: Sun, 20 May 2018 14:59:37 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1526828378000, 
    "config": {
        "methods": [
            "GET", 
            "POST"
        ], 
        "exposed_headers": [
            "X-Auth-Token"
        ], 
        "max_age": 3600, 
        "headers": [
            "Accept", 
            "Accept-Version", 
            "Content-Length", 
            "Content-MD5", 
            "Content-Type", 
            "Date", 
            "X-Auth-Token"
        ], 
        "credentials": true, 
        "origins": [
            "http://contoso.com"
        ], 
        "preflight_continue": false
    }, 
    "id": "10e6e1ab-08b8-4ef3-9a96-d810df78c6ab", 
    "enabled": true, 
    "route_id": "f7c8fdb6-5f65-46e3-b3e8-9ad8c8a03c13", 
    "name": "cors"
}
[root@contoso ~]# curl -i -X GET \
--url http://localhost:8000/v1/countries?page=5
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 1360
Connection: keep-alive
Date: Sun, 20 May 2018 15:00:16 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.1.13
X-Powered-By: PHP/7.1.13
X-RateLimit-Limit-countries: countries=3
Vary: Origin
Access-Control-Allow-Origin: http://contoso.com
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: X-Auth-Token
X-Kong-Upstream-Latency: 72
X-Kong-Proxy-Latency: 54
Via: kong/0.13.1

{
    "total": 170433, 
    "per_page": 10, 
    "current_page": "5", 
    "last_page": 17044, 
    "data": [
        {
            "id": 41, 
            "sip": "1.32.195.0", 
            "eip": "1.32.196.255", 
            "sip2long": 18924288, 
            "eip2long": 18924799, 
            "code": "HK", 
            "country_name": "Hong Kong"
        }, 
        {
            "id": 42, 
            "sip": "1.32.197.0", 
            "eip": "1.32.197.255", 
            "sip2long": 18924800, 
            "eip2long": 18925055, 
            "code": "TW", 
            "country_name": "Taiwan"
        }, 
        {
            "id": 43, 
            "sip": "1.32.198.0", 
            "eip": "1.32.199.255", 
            "sip2long": 18925056, 
            "eip2long": 18925567, 
            "code": "HK", 
            "country_name": "Hong Kong"
        }, 
        {
            "id": 44, 
            "sip": "1.32.200.0", 
            "eip": "1.32.201.255", 
            "sip2long": 18925568, 
            "eip2long": 18926079, 
            "code": "SG", 
            "country_name": "Singapore"
        }, 
        {
            "id": 45, 
            "sip": "1.32.202.0", 
            "eip": "1.32.202.127", 
            "sip2long": 18926080, 
            "eip2long": 18926207, 
            "code": "TW", 
            "country_name": "Taiwan"
        }, 
        {
            "id": 46, 
            "sip": "1.32.202.128", 
            "eip": "1.32.202.255", 
            "sip2long": 18926208, 
            "eip2long": 18926335, 
            "code": "SG", 
            "country_name": "Singapore"
        }, 
        {
            "id": 47, 
            "sip": "1.32.203.0", 
            "eip": "1.32.203.127", 
            "sip2long": 18926336, 
            "eip2long": 18926463, 
            "code": "TW", 
            "country_name": "Taiwan"
        }, 
        {
            "id": 48, 
            "sip": "1.32.203.128", 
            "eip": "1.32.203.255", 
            "sip2long": 18926464, 
            "eip2long": 18926591, 
            "code": "SG", 
            "country_name": "Singapore"
        }, 
        {
            "id": 49, 
            "sip": "1.32.204.0", 
            "eip": "1.32.204.127", 
            "sip2long": 18926592, 
            "eip2long": 18926719, 
            "code": "TW", 
            "country_name": "Taiwan"
        }, 
        {
            "id": 50, 
            "sip": "1.32.204.128", 
            "eip": "1.32.207.255", 
            "sip2long": 18926720, 
            "eip2long": 18927615, 
            "code": "SG", 
            "country_name": "Singapore"
        }
    ]
}
Enabling the plugin for a Service
URL Format http://localhost:8001/services/{service}/plugins
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/services/country/plugins \
--data "name=datadog"  \
--data "config.host=127.0.0.1" \
--data "config.port=8125"
HTTP/1.1 201 Created
Date: Sun, 20 May 2018 15:16:29 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1526829388000, 
    "config": {
        "host": "127.0.0.1", 
        "port": 8125, 
        "prefix": "kong", 
        "metrics": [
            {
                "sample_rate": 1, 
                "name": "request_count", 
                "tags": [
                    "app:kong"
                ], 
                "stat_type": "counter"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "latency", 
                "stat_type": "timer"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "request_size", 
                "stat_type": "timer"
            }, 
            {
                "sample_rate": 1, 
                "name": "status_count", 
                "tags": [
                    "app:kong"
                ], 
                "stat_type": "counter"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "response_size", 
                "stat_type": "timer"
            }, 
            {
                "consumer_identifier": "custom_id", 
                "name": "unique_users", 
                "tags": [
                    "app:kong"
                ], 
                "stat_type": "set"
            }, 
            {
                "stat_type": "counter", 
                "sample_rate": 1, 
                "name": "request_per_user", 
                "tags": [
                    "app:kong"
                ], 
                "consumer_identifier": "custom_id"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "upstream_latency", 
                "stat_type": "timer"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "kong_latency", 
                "stat_type": "timer"
            }, 
            {
                "stat_type": "counter", 
                "sample_rate": 1, 
                "name": "status_count_per_user", 
                "tags": [
                    "app:kong"
                ], 
                "consumer_identifier": "custom_id"
            }
        ]
    }, 
    "id": "34f99e34-2deb-4c39-8ea9-880d8d62cc6c", 
    "enabled": true, 
    "service_id": "13658bbd-b529-48d2-9f52-457827adece6", 
    "name": "datadog"
}
Enabling the plugin for a Route
URL Format http://localhost:8001/routes/{route_id}/plugins
[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/routes/f7c8fdb6-5f65-46e3-b3e8-9ad8c8a03c13/plugins \
--data "name=datadog"  \
--data "config.host=127.0.0.1" \
--data "config.port=8125"
HTTP/1.1 201 Created
Date: Sun, 20 May 2018 15:18:10 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.13.1

{
    "created_at": 1526829491000, 
    "config": {
        "host": "127.0.0.1", 
        "port": 8125, 
        "prefix": "kong", 
        "metrics": [
            {
                "sample_rate": 1, 
                "name": "request_count", 
                "tags": [
                    "app:kong"
                ], 
                "stat_type": "counter"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "latency", 
                "stat_type": "timer"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "request_size", 
                "stat_type": "timer"
            }, 
            {
                "sample_rate": 1, 
                "name": "status_count", 
                "tags": [
                    "app:kong"
                ], 
                "stat_type": "counter"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "response_size", 
                "stat_type": "timer"
            }, 
            {
                "consumer_identifier": "custom_id", 
                "name": "unique_users", 
                "tags": [
                    "app:kong"
                ], 
                "stat_type": "set"
            }, 
            {
                "stat_type": "counter", 
                "sample_rate": 1, 
                "name": "request_per_user", 
                "tags": [
                    "app:kong"
                ], 
                "consumer_identifier": "custom_id"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "upstream_latency", 
                "stat_type": "timer"
            }, 
            {
                "tags": [
                    "app:kong"
                ], 
                "name": "kong_latency", 
                "stat_type": "timer"
            }, 
            {
                "stat_type": "counter", 
                "sample_rate": 1, 
                "name": "status_count_per_user", 
                "tags": [
                    "app:kong"
                ], 
                "consumer_identifier": "custom_id"
            }
        ]
    }, 
    "id": "777948c9-787d-4fbc-b507-7cf31a91b7a7", 
    "enabled": true, 
    "route_id": "f7c8fdb6-5f65-46e3-b3e8-9ad8c8a03c13", 
    "name": "datadog"
}

Enabling the plugin for a Consumer

如下命令要想被执行,可不止这一条,还需要其他多条命令的配合,参照前面的范例自己补充吧,以下命令的玩法省略

[root@contoso ~]# curl -i -X POST \
--url http://localhost:8001/plugins \
--data "name=datadog" \
--data "consumer_id={consumer_id}"  \
--data "config.host=127.0.0.1" \
--data "config.port=8125"



Installing on CentOS
The Datadog Agent has x86_64 packages. For other architectures, you can use the source (https://app.datadoghq.com/signup/agent#source) install.

Use our easy one-step install.

DD_API_KEY=a1585022930733da3fcc9ef7f47b7f9e bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/datadog-agent/master/cmd/agent/install_script.sh)"

If you prefer to see the installation step-by-step, click (https://app.datadoghq.com/signup/agent#) here

1. Set up Datadog's Yum repo on your system by creating /etc/yum.repos.d/datadog.repo with the contents:

[root@contoso ~]# cat > /etc/yum.repos.d/datadog.repo
[datadog]
name = Datadog, Inc.
baseurl = https://yum.datadoghq.com/stable/6/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://yum.datadoghq.com/DATADOG_RPM_KEY.public

2. Update your local yum repo and install the Agent:

[root@contoso ~]# yum makecache && yum remove datadog-agent-base && yum install -y datadog-agent

3. Copy the example config into place and plug in your API key (a1585022930733da3fcc9ef7f47b7f9e):

[root@contoso ~]# sh -c "sed 's/api_key:.*/api_key: a1585022930733da3fcc9ef7f47b7f9e/' /etc/datadog-agent/datadog.yaml.example > /etc/datadog-agent/datadog.yaml"

4. Re-start the Agent on Centos 7 and above:

[root@contoso ~]# systemctl restart datadog-agent.service

[root@contoso ~]# systemctl status datadog-agent.service
鈼[0m datadog-agent.service - "Datadog Agent"
   Loaded: loaded (/usr/lib/systemd/system/datadog-agent.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-05-21 17:04:24 CST; 13s ago
 Main PID: 22872 (agent)
   CGroup: /system.slice/datadog-agent.service
           鈹斺攢22872 /opt/datadog-agent/bin/agent/agent start -p /opt/datadog-agent/run/agent.pid

May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (autoconfig.go:268 in schedule) | Scheduling check memory
May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (scheduler.go:72 in Enter) | Scheduling check memory... of 15s
May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (autoconfig.go:268 in schedule) | Scheduling check network
May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (scheduler.go:72 in Enter) | Scheduling check networ... of 15s
May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (autoconfig.go:268 in schedule) | Scheduling check ntp
May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (scheduler.go:72 in Enter) | Scheduling check ntp wi... of 15s
May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (autoconfig.go:268 in schedule) | Scheduling check uptime
May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (scheduler.go:72 in Enter) | Scheduling check uptime... of 15s
May 21 17:04:25 contoso.org agent[22872]: 2018-05-21 17:04:25 CST | INFO | (serializer.go:180 in SendMetadata) | Sent host meta... bytes.
May 21 17:04:32 contoso.org agent[22872]: 2018-05-21 17:04:32 CST | INFO | (transaction.go:109 in Process) | Successfully poste...actions
Hint: Some lines were ellipsized, use -l to show in full.


[root@contoso ~]# cat /etc/datadog-agent/datadog.yaml.example

[root@contoso ~]# ls /etc/datadog-agent/conf.d
activemq.d            dns_check.d      haproxy.d               kubernetes_state.d   nagios.d             rabbitmq.d     teamcity.d
activemq_xml.d        docker.d         hdfs_datanode.d         kyototycoon.d        network.d            redisdb.d      tokumx.d
apache.d              ecs_fargate.d    hdfs_namenode.d         lighttpd.d           nfsstat.d            riakcs.d       tomcat.d
btrfs.d               elastic.d        http_check.d            linkerd.d            nginx.d              riak.d         twemproxy.d
cacti.d               envoy.d          io.d                    linux_proc_extras.d  ntp.d                snmp.d         uptime.d
cassandra.d           etcd.d           istio.d                 load.d               openstack.d          solr.d         varnish.d
cassandra_nodetool.d  file_handle.d    jmx.d                   mapreduce.d          oracle.d             spark.d        vsphere.d
ceph.d                fluentd.d        kafka_consumer.d        marathon.d           pgbouncer.d          squid.d        yarn.d
consul.d              gearmand.d       kafka.d                 mcache.d             php_fpm.d            ssh_check.d    zk.d
couchbase.d           gitlab.d         kong.d                  memory.d             postfix.d            statsd.d
couch.d               gitlab_runner.d  kube_dns.d              mesos_master.d       postgres.d           supervisord.d
cpu.d                 go_expvar.d      kubelet.d               mesos_slave.d        powerdns_recursor.d  system_core.d
directory.d           go-metro.d       kube_proxy.d            mongo.d              process.d            system_swap.d
disk.d                gunicorn.d       kubernetes_apiserver.d  mysql.d              prometheus.d         tcp_check.d
[root@contoso ~]# ls /etc/datadog-agent/conf.d/kong.d
conf.yaml.example

5. Edit the kong.d/conf.yaml file, in the conf.d/ folder at the root of your Agent’s directory
[root@contoso ~]# cat > /etc/datadog-agent/conf.d/kong.d/conf.yaml
init_config:

instances:
  # For every instance, you need an `kong_status_url` and can optionally
  # supply a list of tags.
  #
  - kong_status_url: http://localhost:8001/status/
  #   ssl_validation: true
    tags:
        - instance:foo
  #
  # - kong_status_url: http://example2.com:8001/status/
  #   tags:
  #     - instance:bar

找到以下图片显示的页面 ,你需要安装 Kong Integrations ,在众多列表项中找到 Kong Available

点击 +Available  点击 Install Integrations


6. Restart the Agent to begin sending Kong metrics to Datadog.
 
systemctl restart datadog-agent.service




[root@contoso ~]# for i in `seq 1 10000`
do
curl -i -X GET \
--url http://contoso.org:8000/v1/countries?page=$i
done

[root@contoso ~]# yum install -y httpd-tools
[root@contoso ~]# ab -V
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

[root@contoso ~]# ab -n 50000 -c 200 http://contoso.org:8000/v1/countries?page=5
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking contoso.org (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests


Server Software:        Apache/2.4.6
Server Hostname:        contoso.org
Server Port:            8000

Document Path:          /v1/countries?page=5
Document Length:        1360 bytes

Concurrency Level:      200
Time taken for tests:   973.983 seconds
Complete requests:      50000
Failed requests:        7660
   (Connect: 0, Receive: 0, Length: 7660, Exceptions: 0)
Write errors:           0
Non-2xx responses:      7660
Total transferred:      83683169 bytes
HTML transferred:       58746720 bytes
Requests per second:    51.34 [#/sec] (mean)
Time per request:       3895.934 [ms] (mean)
Time per request:       19.480 [ms] (mean, across all concurrent requests)
Transfer rate:          83.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   7.2      0     184
Processing:    53 3891 2032.9   3634   41689
Waiting:       53 3889 2032.9   3633   41689
Total:         53 3893 2033.3   3637   41732

Percentage of the requests served within a certain time (ms)
  50%   3637
  66%   4338
  75%   4849
  80%   5193
  90%   6220
  95%   7197
  98%   8613
  99%   9952
 100%  41732 (longest request)
[root@contoso ~]#



相关文章
相关标签/搜索