跳转至

NetStat


NetStat 指标展示,包括 Tcp 连接数、等待连接、等待处理请求、Udp Socket 连接等。

配置

进入 DataKit 安装目录下的 conf.d/samples 目录,复制 netstat.conf.sample 并命名为 netstat.conf。示例如下:

[[inputs.netstat]]
  ##(Optional) Collect interval, default is 10 seconds
  interval = '10s'

## The ports you want display
## Can add tags too
# [[inputs.netstat.addr_ports]]
  # ports = ["80","443"]

## Groups of ports and add different tags to facilitate statistics
# [[inputs.netstat.addr_ports]]
  # ports = ["80","443"]
# [inputs.netstat.addr_ports.tags]
  # service = "http"

# [[inputs.netstat.addr_ports]]
  # ports = ["9529"]
# [inputs.netstat.addr_ports.tags]
  # service = "datakit"
  # foo = "bar"

## Server may have multiple network cards
## Display only some network cards
## Can add tags too
# [[inputs.netstat.addr_ports]]
  # ports = ["1.1.1.1:80","2.2.2.2:80"]
  # ports_match is preferred if both ports and ports_match configured
  # ports_match = ["*:80","*:443"]

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

配置技巧:

## (1) 配置关注的端口号
[[inputs.netstat.addr_ports]]
  ports = ["80","443"]
# (2) 配置两组端口,加上不同的 tag,方便统计
[[inputs.netstat.addr_ports]]
  ports = ["80","443"]
  [inputs.netstat.addr_ports.tags]
    service = "http"

[[inputs.netstat.addr_ports]]
    ports = ["9529"]
    [inputs.netstat.addr_ports.tags]
        service = "datakit"
# (3) 服务器有多个网卡,只关心某几个网卡的情况
[[inputs.netstat.addr_ports]]
  ports = ["1.1.1.1:80","2.2.2.2:80"]
# (4) 服务器有多个网卡,要求按每个网卡分别展示这个配置,会屏蔽掉 ports 的配置值
[[inputs.netstat.addr_ports]]
  ports = ["1.1.1.1:80","2.2.2.2:80"] // 无效,被 ports_match 屏蔽
  ports_match = ["*:80","*:443"] // 有效

配置好后,重启 DataKit 即可。

可通过 ConfigMap 方式注入采集器配置配置 ENV_DATAKIT_INPUTS 开启采集器。

也支持以环境变量的方式修改配置参数(需要在 ENV_DEFAULT_ENABLED_INPUTS 中加为默认采集器):

  • ENV_INPUT_NETSTAT_INTERVAL

    采集器重复间隔时长

    字段类型: Duration

    采集器配置字段: interval

    默认值: 10s

  • ENV_INPUT_NETSTAT_ADDR_PORTS

    端口分组并添加不同的标签以便于统计

    字段类型: JSON

    采集器配置字段: addr_ports

    示例: '["1.1.1.1:80","443"]'

  • ENV_INPUT_NETSTAT_TAGS

    自定义标签。如果配置文件有同名标签,将会覆盖它

    字段类型: String

    采集器配置字段: tags

    示例: 'tag1=value1,tag2=value2'


指标

以下所有数据采集,默认会追加名为 host 的全局 tag(tag 值为 DataKit 所在主机名),也可以在配置中通过 [inputs.netstat.tags] 指定其它标签:

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

不分端口号统计的指标集:netstat,分端口号统计的指标集:netstat_port

Tags & Fields Description
addr_port
(tag)
Addr and port. Optional.
host
(tag)
Host name.
ip_version
(tag)
IP version, 4 for IPV4, 6 for IPV6, unknown for others
tcp_close Current number of TCP sockets in CLOSE state.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_close_wait Current number of TCP sockets in CLOSE_WAIT state after the remote endpoint has requested termination.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_closing Current number of TCP sockets in CLOSING state while both endpoints are closing the connection.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_established Current number of TCP sockets in ESTABLISHED state.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_fin_wait1 Current number of TCP sockets in FIN_WAIT1 state after the local endpoint has requested connection termination.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_fin_wait2 Current number of TCP sockets in FIN_WAIT2 state while waiting for the remote endpoint to terminate the connection.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_last_ack Current number of TCP sockets in LAST_ACK state while waiting for acknowledgement of the final termination segment.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_listen Current number of TCP sockets in LISTEN state waiting for incoming connection requests.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_none Current number of TCP sockets whose state was reported as NONE by the operating system.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_syn_recv Current number of TCP sockets in SYN_RECV state after receiving a connection request and sending an acknowledgement.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_syn_sent Current number of TCP sockets in SYN_SENT state after sending a connection request.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
tcp_time_wait Current number of TCP sockets in TIME_WAIT state after connection termination.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
udp_socket Current number of UDP sockets.
Type: int | (gauge)
Unit: count
Tagged by: ip_version
Tags & Fields Description
addr_port
(tag)
Matched local address and port, or configured port value when the input is configured without an address.
host
(tag)
Host name.
ip_version
(tag)
IP version, 4 for IPV4, 6 for IPV6, unknown for others
pid Process ID associated with the last matched socket in this address/port group. This field is omitted from the aggregate netstat measurement.
Type: int | (gauge)
Unit: N/A
Tagged by: addr_port, ip_version
tcp_close Current number of matched TCP sockets in CLOSE state.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_close_wait Current number of matched TCP sockets in CLOSE_WAIT state after the remote endpoint has requested termination.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_closing Current number of matched TCP sockets in CLOSING state while both endpoints are closing the connection.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_established Current number of matched TCP sockets in ESTABLISHED state.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_fin_wait1 Current number of matched TCP sockets in FIN_WAIT1 state after the local endpoint has requested connection termination.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_fin_wait2 Current number of matched TCP sockets in FIN_WAIT2 state while waiting for the remote endpoint to terminate the connection.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_last_ack Current number of matched TCP sockets in LAST_ACK state while waiting for acknowledgement of the final termination segment.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_listen Current number of matched TCP sockets in LISTEN state waiting for incoming connection requests.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_none Current number of matched TCP sockets whose state was reported as NONE by the operating system.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_syn_recv Current number of matched TCP sockets in SYN_RECV state after receiving a connection request and sending an acknowledgement.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_syn_sent Current number of matched TCP sockets in SYN_SENT state after sending a connection request.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
tcp_time_wait Current number of matched TCP sockets in TIME_WAIT state after connection termination.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version
udp_socket Current number of matched UDP sockets.
Type: int | (gauge)
Unit: count
Tagged by: addr_port, ip_version

文档评价

文档内容是否对您有帮助? ×