コンテンツにスキップ

Consul

·


Consul コレクターは、Consul 関連のメトリクス データを収集するために使用されます。現在、Prometheus 形式のデータのみをサポートしています。

設定

前提条件

consul-exporter のインストール

  • consul_exporter 圧縮パッケージをダウンロード
sudo wget https://github.com/prometheus/consul_exporter/releases/download/v0.7.1/consul_exporter-0.7.1.linux-amd64.tar.gz
  • consul_exporter 圧縮パッケージを解凍します。
sudo tar -zxvf consul_exporter-0.7.1.linux-amd64.tar.gz  
  • consul_exporter-0.7.1.linux-amd64 ディレクトリに入り、consul_exporter スクリプトを実行します。
./consul_exporter     

コレクターの設定

DataKit インストール ディレクトリの下の conf.d/samples ディレクトリに入り、consul.conf.sample をコピーして、consul.conf という名前を付けます。例は次のとおりです。

[[inputs.prom]]
  url = "http://127.0.0.1:9107/metrics"
  source = "consul"
  metric_types = ["counter", "gauge"]
  metric_name_filter = ["consul_raft_leader", "consul_raft_peers", "consul_serf_lan_members", "consul_catalog_service", "consul_catalog_service_node_healthy", "consul_health_node_status", "consul_serf_lan_member_status"]
  measurement_prefix = ""
  tags_ignore = ["check"]
  interval = "10s"

[[inputs.prom.measurements]]
  prefix = "consul_"
  name = "consul"

設定後は、DataKitを再起動します だけです。

現在、コレクタは コレクター設定を挿入するための ConfigMap メソッド を通じてオンにできます。

メトリクス

consul

Tags & Fields Description
check
(tag)
Consul health check label emitted by consul_exporter.
check_id
(tag)
Consul health check ID.
check_name
(tag)
Consul health check name.
host
(tag)
Host name associated with the scraped Consul exporter target.
instance
(tag)
Scraped exporter instance endpoint.
key
(tag)
Consul KV key.
member
(tag)
Consul Serf member name.
node
(tag)
Consul node name.
service_id
(tag)
Consul service ID.
service_name
(tag)
Consul service name.
status
(tag)
Consul health status label, such as critical, maintenance, passing, or warning.
tag
(tag)
Consul service tag value.
catalog_kv Numeric value stored at the tagged Consul key in the key/value catalog. Non-numeric keys are omitted.
Type: float | (gauge)
Unit: N/A
catalog_service_node_healthy Whether the tagged Consul service is healthy on the tagged node.
Type: float | (gauge)
Unit: bool
catalog_services Number of services registered in the Consul catalog.
Type: float | (gauge)
Unit: count
health_node_status Whether the tagged Consul node health check is currently in the tagged status.
Type: float | (gauge)
Unit: bool
health_service_status Whether the tagged Consul service health check is currently in the tagged status.
Type: float | (gauge)
Unit: bool
raft_leader Whether this Consul node reports that the Raft cluster currently has a leader.
Type: float | (gauge)
Unit: bool
raft_peers Number of Consul servers participating as peers in the Raft cluster.
Type: float | (gauge)
Unit: count
serf_lan_member_status Numeric Serf LAN member status code for the tagged member. 1=alive, 2=leaving, 3=left, 4=failed.
Type: float | (gauge)
Unit: N/A
serf_lan_members Number of members in the Consul Serf LAN pool.
Type: float | (gauge)
Unit: count
serf_wan_member_status Numeric Serf WAN member status code for the tagged member. 1=alive, 2=leaving, 3=left, 4=failed.
Type: float | (gauge)
Unit: N/A
service_checks Whether the tagged Consul service is linked with the tagged check_id and check_name.
Type: float | (gauge)
Unit: bool
service_tag Whether the tagged Consul service tag exists for the service_id, node, and tag label set.
Type: float | (gauge)
Unit: bool
up Whether the consul_exporter successfully queried Consul during the last scrape.
Type: float | (gauge)
Unit: bool

ログ

Consul ログを収集したい場合は、Consul を開くときに -syslog パラメータを使用する必要があります。たとえば、

consul agent -dev -syslog

ロギング コレクターを使用してログを収集するには、ロギング コレクターを構成する必要があります。 DataKit インストール ディレクトリの下の conf.d/log ディレクトリに入り、logging.conf.sample をコピーして、logging.conf という名前を付けます。 構成は次のとおりです。

[[inputs.logging]]
  ## required
  logfiles = [
    "/var/log/syslog",
  ]

  ## glob filteer
  ignore = [""]

  ## your logging source, if it's empty, use 'default'
  source = "consul"

  ## add service tag, if it's empty, use $source.
  service = ""

  ## grok pipeline script path
  pipeline = "consul.p"

  ## optional status:
  ##   "emerg","alert","critical","error","warning","info","debug","OK"
  ignore_status = []

  ## optional encodings:
  ##    "utf-8", "utf-16le", "utf-16le", "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'''

  [inputs.logging.tags]
  # some_tag = "some_value"
  # more_tag = "some_other_value"

元のログテキスト:

Sep 18 19:30:23 derrick-ThinkPad-X230 consul[11803]: 2021-09-18T19:30:23.522+0800 [INFO]  agent.server.connect: initialized primary datacenter CA with provider: provider=consul

解析後のフィールド一覧は次のとおりです。

フィールド名 フィールド値 説明
date 2021-09-18T19:30:23.522+0800 ログの日付
level INFO ログレベル
character agent.server.connect 役割
msg initialized primary datacenter CA with provider: provider=consul ログの内容

フィードバック

このページは役に立ちましたか?