1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      網(wǎng)絡探測:BlackboxExporter

      系統(tǒng)運維 網(wǎng)絡探測:Blackbox Exporter 什么是 blackbox exporter?

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

      讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:域名申請虛擬主機、營銷軟件、網(wǎng)站建設、棲霞網(wǎng)站維護、網(wǎng)站推廣。以 docker 方式運行 blackbox exporter

      拉取鏡像

      docker pull prom/blackbox-exporter

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

      $ 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 
      COPY dir:b1c1c3c551755544b818d03ad9136b137ca12c48393ba5cdd58d7f845647e042 in /
       LABEL maintainer=The Prometheus Authors 
       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),以及當前探針的具體配置項:

      # 探針類型: http https tcp dns icmp
      prober:    #必選
      
      # 超時時間:
      [timeout: ] #默認單位秒
      
      # 探針的詳細配置,最多只能配置其中一個
      [ http:  ]
      [ tcp:  ]
      [ dns:  ]
      [ icmp:  ]
      可配置參數(shù)
      # 此探針接受的狀態(tài)代碼。 默認為2xx。
        [ valid_status_codes: , ... | default = 2xx ]
      
      # 此探針接受的 HTTP 版本.
        [ valid_http_versions: , ... ]
      
      #探針將使用的HTTP方法。
        [ method:  | default = GET ]
      
      # 為探針設置的HTTP標頭。
        headers:
          [ :  ... ]
      
      # 探針是否將遵循任何重定向
        [ no_follow_redirects:  | default = false ]
      
      # 如果存在SSL,則探測失敗。
        [ fail_if_ssl:  | default = false ]
      
      # 如果不存在SSL,則探測失敗。
        [ fail_if_not_ssl:  | default = false ]
      
      # 如果響應主體與正則表達式匹配,則探測失敗。
        fail_if_body_matches_regexp:
          [ - , ... ]
      
      # 如果響應主體與正則表達式不匹配,則探測失敗。
        fail_if_body_not_matches_regexp:
          [ - , ... ]
      
      # 如果響應頭與正則表達式匹配,則探測失敗。 對于具有多個值的標頭,如果*至少一個*匹配,則失敗。
        fail_if_header_matches:
          [ - , ... ]
      
      # 如果響應頭與正則表達式不匹配,則探測失敗。 對于具有多個值的標頭,如果* none *不匹配,則失敗。
        fail_if_header_not_matches:
          [ - , ... ]
      
      # HTTP探針的TLS協(xié)議的配置。
        tls_config:
          [  ]
      
      # 目標的HTTP基本身份驗證憑據(jù)。
        basic_auth:
          [ username:  ]
          [ password:  ]
      
      # 目標的承載令牌。
        [ bearer_token:  ]
      
      # 目標的承載令牌文件
        [ bearer_token_file:  ]
      
      # 用于連接到目標的HTTP代理服務器。
        [ proxy_url:  ]
      
      # HTTP探針的IP協(xié)議(ip4,ip6)
        [ preferred_ip_protocol:  | default = ip6 ]
        [ ip_protocol_fallback:  | default = true ]
      
      # 探針中使用的HTTP請求的主體。
        body: [  ]
      
      ###################################################################
      
          header: ,
          regexp: ,
          [ allow_missing:  | default = false ]
      分別介紹幾種應用場景 ping 檢測

      可以通過 ping(icmp)檢測服務器的存活,在 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
      #探測從開始到結束的時間,單位 s,請求這個頁面響應時間
      probe_duration_seconds 0.651619323
      
      probe_failed_due_to_regex 0
      
      #HTTP 內(nèi)容響應的長度
      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  #響應時間
      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
      #未壓縮的響應主體長度
      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 能力(服務發(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 所在的機器和端口

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

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

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

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

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

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

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

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

      自定義探針行為
      在默認情況下HTTP探針只會對HTTP返回狀態(tài)碼進行校驗,如果狀態(tài)碼為2XX(200 <= StatusCode < 300)則表示探測成功,并且探針返回的指標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]

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

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

      而如果用戶對于HTTP服務是否啟用SSL有強制的標準。則可以使用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作為控制探針探測行為成功與否的標準以外,還可以匹配HTTP服務的響應內(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 界面里導入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ǎng)站不可訪問\'
            description: \'{{$labels.instance}} 不可訪問,請及時查看,當前狀態(tài)碼為{{$value}}\'

      參考:

      blackbox-configs --> https://github.com/prometheus/blackbox_exporter/blob/master/CONFIGURATION.md
      prometheus-configs --> https://prometheus.io/docs/prometheus/latest/configuration/configuration/
      https://yunlzheng.gitbook.io/prometheus-book/part-ii-prometheus-jin-jie/exporter/commonly-eporter-usage/install_blackbox_exporter
      https://www.li-rui.top/2018/11/23/monitor/blackbox_exporter%E4%BD%BF%E7%94%A8/

      新聞名稱:網(wǎng)絡探測:BlackboxExporter
      文章源于:http://www.ef60e0e.cn/article/cgedod.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        平潭县| 获嘉县| 吉安县| 瓦房店市| 德钦县| 瑞昌市| 西贡区| 阿拉善左旗| 东莞市| 舞阳县| 正安县| 甘肃省| 兴义市| 抚州市| 油尖旺区| 武胜县| 文化| 廉江市| 开化县| 望城县| 苍溪县| 阿拉尔市| 定兴县| 永和县| 阿合奇县| 临泉县| 克拉玛依市| 犍为县| 永城市| 长寿区| 南部县| 新建县| 铜梁县| 安化县| 巴中市| 罗田县| 兰溪市| 周至县| 九台市| 金溪县| 安西县|