💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## **主机连通性探测** 根据上节的安装教程,安装好BlackboxExporter后,我们在主机上执行以下命令: ``` $ curl localhost:9115/probe?module=icmp\&target=114.114.114.114 # HELP probe_dns_lookup_time_seconds Returns the time taken for probe dns lookup in seconds # TYPE probe_dns_lookup_time_seconds gauge probe_dns_lookup_time_seconds 2.0641e-05 # HELP probe_duration_seconds Returns how long the probe took to complete in seconds # TYPE probe_duration_seconds gauge probe_duration_seconds 0.048167187 # HELP probe_icmp_duration_seconds Duration of icmp request by phase # TYPE probe_icmp_duration_seconds gauge probe_icmp_duration_seconds{phase="resolve"} 2.0641e-05 probe_icmp_duration_seconds{phase="rtt"} 0.04375009 probe_icmp_duration_seconds{phase="setup"} 0.004217665 # HELP probe_ip_protocol Specifies whether probe ip protocol is IP4 or IP6 # TYPE probe_ip_protocol gauge probe_ip_protocol 4 # HELP probe_success Displays whether or not the probe was a success # TYPE probe_success gauge probe_success 1 ``` 我们发现,输出就是Prometheus标准的metrics。特别注意最后一个指标`probe_succcess`,它的值为`1`或`0`。 当我们向blackbox-exporter发起上述请求时,blackbox-exporter就会去ping 114.114.114.114,如果ping通了,则`probe_success`的值为`1`,如果没有ping通,则`probe_success`的值为`0`。 ## **TCP端口连通性探测** 我们再执行以下命令: ``` curl localhost:9115/probe?module=tcp_connect\&target=www.baidu.com:80 # HELP probe_dns_lookup_time_seconds Returns the time taken for probe dns lookup in seconds # TYPE probe_dns_lookup_time_seconds gauge probe_dns_lookup_time_seconds 0.012304919 # HELP probe_duration_seconds Returns how long the probe took to complete in seconds # TYPE probe_duration_seconds gauge probe_duration_seconds 0.023257395 # HELP probe_failed_due_to_regex Indicates if probe failed due to regex # TYPE probe_failed_due_to_regex gauge probe_failed_due_to_regex 0 # HELP probe_ip_protocol Specifies whether probe ip protocol is IP4 or IP6 # TYPE probe_ip_protocol gauge probe_ip_protocol 4 # HELP probe_success Displays whether or not the probe was a success # TYPE probe_success gauge probe_success 1 ``` 同样,最后一个指标也是`probe_success`。当我们发起这个请求时,blackbox-exporter会探测`www.baidu.com`的`80`端口是否可以通,如果是通的,则`probe_success`的值为`1`,否则为`0`。 ## **SSH连通性探测** 我们发起如下的请求: ``` $ curl localhost:9115/probe?module=ssh_banner\&target=localhost:22 # HELP probe_dns_lookup_time_seconds Returns the time taken for probe dns lookup in seconds # TYPE probe_dns_lookup_time_seconds gauge probe_dns_lookup_time_seconds 0.000208936 # HELP probe_duration_seconds Returns how long the probe took to complete in seconds # TYPE probe_duration_seconds gauge probe_duration_seconds 0.016594513 # HELP probe_failed_due_to_regex Indicates if probe failed due to regex # TYPE probe_failed_due_to_regex gauge probe_failed_due_to_regex 0 # HELP probe_ip_protocol Specifies whether probe ip protocol is IP4 or IP6 # TYPE probe_ip_protocol gauge probe_ip_protocol 6 # HELP probe_success Displays whether or not the probe was a success # TYPE probe_success gauge probe_success 1 ``` 当我们发起上面的请求时,blackbox-exporter会尝试ssh到`localhost:22`,如果是通的(不需要密码,相当于我们手动ssh主机,能够得到输入密码的提示),则`probe_success`的值为`1` ## **HTTP的GET请求探测** 执行以下命令: ``` $ curl localhost:9115/probe?module=http_2xx\&target=www.baidu.com # HELP probe_dns_lookup_time_seconds Returns the time taken for probe dns lookup in seconds # TYPE probe_dns_lookup_time_seconds gauge probe_dns_lookup_time_seconds 0.011763045 # HELP probe_duration_seconds Returns how long the probe took to complete in seconds # TYPE probe_duration_seconds gauge probe_duration_seconds 0.169438139 # HELP probe_failed_due_to_regex Indicates if probe failed due to regex # TYPE probe_failed_due_to_regex gauge probe_failed_due_to_regex 0 # HELP probe_http_content_length Length of http content response # TYPE probe_http_content_length gauge probe_http_content_length -1 # HELP probe_http_duration_seconds Duration of http request by phase, summed over all redirects # TYPE probe_http_duration_seconds gauge probe_http_duration_seconds{phase="connect"} 0.011417546 probe_http_duration_seconds{phase="processing"} 0.025588187 probe_http_duration_seconds{phase="resolve"} 0.011763045 probe_http_duration_seconds{phase="tls"} 0 probe_http_duration_seconds{phase="transfer"} 0.120212515 # HELP probe_http_redirects The number of redirects # TYPE probe_http_redirects gauge probe_http_redirects 0 # HELP probe_http_ssl Indicates if SSL was used for the final redirect # TYPE probe_http_ssl gauge probe_http_ssl 0 # HELP probe_http_status_code Response HTTP status code # TYPE probe_http_status_code gauge probe_http_status_code 200 # HELP probe_http_uncompressed_body_length Length of uncompressed response body # TYPE probe_http_uncompressed_body_length gauge probe_http_uncompressed_body_length 284351 # HELP probe_http_version Returns the version of HTTP of the probe response # TYPE probe_http_version gauge probe_http_version 1.1 # HELP probe_ip_protocol Specifies whether probe ip protocol is IP4 or IP6 # TYPE probe_ip_protocol gauge probe_ip_protocol 4 # HELP probe_success Displays whether or not the probe was a success # TYPE probe_success gauge probe_success 1 ``` 当我们发起上述请求时,blackbox-exporter会向`http://www.baidu.com`发起一个GET请求,如果返回码为2xx,则`probe_success`的值为`1`,否则为`0`。 这里 blackbox-exporter 为什么访问的不是 `https://www.baid.com`,这是因为blackbox-exporter的配置文件`/usr/local/blackbox_exporter/blackbox.yml`中的如下配置决定的: ``` http_2xx: prober: http ``` ## **其他** blackbox-exporter还有其他的模块没有介绍,比如`http_post_2xx`、`pop3_bannar`、`irc_banner`。