Prometheus apache_exporter 監控配置


Prometheus apache_exporter 監控配置

在安裝apache_exporter之前,首先得保證Apache有mod_status這個模塊

#修改Apache的配置文件:httpd-info.conf
vim /usr/local/apache/conf/extra/httpd-info.conf
<Location /server-status>
  SetHandler server-status
  Order deny,allow
  allow from all
  AuthType Basic
  AuthName 'Apache Server Status'
  AuthUserFile '/usr/local/apache/conf/.htpasswd'
  Require valid-user
</Location>

<Location /server-info>
  SetHandler server-status
  Order deny,allow
  allow from all
  AuthType Basic
  AuthName 'Apache Server Status'
  AuthUserFile '/usr/local/apache/conf/.htpasswd'
  Require valid-user
</Location>
  • 由於Apache服務信息屬於敏感信息,需配置用戶身份證

    htpasswd -c -m /usr/local/apache/conf/.htpasswd hdkj

  • 接下來正式安裝apache_exporter

  • 創建一個臨時目錄

  • $ mkdir /tmp/go

  • 設置環境變量

  • $ export GOPATH=/tmp/go

  • 進入臨時目錄使用go命令從遠程倉庫獲取apache_exporter

  • $ cd /tmp/go

  • $ go get -u github.com/Lusitaniae/apache_exporter

  • 查看一下下載好的apache_exporter

  • ll src/github.com/Lusitaniae/apache_exporter/

  • 使用make命令編譯源代碼

  • 編譯完成之后,將生成的apache_exporter拷貝至安裝目錄

配置啟動服務:

  • vim /usr/lib/systemd/system/apache_exporter.service

    [Unit]
    Description=Prometheus apache exporter
    Documentation=https://github.com/Lusitaniae/apache_exporter
    After=network.target

    [Service]

    Type=simple

    ExecStart=/usr/local/apache_exporter/apache_exporter --scrape_uri=http://hdkj:HDkj123456@localhost/server-status?auto
    Restart=on-failure

    [Install]
    WantedBy=multi-user.target

     

  • 啟動一下服務

  • systemctl start apache_exporter

  • ss -tnl | grep 9117 #如果端口9117存在,說明服務啟動成功;

在Promethus配置文件中加入apache_exporter

job_name: 'apache_exporter'
metrics_path: "/metrics"
static_configs:

- targets: ['192.168.8.133:9117']
labels:
  instance: '192.168.8.133:9117'

- targets: ['192.168.8.134:9117']
labels:
  instance: '192.168.8.134:9117'

 

配置監控規則:

groups:

- name: apache_exporter_alerts
rules:
   - alert: ApacheWorkerStatus
    expr: apache_workers{state="busy"} > 320
     for: 30s
    labels:
      severity: warning
    annotations:
      summary: "ApacheWorkerStatus (instance {{ $labels.instance }})"
      description: "Apache worker status is busy more than 80%\n VALUE = {{ $value }}\n LABELS: {{ $labels }}"

   - alert: ApacheConnectionsStatus
    expr: apache_connections{state="total"} > 1000
     for: 30s
    labels:
      severity: warning
    annotations:
      summary: "Apache Connection Statuses (instance {{ $labels.instance }})"
      description: "Apache Connections Is Too many \n VALUE = {{ $value }}\n LABELS: {{ $labels }}"

   - alert: Apache Service
    expr: apache_up == 0
     for: 30s
    labels:
      severity: error
    annotations:
      summary: "ApacheServiceStatuses (instance {{ $labels.instance }})"
      description: "Apache Service Is Not Work;Please Connect Ops Group Quick Deal With \n VALUE = {{ $value }}\n LABELS: {{ $labels }}"

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM