You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Prometheus中采集K8s部署的WSO2AM 4.1指标?

WSO2 API Manager 4.1 开启Prometheus指标采集(经验证可行)

以下是针对WSO2AM 4.1版本的经验证配置步骤,无需修改老旧的XML配置文件,完全基于官方推荐的deployment.toml配置体系:

1. 修改WSO2AM核心配置文件

在<WSO2AM_HOME>/repository/conf/deployment.toml中添加并修改以下配置块:

# 启用Metrics基础组件
[metrics]
enabled = true
level = "INFO"
# 关闭控制台指标输出(可选,避免日志冗余)
console_reporter_enabled = false
# 保留JMX上报(不影响Prometheus采集)
jmx_reporter_enabled = true

# 启用Prometheus指标暴露
[metrics.prometheus]
enabled = true
# 自定义指标监听端口,确保不与WSO2AM其他端口冲突
port = 9090
# 设为0.0.0.0允许集群内访问,K8s环境必须配置
host = "0.0.0.0"

2. 验证指标是否正常暴露

重启WSO2AM容器后,在K8s集群内通过Pod IP访问指标端点:

curl http://<wso2am-pod-ip>:9090/metrics

如果返回类似wso2_api_request_count{api_name="...",version="...",...} 123格式的Prometheus指标数据,说明配置生效。

3. K8s集群内的端口与服务配置

3.1 更新Deployment的端口暴露

在WSO2AM的Deployment YAML中,给容器添加metrics端口:

spec:
  containers:
    - name: wso2am
      image: wso2/wso2am:4.1.0
      ports:
        # 原有端口(如9443、8280等)保留
        - containerPort: 9443
          name: https
        - containerPort: 8280
          name: http
        # 添加metrics端口
        - containerPort: 9090
          name: metrics
          protocol: TCP

3.2 配置Service暴露Metrics端口

创建或更新Service,将metrics端口暴露给集群内的Prometheus:

apiVersion: v1
kind: Service
metadata:
  name: wso2am-service
spec:
  type: ClusterIP
  selector:
    app: wso2am
  ports:
    - name: http
      port: 8280
      targetPort: 8280
    - name: https
      port: 9443
      targetPort: 9443
    - name: metrics
      port: 9090
      targetPort: 9090

4. 配置Prometheus抓取任务

在Prometheus的Scrape配置中添加针对WSO2AM的任务:

scrape_configs:
  - job_name: 'wso2am'
    # 自定义抓取间隔
    scrape_interval: 15s
    static_configs:
      # 替换为你的WSO2AM Service名称
      - targets: ['wso2am-service:9090']

常见问题排查

  • 不要修改metrics.xml:4.1版本已完全使用deployment.toml作为配置入口,XML配置会被Toml覆盖,修改无效。
  • 端口冲突检查:查看Pod日志,如果出现Address already in use错误,更换metrics.prometheus.port为未占用端口。
  • 网络访问问题:确保K8s网络策略允许Prometheus所在Namespace访问WSO2AM的9090端口。

内容的提问来源于stack exchange,提问作者Misieq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 01:55:38