apisix配置prometheus

1. 配置 Prometheus

  1. Prometheus 配置文件

    • 首先,确保你已经正确配置了 Prometheus 的 prometheus.yml 文件。在这个文件中,你需要定义 Prometheus 要监控的目标(targets),即你的应用程序或服务。

    • 示例配置文件的一部分如下:

      global:
        scrape_interval: 15s
        evaluation_interval: 15s
      
      scrape_configs:
        - job_name: 'apisix'
          static_configs:
            - targets: ['localhost:9091']
      
      • scrape_interval 定义了 Prometheus 抓取指标数据的频率。

      • evaluation_interval 定义了 Prometheus 执行规则和评估表达式的频率。

      • job_name 是你为你的应用程序或服务定义的一个名称。

      • targets 是你的应用程序的地址和端口。

2. 配置 Apisix

  • 配置文件引入 prometheus 插件

    plugin_attr:
      prometheus:
        export_addr:
          ip: "0.0.0.0"
          port: 9091
    
  • 引入全局插件

    curl http://127.0.0.1:9180/apisix/admin/global_rules/1 -X PUT \
      -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
      -d '{
            "plugins": {
                "prometheus": {
                    "prefer_name": false
                }
            }
        }'
    
  • 重启 Apisix, 查看服务是否配置成功

    curl -i http://127.0.0.1:9091/apisix/prometheus/metrics
    

    输入如下表示成功:

    HTTP/1.1 200 OK
    Server: openresty
    Date: Wed, 23 Mar 2022 13:22:58 GMT
    Content-Type: text/plain; charset=utf-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    
    # HELP apisix_etcd_modify_indexes Etcd modify index for APISIX keys
    # TYPE apisix_etcd_modify_indexes gauge
    apisix_etcd_modify_indexes{key="consumers"} 0
    ...
    # TYPE apisix_node_info gauge
    apisix_node_info{hostname="APISIX"} 1
    

3 参数详解:

