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压缩包
- 进入 consul_exporter-0.7.1.linux-amd64 目录,运行
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 参数,例如
使用 logging 采集器采集日志,需要配置 logging 采集器。
进入 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 |
日志内容 |