那node exporter如何获取主机监听端口信息
时间: 2024-03-24 07:36:24 浏览: 18
Node Exporter 可以通过收集系统内核网络和文件句柄的信息来获取主机监听端口信息。具体来说,Node Exporter 会读取 `/proc/net/tcp` 和 `/proc/net/tcp6` 文件来获取 TCP 监听端口的信息,同时也会读取 `/proc/net/udp` 和 `/proc/net/udp6` 文件来获取 UDP 监听端口的信息。
Node Exporter 收集到的端口信息会作为 `node_network_*` 和 `node_filehandle_*` 系列指标的一部分,其中 `node_network_*` 指标包含 TCP 和 UDP 监听端口的信息,而 `node_filehandle_*` 指标包含每个进程打开的文件句柄数量信息。
例如,可以使用以下命令来列出 Node Exporter 收集到的所有网络相关的指标信息:
```
curl http://node-exporter-ip:9100/metrics | grep node_network
```
您将看到类似于以下内容的输出:
```
# HELP node_network_address_translation_table_entries Number of address translation table entries.
# TYPE node_network_address_translation_table_entries gauge
node_network_address_translation_table_entries 0
# HELP node_network_active_opens Number of times TCP connections have made a direct transition to the SYN-SENT state from the CLOSED state.
# TYPE node_network_active_opens gauge
node_network_active_opens 5
# HELP node_network_attempt_fails Number of times TCP connections have made a direct transition to the CLOSED state from either the SYN-SENT state or the SYN-RCVD state, plus the number of times TCP connections have made a direct transition to the LISTEN state from the SYN-RCVD state.
# TYPE node_network_attempt_fails gauge
node_network_attempt_fails 0
...
```
其中 `node_network_*` 指标中的 `local_address` 和 `local_port` 字段表示监听的本地IP地址和端口。