Kong
Kong のメトリクス、ログ、トレース情報を収集します
メトリクス¶
1. Kong の設定¶
Kong では Prometheus プラグインを有効にしてからメトリクスデータを報告できます。ここではグローバルな方法での設定を推奨します。参考として Kong 公式ドキュメント を参照してください
Kong Manager で設定する¶
Kong Manager にログインし、Plugins メニューをクリックして Prometheus を追加します。
Kong API で設定する¶
curl -X POST http://localhost:8001/plugins \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "prometheus",
"config": {
"per_consumer": true,
"status_code_metrics" : true,
"bandwidth_metrics": true
}
}'
2. DataKit の設定¶
- datakit のインストールディレクトリ配下の
conf.d/samplesディレクトリに移動し、prom.conf.sampleをコピーしてkong.confにします
cp prom.conf.sample kong.conf
kong.confを調整します
以下の 2 つのパラメータだけを調整し、他はそのままにします。
[[inputs.prom]]
## Exporter URLs.
urls = ["http://127.0.0.1:8001/metrics"]
keep_exist_metric_name = true
- DataKit を再起動します
以下のコマンドを実行します
3. Kong のメトリクスセット¶
| メトリクス名 | 単位 | 説明 |
|---|---|---|
| kong_bandwidth_bytes | bytes | Kong の帯域使用量。単位はバイト |
| kong_datastore_reachable | - | データストアに到達可能かどうかを示す状態メトリクス |
| kong_http_requests_total | count | HTTP リクエストの総数 |
| kong_kong_latency_ms_bucket | ms | Kong 自身のレイテンシのヒストグラムバケット。単位はミリ秒 |
| kong_kong_latency_ms_count | count | Kong 自身のレイテンシのカウント |
| kong_kong_latency_ms_sum | ms | Kong 自身のレイテンシの合計。単位はミリ秒 |
| kong_latency_ms_bucket | ms | リクエストレイテンシのヒストグラムバケット。単位はミリ秒 |
| kong_latency_ms_count | count | リクエストレイテンシのカウント |
| kong_latency_ms_sum | ms | リクエストレイテンシの合計。単位はミリ秒 |
| kong_memory_lua_shared_dict_bytes | bytes | Lua 共有辞書で使用されるメモリ。単位はバイト |
| kong_memory_lua_shared_dict_total_bytes | bytes | Lua 共有辞書の総メモリ。単位はバイト |
| kong_memory_workers_lua_vms_bytes | bytes | ワーカープロセス内の Lua 仮想マシンが使用するメモリ。単位はバイト |
| kong_nginx_connections_total | count | Nginx 接続の総数 |
| kong_nginx_metric_errors_total | count | Nginx メトリクスエラーの総数 |
| kong_nginx_requests_total | count | Nginx リクエストの総数 |
| kong_node_info | - | ノード情報 |
| kong_request_latency_ms_bucket | ms | リクエストレイテンシのヒストグラムバケット。単位はミリ秒 |
| kong_request_latency_ms_count | count | リクエストレイテンシのカウント |
| kong_request_latency_ms_sum | ms | リクエストレイテンシの合計。単位はミリ秒 |
| kong_upstream_latency_ms_bucket | ms | アップストリームレイテンシのヒストグラムバケット。単位はミリ秒 |
| kong_upstream_latency_ms_count | count | アップストリームレイテンシのカウント |
| kong_upstream_latency_ms_sum | ms | アップストリームレイテンシの合計。単位はミリ秒 |
ログ¶
1. Kong の設定¶
Kong では TCP Log プラグインを有効にしてからログデータを報告できます
Kong Manager で設定する¶
Kong Manager にログインし、Plugins メニューをクリックして TCP Log を追加します。
パラメータの説明:
- host:DataKit host
- port: DataKit ログ socket ポート
Kong API で設定する¶
curl -X POST http://localhost:8001/plugins \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "tcp-log",
"config": {
"port": 9580,
"host" : "<datakit-host>"
}
}'
2. DataKit の設定¶
- datakit のインストールディレクトリ配下の
conf.d/logディレクトリに移動し、logging.conf.sampleをコピーしてkong-socket.confにします
cp logging.conf.sample kong-socket.conf
kong-socket.confを調整します
以下の全文で置き換えます。
# {"version": "1.22.0", "desc": "do NOT edit this line"}
[[inputs.logging]]
## Required
## File names or a pattern to tail.
# Only two protocols are supported:TCP and UDP.
sockets = [
"tcp://0.0.0.0:9580",
# "udp://0.0.0.0:9531",
]
## glob filteer
ignore = [""]
## Your logging source, if it's empty, use 'default'.
source = "kong_tcp_log"
## Add service tag, if it's empty, use $source.
service = ""
## Grok pipeline script name.
pipeline = ""
## optional status:
## "emerg","alert","critical","error","warning","info","debug","OK"
ignore_status = []
## optional encodings:
## "utf-8", "utf-16le", "utf-16be", "gbk", "gb18030" or ""
character_encoding = ""
## The pattern should be a regexp. Note the use of '''this regexp'''.
## regexp link: https://golang.org/pkg/regexp/syntax/#hdr-Syntax
# multiline_match = '''^\S'''
auto_multiline_detection = true
auto_multiline_extra_patterns = []
## Removes ANSI escape codes from text strings.
remove_ansi_escape_codes = false
## If the data sent failure, will retry forevery.
blocking_mode = true
## If file is inactive, it is ignored.
## time units are "ms", "s", "m", "h"
ignore_dead_log = "1h"
## Read file from beginning.
from_beginning = false
[inputs.logging.tags]
# some_tag = "some_value"
# more_tag = "some_other_value"
- DataKit を再起動します
以下のコマンドを実行します
Pipeline¶
Pipeline はログのフィールド抽出に利用できます。テンプレートはあらかじめ組み込まれており、Pipeline テンプレートライブラリで Kong を見つけてクローンし、利用できます。
トレース¶
1. Kong の設定¶
Kong では OpenTelemetry プラグインを有効にしてからトレースデータを報告できます。この機能は Kong version ≥ 3.3.2 が必要です。
グローバルなトレース設定を有効にする¶
kong.conf に以下の設定項目を追加します:
または環境変数を追加します:
Kong サービスを再起動すると有効になります。
Kong Manager で設定する¶
Kong Manager にログインし、Plugins メニューをクリックして OpenTelemetry を追加します。
Kong API で設定する¶
curl -X POST http://localhost:8001/plugins \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"protocols": [
"http"
],
"name": "opentelemetry",
"config": {
"propagation": {
"default_format": "datadog"
},
"traces_endpoint": "http://192.168.2.110:9529/otel/v1/traces"
},
"enabled": true
}'
2. DataKit の設定¶
- datakit のインストールディレクトリ配下の
conf.d/opentelemetryディレクトリに移動し、opentelemetry.conf.sampleをコピーしてopentelemetry.confにします
cp opentelemetry.conf.sample opentelemetry.conf
設定内容の調整は不要です
- DataKit を再起動します
以下のコマンドを実行します