goaccess 經過jsonpath 轉換爲prometheus metrics

goaccess 是一個不錯的日誌分析工具,包含了json 數據同時支持基於websocket 的實時數據處理,固然咱們能夠經過jsonpath
的exporter 轉換爲支持promethues 的metrics,仍是很方便的html

環境準備

  • docker-compose 文件
version: "3"
services:
  metrics:
   image: sunbird/prometheus-jsonpath-exporter
   volumes: 
   - "./conf/config.yml:/etc/prometheus-jsonpath-exporter/config.yml"
   ports:
   - "9158:9158"
   command: /etc/prometheus-jsonpath-exporter/config.yml
  g:
    image: grafana/grafana
    ports:
    - "3000:3000"
  p:
    image: prom/prometheus
    volumes:
    - "./conf/prometheus.yml:/etc/prometheus/prometheus.yml"
    ports:
    - "9090:9090" 
  log:
    image: dalongrong/goaccess-geo
    ports:
    - "7890:7890"
    volumes: 
    - "./data:/srv/data"
    - "./logs:/srv/logs"
    - "./html:/srv/report"
    - "./geoip/:/src/geoip/"
  web:
    image: nginx
    ports: 
    - "8080:80"
    volumes: 
    - "./html/:/usr/share/nginx/html/"
  • prometheus 配置

    conf/prometheus.ymlnginx

scrape_configs:
  - job_name: go_access
    metrics_path: /
    static_configs:
      - targets: ['metrics:9158']
  • jsonpath exporter 配置

    conf/config.ymlgit

exporter_port: 9158 # Port on which prometheus can call this exporter to get metrics
log_level: info
json_data_url: http://web/app.json # Url to get json data used for fetching metric values
metric_name_prefix: go_access # All metric names will be prefixed with this value
metrics:
- name: total_request # Final metric name will be go_access_total_request
  description: Number of total request
  path: $.general.total_requests
  • goaccess 配置

    主要是添加支持json 的處理data/goaccess.confgithub

geoip-database /src/geoip/GeoLiteCity.dat
log-format COMBINED
real-time-html true
log-file /srv/logs/access.log
output /srv/report/index.html
output /srv/report/app.json
  • 說明
    metrics 很簡單,就是經過jsonpath 獲取請求的總數

運行&&測試

  • 啓動
docker-compose up -d
  • 效果
    goaccess

    jsonpath exporter metrics

    prometheus

說明

這個只是一種簡單的處理實際上咱們能夠基於其餘的nginx 或者logger exporter 進行prometheus metrics 的處理,對於須要進行離線日誌請求分析的,
也是一種不錯的方案,須要的操做比較少,可是能夠幫助咱們分析好多有用的信息web

參考資料

https://github.com/project-sunbird/prometheus-jsonpath-exporter
https://github.com/rongfengliang/goaccess-geoip-docker-compose-demo
https://goaccess.io/
https://goessner.net/articles/JsonPath/index.html#e2docker

相關文章
相關標籤/搜索