# HELP apisix_bandwidth Total bandwidth in bytes consumed per service in APISIX
# apisix中每个consumer消耗的总带宽 counter
apisix_bandwidth{type="egress",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169"} 616
apisix_bandwidth{type="ingress",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169"} 168
# HELP apisix_etcd_modify_indexes Etcd modify index for APISIX keys
# APISIX键的索引 gauge
apisix_etcd_modify_indexes{key="consumers"} 1601
apisix_etcd_modify_indexes{key="global_rules"} 2060
apisix_etcd_modify_indexes{key="max_modify_index"} 2060
apisix_etcd_modify_indexes{key="prev_index"} 2115
apisix_etcd_modify_indexes{key="protos"} 2029
apisix_etcd_modify_indexes{key="routes"} 1862
apisix_etcd_modify_indexes{key="services"} 208
apisix_etcd_modify_indexes{key="ssls"} 0
apisix_etcd_modify_indexes{key="stream_routes"} 0
apisix_etcd_modify_indexes{key="upstreams"} 1856
apisix_etcd_modify_indexes{key="x_etcd_index"} 2116
# HELP apisix_etcd_reachable Config server etcd reachable from APISIX, 0 is unreachable
# etcd 服务是否可达,0不可达 gauge
apisix_etcd_reachable 1
# HELP apisix_http_latency HTTP request latency in milliseconds per service in APISIX
# 在APISIX中,每个服务的HTTP请求延迟,以毫秒为单位 histogram
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="1"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="2"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="5"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="10"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="20"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="50"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="100"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="200"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="500"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="1000"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="2000"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="5000"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="10000"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="30000"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="60000"} 2
apisix_http_latency_bucket{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="+Inf"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="10"} 1
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="20"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="50"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="100"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="200"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="500"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="1000"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="2000"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="5000"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="10000"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="30000"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="60000"} 2
apisix_http_latency_bucket{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="+Inf"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="10"} 1
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="20"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="50"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="100"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="200"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="500"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="1000"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="2000"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="5000"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="10000"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="30000"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="60000"} 2
apisix_http_latency_bucket{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169",le="+Inf"} 2
apisix_http_latency_count{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169"} 2
apisix_http_latency_count{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169"} 2
apisix_http_latency_count{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169"} 2
apisix_http_latency_sum{type="apisix",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169"} 0
apisix_http_latency_sum{type="request",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169"} 20.999670028687
apisix_http_latency_sum{type="upstream",route="00000000000000000408",service="",consumer="",node="10.xx.xx.169"} 22
# HELP apisix_http_requests_total The total number of client requests since APISIX started
# 自APISIX启动以来的客户端请求总数 gauge
apisix_http_requests_total 3
# HELP apisix_http_status HTTP status codes per service in APISIX
# HELP apisix_http_status APISIX中每个服务的HTTP状态码 counter
apisix_http_status{code="200",route="00000000000000000408",matched_uri="/demo/*",matched_host="",service="",consumer="",node="10.xx.xx.169"} 2
# HELP apisix_nginx_http_current_connections Number of HTTP connections
# HTTP连接数 gauge
apisix_nginx_http_current_connections{state="accepted"} 3
apisix_nginx_http_current_connections{state="active"} 1
apisix_nginx_http_current_connections{state="handled"} 3
apisix_nginx_http_current_connections{state="reading"} 0
apisix_nginx_http_current_connections{state="waiting"} 0
apisix_nginx_http_current_connections{state="writing"} 1
# HELP apisix_nginx_metric_errors_total Number of nginx-lua-prometheus errors
# apisix_nginx_metric 错误总数 counter
apisix_nginx_metric_errors_total 0
# HELP apisix_node_info Info of APISIX node
# apisix 节点数量 gauge
apisix_node_info{hostname="4783dd3ab504"} 1
# HELP apisix_shared_dict_capacity_bytes The capacity of each nginx shared DICT since APISIX start
# 自APISIX启动以来,每个nginx共享DICT的容量 gauge
apisix_shared_dict_capacity_bytes{name="access-tokens"} 1048576
apisix_shared_dict_capacity_bytes{name="balancer-ewma"} 10485760
apisix_shared_dict_capacity_bytes{name="balancer-ewma-last-touched-at"} 10485760
apisix_shared_dict_capacity_bytes{name="balancer-ewma-locks"} 10485760
apisix_shared_dict_capacity_bytes{name="cas_sessions"} 10485760
apisix_shared_dict_capacity_bytes{name="discovery"} 1048576
apisix_shared_dict_capacity_bytes{name="etcd-cluster-health-check"} 10485760
apisix_shared_dict_capacity_bytes{name="ext-plugin"} 1048576
apisix_shared_dict_capacity_bytes{name="internal-status"} 10485760
apisix_shared_dict_capacity_bytes{name="introspection"} 10485760
apisix_shared_dict_capacity_bytes{name="jwks"} 1048576
apisix_shared_dict_capacity_bytes{name="lrucache-lock"} 10485760
apisix_shared_dict_capacity_bytes{name="memory_cache"} 52428800
apisix_shared_dict_capacity_bytes{name="plugin-api-breaker"} 10485760
apisix_shared_dict_capacity_bytes{name="plugin-limit-conn"} 10485760
apisix_shared_dict_capacity_bytes{name="plugin-limit-count"} 10485760
apisix_shared_dict_capacity_bytes{name="plugin-limit-count-redis-cluster-slot-lock"} 1048576
apisix_shared_dict_capacity_bytes{name="plugin-limit-count-reset-header"} 10485760
apisix_shared_dict_capacity_bytes{name="plugin-limit-req"} 10485760
apisix_shared_dict_capacity_bytes{name="prometheus-metrics"} 10485760
apisix_shared_dict_capacity_bytes{name="upstream-healthcheck"} 10485760
apisix_shared_dict_capacity_bytes{name="worker-events"} 10485760
# HELP apisix_shared_dict_free_space_bytes The free space of each nginx shared DICT since APISIX start
# 自APISIX启动以来,每个nginx共享DICT的空闲空间 gauge
apisix_shared_dict_free_space_bytes{name="access-tokens"} 1032192
apisix_shared_dict_free_space_bytes{name="balancer-ewma"} 10412032
apisix_shared_dict_free_space_bytes{name="balancer-ewma-last-touched-at"} 10412032
apisix_shared_dict_free_space_bytes{name="balancer-ewma-locks"} 10412032
apisix_shared_dict_free_space_bytes{name="cas_sessions"} 10412032
apisix_shared_dict_free_space_bytes{name="discovery"} 1032192
apisix_shared_dict_free_space_bytes{name="etcd-cluster-health-check"} 10412032
apisix_shared_dict_free_space_bytes{name="ext-plugin"} 1032192
apisix_shared_dict_free_space_bytes{name="internal-status"} 10407936
apisix_shared_dict_free_space_bytes{name="introspection"} 10412032
apisix_shared_dict_free_space_bytes{name="jwks"} 1032192
apisix_shared_dict_free_space_bytes{name="lrucache-lock"} 10412032
apisix_shared_dict_free_space_bytes{name="memory_cache"} 52113408
apisix_shared_dict_free_space_bytes{name="plugin-api-breaker"} 10412032
apisix_shared_dict_free_space_bytes{name="plugin-limit-conn"} 10412032
apisix_shared_dict_free_space_bytes{name="plugin-limit-count"} 10412032
apisix_shared_dict_free_space_bytes{name="plugin-limit-count-redis-cluster-slot-lock"} 1036288
apisix_shared_dict_free_space_bytes{name="plugin-limit-count-reset-header"} 10412032
apisix_shared_dict_free_space_bytes{name="plugin-limit-req"} 10412032
apisix_shared_dict_free_space_bytes{name="prometheus-metrics"} 10379264
apisix_shared_dict_free_space_bytes{name="upstream-healthcheck"} 10412032
apisix_shared_dict_free_space_bytes{name="worker-events"} 10407936

4. Apisix 参数表格

需求名称参数备注
路由总数apisix_etcd_modify_indexes{key=“routes”}
服务总数apisix_etcd_modify_indexes{key=“services”}
今日请求总数apisix_http_requests_total
节点数量apisix_node_info{hostname=“4783dd3ab504”}
路由请求占比apisix_http_latency_bucket{type=“apisix”,
route=“00000000000000000408”,
service=“”,consumer=“”,node=“10.xx.xx.169”,le=“1”}
请求状态码apisix_http_status{code=“200”,
route=“00000000000000000408”,
matched_uri=“/demo/*”,matched_host=“”,
service=“”,consumer=“”,node=“10.xx.xx.169”}
响应时间apisix_http_latency_count,apisix_http_latency_sum

  • 23
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值