<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • BlackboxExporter是什么?-創(chuàng)新互聯(lián)

            這篇文章主要為大家詳細(xì)介紹了Blackbox Exporter,其中包括如何運行Blackbox Exporter,對Blackbox Exporter配置文件的解讀,感興趣的小伙伴們可以參考一下。

            專注于為中小企業(yè)提供網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)寒亭免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。

            什么是 blackbox exporter?

            Blackbox Exporter 是 Prometheus 社區(qū)提供的 官方黑盒監(jiān)控解決方案,其允許用戶通過:http\HTTPS\DNS\TCP\ICMP的方式對網(wǎng)絡(luò)進行探測.

            以 docker 方式運行 blackbox exporter

            拉取鏡像

            docker pull prom/blackbox-exporter

            查看 dockerfile(這是一個好習(xí)慣)

            $ cat check_docker_file.sh
            #!/bin/bash
            export PATH=$PATH
            if [ $# -eq 1 ];then
                    docker history --format {{.CreatedBy}} --no-trunc=true $1 |sed "s/\/bin\/sh\ -c\ \#(nop)\ //g"|sed "s/\/bin\/sh\ -c/RUN/g" | tac
                else
                    echo "sh Obtain_dockerfile.sh $DOCKER_IMAGE"
            fi
            
            $ sh check_docker_file.sh prom/blackbox-exporter:latest
            ADD file:b265aa0ea2ef7ff1f4a3e087217e75aca2c90f5c345406299664cc7969b2b28e in /
             CMD ["sh"]
             MAINTAINER The Prometheus Authors <[email protected]>
            COPY dir:b1c1c3c551755544b818d03ad9136b137ca12c48393ba5cdd58d7f845647e042 in /
             LABEL maintainer=The Prometheus Authors <[email protected]>
             ARG ARCH=amd64
             ARG OS=linux
            COPY file:2bfe91827ebb767bc51f40cd84675a3c315d9da8a70f6d8071c806e0b2b1ee73 in /bin/blackbox_exporter
            COPY file:6e820c2d591d3433d139b66241b74e9b7ffc90c9e120bac49cf97014e16f070a in /etc/blackbox_exporter/config.yml
             EXPOSE 9115
             ENTRYPOINT ["/bin/blackbox_exporter"]
             CMD ["--config.file=/etc/blackbox_exporter/config.yml"]

            運行 blackbox exporter

            docker run -id --name blackbox-exporter -p 9115:9115  prom/blackbox-exporter

            blackbox exporter 配置文件解讀

            官方解釋:https://github.com/prometheus/blackbox_exporter/blob/master/CONFIGURATION.md

            modules:
              http_2xx:
                prober: http
              http_post_2xx:
                prober: http
                http:
                  method: POST
              tcp_connect:
                prober: tcp
              pop3s_banner:
                prober: tcp
                tcp:
                  query_response:
                  - expect: "^+OK"
                  tls: true
                  tls_config:
                    insecure_skip_verify: false
              ssh_banner:
                prober: tcp
                tcp:
                  query_response:
                  - expect: "^SSH-2.0-"
              irc_banner:
                prober: tcp
                tcp:
                  query_response:
                  - send: "NICK prober"
                  - send: "USER prober prober prober :prober"
                  - expect: "PING :([^ ]+)"
                    send: "PONG ${1}"
                  - expect: "^:[^ ]+ 001"
              icmp:
                prober: icmp

            運行 blackbox exporter 時,需要用戶提供探針的配置信息,這些配置信息可能是一些自定義的 HTTP 頭信息,也可能是探測時需要的一些 TSL(秘鑰證書) 配置,也可能是探針本身的驗證行為.在 blackbox exporter 每一個探針配置稱為一個 module,并且以 YAML 配置文件的形式提供給 blackbox exporter.每一個 module 主要包含以下配置內(nèi)容,探針類型(prober),驗證訪問超時時間(timeout),以及當(dāng)前探針的具體配置項:

            # 探針類型: http https tcp dns icmp
            prober: <prober_string>   #必選
            
            # 超時時間:
            [timeout: <duration>] #默認(rèn)單位秒
            
            # 探針的詳細(xì)配置,最多只能配置其中一個
            [ http: <http_probe> ]
            [ tcp: <tcp_probe> ]
            [ dns: <dns_probe> ]
            [ icmp: <icmp_probe> ]

            <http_probe>可配置參數(shù)

            # 此探針接受的狀態(tài)代碼。 默認(rèn)為2xx。
              [ valid_status_codes: <int>, ... | default = 2xx ]
            
            # 此探針接受的 HTTP 版本.
              [ valid_http_versions: <string>, ... ]
            
            #探針將使用的HTTP方法。
              [ method: <string> | default = "GET" ]
            
            # 為探針設(shè)置的HTTP標(biāo)頭。
              headers:
                [ <string>: <string> ... ]
            
            # 探針是否將遵循任何重定向
              [ no_follow_redirects: <boolean> | default = false ]
            
            # 如果存在SSL,則探測失敗。
              [ fail_if_ssl: <boolean> | default = false ]
            
            # 如果不存在SSL,則探測失敗。
              [ fail_if_not_ssl: <boolean> | default = false ]
            
            # 如果響應(yīng)主體與正則表達式匹配,則探測失敗。
              fail_if_body_matches_regexp:
                [ - <regex>, ... ]
            
            # 如果響應(yīng)主體與正則表達式不匹配,則探測失敗。
              fail_if_body_not_matches_regexp:
                [ - <regex>, ... ]
            
            # 如果響應(yīng)頭與正則表達式匹配,則探測失敗。 對于具有多個值的標(biāo)頭,如果*至少一個*匹配,則失敗。
              fail_if_header_matches:
                [ - <http_header_match_spec>, ... ]
            
            # 如果響應(yīng)頭與正則表達式不匹配,則探測失敗。 對于具有多個值的標(biāo)頭,如果* none *不匹配,則失敗。
              fail_if_header_not_matches:
                [ - <http_header_match_spec>, ... ]
            
            # HTTP探針的TLS協(xié)議的配置。
              tls_config:
                [ <tls_config> ]
            
            # 目標(biāo)的HTTP基本身份驗證憑據(jù)。
              basic_auth:
                [ username: <string> ]
                [ password: <secret> ]
            
            # 目標(biāo)的承載令牌。
              [ bearer_token: <secret> ]
            
            # 目標(biāo)的承載令牌文件
              [ bearer_token_file: <filename> ]
            
            # 用于連接到目標(biāo)的HTTP代理服務(wù)器。
              [ proxy_url: <string> ]
            
            # HTTP探針的IP協(xié)議(ip4,ip6)
              [ preferred_ip_protocol: <string> | default = "ip6" ]
              [ ip_protocol_fallback: <boolean> | default = true ]
            
            # 探針中使用的HTTP請求的主體。
              body: [ <string> ]
            
            ###################################################################
            <http_header_match_spec>
                header: <string>,
                regexp: <regex>,
                [ allow_missing: <boolean> | default = false ]

            分別介紹幾種應(yīng)用場景

            ping 檢測

            可以通過 ping(icmp)檢測服務(wù)器的存活,在 prometheus 配置文件中配置使用 ping module:

             icmp:
                prober: icmp

            與 prometheus 集成

             - job_name: 'blackbox-ping'
                metrics_path: /probe
                params:
                  modelus: [icmp]
                static_configs:
                - targets:
                  - 223.5.5.5
                  lables:
                    instance: aliyun
                - targets:
                  - 47.92.229.67
                  lables:
                    instance: zsf
                relabel_configs:
                  - source_labels: [__address__]
                    target_label: __param_target
                  - source_labels: [__param_target]
                    target_label: instance
                  - target_label: __address__
                    replacement: 192.168.111.65:9115

            HTTP

            blackbox config file

            modules:
              http_2xx:
                prober: http
                http:
                  method: GET
              http_post_2xx:
                prober: http
                http:
                  method: POST

            配置好之后運行如指令

            #DNS解析時間,單位 s
            probe_dns_lookup_time_seconds 0.039431355
            #探測從開始到結(jié)束的時間,單位 s,請求這個頁面響應(yīng)時間
            probe_duration_seconds 0.651619323
            
            probe_failed_due_to_regex 0
            
            #HTTP 內(nèi)容響應(yīng)的長度
            probe_http_content_length -1
            #按照階段統(tǒng)計每階段的時間
            probe_http_duration_seconds{phase="connect"} 0.050388884   #連接時間
            probe_http_duration_seconds{phase="processing"} 0.45868667 #處理請求的時間
            probe_http_duration_seconds{phase="resolve"} 0.040037612  #響應(yīng)時間
            probe_http_duration_seconds{phase="tls"} 0.145433254    #校驗證書的時間
            probe_http_duration_seconds{phase="transfer"} 0.000566269 
            #重定向的次數(shù)
            probe_http_redirects 1
            #ssl 指示是否將 SSL 用于最終重定向
            probe_http_ssl 1
            #返回的狀態(tài)碼
            probe_http_status_code 200
            #未壓縮的響應(yīng)主體長度
            probe_http_uncompressed_body_length 40339
            #http 協(xié)議的版本
            probe_http_version 1.1
            #使用的 ip 協(xié)議的版本號
            probe_ip_protocol 4
            
            probe_ssl_earliest_cert_expiry 1.59732e+09
            #是否探測成功
            probe_success 1
            #TLS 的版本號
            probe_tls_version_info{version="TLS 1.2"} 1

            與 prometheus 集成,采用prometheus 的 Relabelinng 能力(服務(wù)發(fā)現(xiàn))

             - job_name: 'blackbox-http'
                metrics_path: /probe
                params:
                  modelue: [http_2xx]
                static_configs:
                - targets:
                  - http://www.zhangshoufu.com
                  - http://www.xuliangwei.com
                relabel_configs:
                  - source_labels: [__address__]
                    target_label: __param_target
                  - source_labels: [__param_target]
                    target_label: instance
                  - target_label: __address__
                    replacement: 192.168.111.65:9115  #blackbox-exporter 所在的機器和端口

            這里針對每一個探針服務(wù)(如http_2xx)定義一個采集任務(wù),并且直接將任務(wù)的采集目標(biāo)定義為我們需要探測的站點。在采集樣本數(shù)據(jù)之前通過relabel_configs對采集任務(wù)進行動態(tài)設(shè)置。

            1, 根據(jù) Target 實例的地址,寫入__param_target標(biāo)簽中,__param_&lt;name&gt;形式的標(biāo)簽表示,在采集任務(wù)時會在請求目標(biāo)地址中添加<name>參數(shù),等同于 params 的設(shè)置
            2, 獲取__param_target的值,并覆寫到instance標(biāo)簽中;
            3, 覆寫Target實例的__address__標(biāo)簽值為BlockBox Exporter實例的訪問地址。

            自定義 HTTP 請求
            HTTP服務(wù)通常會以不同的形式對外展現(xiàn),有些可能就是一些簡單的網(wǎng)頁,而有些則可能是一些基于REST的API服務(wù)。 對于不同類型的HTTP的探測需要管理員能夠?qū)TTP探針的行為進行更多的自定義設(shè)置,包括:HTTP請求方法、HTTP頭信息、請求參數(shù)等。對于某些啟用了安全認(rèn)證的服務(wù)還需要能夠?qū)TTP探測設(shè)置相應(yīng)的Auth支持。對于HTTPS類型的服務(wù)還需要能夠?qū)ψC書進行自定義設(shè)置。
            如下所示,這里通過method定義了探測時使用的請求方法,對于一些需要請求參數(shù)的服務(wù),還可以通過headers定義相關(guān)的請求頭信息,使用body定義請求內(nèi)容:

            http_post_2xx:
                prober: http
                timeout: 5s
                http:
                  method: POST
                  headers:
                    Content-Type: application/json
                  body: '{}'

            如果HTTP服務(wù)啟用了安全認(rèn)證,Blockbox Exporter內(nèi)置了對basic_auth的支持,可以直接設(shè)置相關(guān)的認(rèn)證信息即可:

            http_basic_auth_example:
                prober: http
                timeout: 5s
                http:
                  method: POST
                  headers:
                    Host: "login.example.com"
                  basic_auth:
                    username: "username"
                    password: "mysecret"

            對于使用了Bear Token的服務(wù)也可以通過bearer_token配置項直接指定令牌字符串,或者通過bearer_token_file指定令牌文件。
            對于一些啟用了HTTPS的服務(wù),但是需要自定義證書的服務(wù),可以通過tls_config指定相關(guān)的證書信息:

            http_custom_ca_example:
                prober: http
                http:
                  method: GET
                  tls_config:
                    ca_file: "/certs/my_cert.crt"

            自定義探針行為
            在默認(rèn)情況下HTTP探針只會對HTTP返回狀態(tài)碼進行校驗,如果狀態(tài)碼為2XX(200 <= StatusCode < 300)則表示探測成功,并且探針返回的指標(biāo)probe_success值為1。
            如果用戶需要指定HTTP返回狀態(tài)碼,或者對HTTP版本有特殊要求,如下所示,可以使用valid_http_versions和valid_status_codes進行定義:

            http_2xx_example:
                prober: http
                timeout: 5s
                http:
                  valid_http_versions: ["HTTP/1.1", "HTTP/2"]
                  valid_status_codes: [200,301,302]

            默認(rèn)情況下,Blockbox返回的樣本數(shù)據(jù)中也會包含指標(biāo)probe_http_ssl,用于表明當(dāng)前探針是否使用了SSL:

            # HELP probe_http_ssl Indicates if SSL was used for the final redirect
            # TYPE probe_http_ssl gauge
            probe_http_ssl 0

            而如果用戶對于HTTP服務(wù)是否啟用SSL有強制的標(biāo)準(zhǔn)。則可以使用fail_if_ssl和fail_if_not_ssl進行配置。fail_if_ssl為true時,表示如果站點啟用了SSL則探針失敗,反之成功。fail_if_not_ssl剛好相反。

             http_2xx_example:
                prober: http
                timeout: 5s
                http:
                  valid_status_codes: []
                  method: GET
                  no_follow_redirects: false
                  fail_if_ssl: false
                  fail_if_not_ssl: false

            除了基于HTTP狀態(tài)碼,HTTP協(xié)議版本以及是否啟用SSL作為控制探針探測行為成功與否的標(biāo)準(zhǔn)以外,還可以匹配HTTP服務(wù)的響應(yīng)內(nèi)容。使用fail_if_matches_regexp和fail_if_not_matches_regexp用戶可以定義一組正則表達式,用于驗證HTTP返回內(nèi)容是否符合或者不符合正則表達式的內(nèi)容。

             http_2xx_example:
                prober: http
                timeout: 5s
                http:
                  method: GET
                  fail_if_matches_regexp:
                    - "Could not connect to database"
                  fail_if_not_matches_regexp:
                    - "Download the latest version here"

            具體可以看我上面的配置詳解

            在 grafana 里面展示

            在 grafana web 界面里導(dǎo)入9965這個 dashboards,記得要安裝圖餅
            手工安裝

            wget  https://grafana.com/api/plugins/grafana-piechart-panel/versions/latest/download -O ./grafana-piechart-panel.zip
            下載到插件目錄,然后解壓成目錄名稱為grafana-piechart-panel 目錄,然后重新啟動 grafana

            prometheus 告警規(guī)則

            groups:
            - name: example
              rules:
              - alert: curlHttpStatus
                expr:  probe_http_status_code{job="blackbox-http"}>=400 and probe_success{job="blackbox-http"}==0
                #for: 1m
                labels:
                  docker: number
                annotations:
                  summary: '業(yè)務(wù)報警: 網(wǎng)站不可訪問'
                  description: '{{$labels.instance}} 不可訪問,請及時查看,當(dāng)前狀態(tài)碼為{{$value}}'

            看完上述內(nèi)容,你們對Blackbox Exporter有進一步的了解嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝各位的閱讀!

            另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.jbt999.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

            文章名稱:BlackboxExporter是什么?-創(chuàng)新互聯(lián)
            網(wǎng)頁URL:http://www.jbt999.com/article40/sheho.html

            成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、定制開發(fā)、建站公司關(guān)鍵詞優(yōu)化、網(wǎng)站設(shè)計、外貿(mào)建站

            廣告

            聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

            成都網(wǎng)站建設(shè)

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 18 网站视频 | 久久岛国电影免费观看软件 | 日韩熟妇视频 | 在线看a黄色片……` | 精品国产视频在线观看 |