Sentinel provides real-time metrics, including resource count, response time, concurrency, etc. You can view these metrics on Sentinel-Dashboard, but you can also use the metrics API to retrieve data.

To activate the transport API server, add the following dependency to your pom.xml:

  1. <dependency>
  2. <groupId>com.alibaba.csp</groupId>
  3. <artifactId>sentinel-transport-simple-http</artifactId>
  4. <version>x.y.z</version>
  5. </dependency>

The default port of the HTTP API server is 8719, but you could modify this via the csp.sentinel.api.port property item.

Metrics of Resources

Get real-time metrics of all resources

Note: the metric is single-instance level.

API: GET /clusterNode

  1. [
  2. {"avgRt":0.0, //avg response time per second
  3. "blockRequest":0, //block count per minute
  4. "blockedQps":0.0, //block count per second
  5. "curThreadNum":0, //current concurrency
  6. "passQps":1.0, // success exit count per second
  7. "passReqQps":1.0, //pass count per second
  8. "resourceName":"/registry/machine", resource name
  9. "timeStamp":1529905824134, //time stamp
  10. "totalQps":1.0, // total request count per minute
  11. "totalRequest":193},
  12. ....
  13. ]

Get real-time metric by resource name

Note: the metric is single-instance level.

Run command curl http://localhost:8719/cnode?id=xxxx to query a specified resource name. The parameter id corresponds to the resource name. Fuzzy query is supported.

Sample result:

  1. idx id thread pass blocked success total aRt 1m-pass 1m-block 1m-all exeption
  2. 6 /app/aliswitch2/machines.json 0 0 0 0 0 0 0 0 0 0
  3. 7 /app/sentinel-admin/machines.json 0 1 0 1 1 6 0 0 0 0
  4. 8 /identity/machine.json 0 0 0 0 0 0 0 0 0 0
  5. 9 /registry/machine 0 2 0 2 2 1 192 0 192 0
  6. 10 /app/views/machine.html 0 1 0 1 1 2 0 0 0 0

Display origin metrics of the resource

Command: curl http://localhost:8719/origin?id=xxxx

  1. id: nodeA
  2. idx origin threadNum passedQps blockedQps totalQps aRt 1m-passed 1m-blocked 1m-total
  3. 1 caller1 0 0 0 0 0 0 0 0
  4. 2 caller2 0 0 0 0 0 0 0 0

Among which, origin is defined by calling the following method:

  1. Context.enter(resourceNameorigin)

Invocation Chain

API: GET /tree

  1. EntranceNode: machine-root(t:0 pq:1 bq:0 tq:1 rt:0 prq:1 1mp:0 1mb:0 1mt:0)
  2. -EntranceNode1: Entrance1(t:0 pq:1 bq:0 tq:1 rt:0 prq:1 1mp:0 1mb:0 1mt:0)
  3. --nodeA(t:0 pq:1 bq:0 tq:1 rt:0 prq:1 1mp:0 1mb:0 1mt:0)
  4. -EntranceNode2: Entrance1(t:0 pq:1 bq:0 tq:1 rt:0 prq:1 1mp:0 1mb:0 1mt:0)
  5. --nodeA(t:0 pq:1 bq:0 tq:1 rt:0 prq:1 1mp:0 1mb:0 1mt:0)
  6. t:threadNum pq:passQps bq:blockedQps tq:totalQps rt:averageRt prq: passRequestQps 1mp:1m-passed 1mb:1m-blocked 1mt:1m-total

History Resource Metrics

Metric log

Resource metrics log is generated in the directory: ${home}\logs\csp\${appName}-${pid}-metrics.log.${date}.xx. For example, log file name would be: app-3518-metrics.log.2018-06-22.1

  1. 1529573107000|2018-06-21 17:25:07|sayHello(java.lang.String,long)|10|3601|10|0|2
indexexampledescription
11529573107000time stamp
22018-06-21 17:25:07date
3sayHello(java.lang.String,long)resource name
410the count of pass resource per second
53601the count of blocked resource per second
610the count of exit resource per second
70the count of exception per second
82the avg response time

Block log

Also, the block log will be generated in the dir ${home}\logs\csp\sentinel-block.log. If no block happens, the log will not be generated.

  1. 2014-06-20 16:35:10|1|sayHello(java.lang.String,long),FlowException,default,origin|61,0
  2. 2014-06-20 16:35:11|1|sayHello(java.lang.String,long),FlowException,default,origin|1,0
IndexExampleDescription
12014-06-20 16:35:10timestamp
21the resource index
3sayHello(java.lang.String,long)resource name
4XXXExceptionFlowException is blocked by flow rules, DegradeException is blocked by degradation rules,SystemExceptionis blocked by system rules
5defaultthe limit app defined in effective rule
6originthe origin of the blocked resource. could be empty
761,061 the blocked count this second. and 0 can be ignored

Metric log fetching API

  1. curl http://localhost:8719/metric?startTime=XXXX&endTime=XXXX

History Resource Metrics

  1. 1529998904000|2018-06-26 15:41:44|abc|100|0|0|0|0
  2. 1529998905000|2018-06-26 15:41:45|abc|4|5579|104|0|728
  3. 1529998906000|2018-06-26 15:41:46|abc|0|15698|0|0|0
  4. 1529998907000|2018-06-26 15:41:47|abc|0|19262|0|0|0
  5. 1529998908000|2018-06-26 15:41:48|abc|0|19502|0|0|0
  6. 1529998909000|2018-06-26 15:41:49|abc|0|18386|0|0|0
  7. 1529998910000|2018-06-26 15:41:50|abc|0|19189|0|0|0
  8. 1529998911000|2018-06-26 15:41:51|abc|0|16543|0|0|0
  9. 1529998912000|2018-06-26 15:41:52|abc|0|18471|0|0|0
  10. 1529998913000|2018-06-26 15:41:53|abc|0|19405|0|0|0