运维指南

Metrics配置指南

Seata支持在TC、TM和RM三个角色开启Metrics数据采集并输出到Prometheus监控系统中。

在TC中配置开启Metrics

步骤一:在Seata Server中增加Metrics的依赖并重新编译Server

打开Seata Server源代码的pom,添加Metrics依赖:

  1. <dependency>
  2. <groupId>${project.groupId}</groupId>
  3. <artifactId>seata-metrics-prometheus</artifactId>
  4. </dependency>

重新编译Server,启动,输入http://tc-server-ip:9898/metrics,即可获得最新的Metrics数据,例如:

  1. # HELP seata seata
  2. # TYPE seata untyped
  3. seata_transaction{meter="counter",role="tc",status="committed",} 1358.0 1551946035372
  4. seata_transaction{meter="counter",role="tc",status="active",} 0.0 1551946035372
  5. seata_transaction{meter="summary",role="tc",statistic="count",status="committed",} 6.0 1551946035372
  6. seata_transaction{meter="summary",role="tc",statistic="total",status="committed",} 6.0 1551946035372
  7. seata_transaction{meter="summary",role="tc",statistic="tps",status="committed",} 1.6163793103448276 1551946035372
  8. seata_transaction{meter="timer",role="tc",statistic="count",status="committed",} 6.0 1551946035372
  9. seata_transaction{meter="timer",role="tc",statistic="total",status="committed",} 910.0 1551946035372
  10. seata_transaction{meter="timer",role="tc",statistic="max",status="committed",} 164.0 1551946035372
  11. seata_transaction{meter="timer",role="tc",statistic="average",status="committed",} 151.66666666666666 1551946035372

提示:

  1. 目前我们使用的Prometheus数据发布端口固定为9898,未来会将其修改为可配置项,请确保此端口不会被占用;
  2. 如果某些Transaction状态没有发生,例如rollback,那么对应的Metrics指标也不会存在(输出)。

步骤二:修改Prometheus配置文件并启动Prometheus

打开Prometheus的配置文件prometheus.yml,在scrape_configs中增加一项抓取Seata TC的Metrics数据:

  1. scrape_configs:
  2. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  3. - job_name: 'prometheus'
  4. # metrics_path defaults to '/metrics'
  5. # scheme defaults to 'http'.
  6. static_configs:
  7. - targets: ['localhost:9090']
  8. - job_name: 'seata'
  9. # metrics_path defaults to '/metrics'
  10. # scheme defaults to 'http'.
  11. static_configs:
  12. - targets: ['tc-server-ip:9898']

步骤三:在Prometheus UI或Grafana中查看Seata TC的Metrics

在浏览器中打开Prometheus UIhttp://localhost:9090/graph,选择seata_transaction,点击查询,即可获取到最新数据:

tc-prometheus

推荐在Prometheus中结合配置Grafana获得更好的查询效果:

tc-grafana

提示:此配置是将Prometheus作为Grafana的数据源,因此数据完全相同,只是使用Grafana显示效果更佳。