Prometheus Metrics Configuration Guide

Seata supports enabling Metrics data collection in TC and outputting it to the Prometheus monitoring system.

Configure Metrics in TC

Step 1: Open the Metrics configuration in TC

Seata Server already includes the metrics (seata-metrics-all) dependency, but it is disabled by default. You need to enable the collection configuration for metrics.

  1. seata:
  2. metrics:
  3. enabled: true
  4. registry-type: compact
  5. exporter-list: prometheus
  6. exporter-prometheus-port: 9898

Enter http://tc-server-ip:9898/metrics to obtain the latest Metrics data, for example:

  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

Obtaining similar data as above proves that the metric is successfully enabled.

Note:

  1. If certain transaction statuses, such as rollback, do not occur, the corresponding metric indicators will not exist (output).

Step 2: Modify the Prometheus configuration file and start Prometheus

Open the Prometheus configuration file prometheus.yml and add a scrape configuration to fetch Seata TC’s Metrics data:

  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'.
  1. static_configs:
  2. - targets: ['localhost:9090']
  3. - job_name: 'seata'
  4. # metrics_path defaults to '/metrics'
  5. # scheme defaults to 'http'.
  6. static_configs:
  7. - targets: ['tc-server-ip:9898']

Step 3: View Seata TC Metrics in Prometheus UI or Grafana

Open Prometheus UI http://localhost:9090/graph in a browser, select seata_transaction, and click on “Execute” to retrieve the latest data:

tc-prometheus

It is recommended to use Grafana in conjunction with Prometheus for better query results:

tc-grafana

Note: This configuration sets Prometheus as the data source for Grafana, so the data is the same, but Grafana provides a better display effect.