Global Dynamic Metrics
Global dynamic metrics can dynamically aggregate the data you want by writing metrics SQL, such as statistics on the percentage of current gateway cache hits, or the distribution of request status codes.
Here we provide a practical example of viewing the distribution of status codes.
After clicking the Save button, wait a few minutes for the data to show on the page.
Alternatively, we can also switch to a bar chart or pie chart.
If you want to count the city distribution according to the customer IP, you can write the following metric SQL.
select client_city, count(*) as cnt from reqs group by client_city order by cnt desc limit 50
If you want to know which resource is hottest, you can write the following metric SQL.
select uri, sum(total_size) as size from reqs group by uri order by size desc limit 10
Yon can also add a where clause to limit the resource you are really care about.
select uri, sum(total_size) as size from reqs where uri like /\bopenresty-\d+(?:\.\d+)+(?:rc\d+)?\.tar\.gz$/ group by uri order by size desc limit 10
limit Nhas a significant impact on performance, please ensure that
Nis less than 15.
More metrics SQL details can be found in this documentation. Metrics SQL
Standard Metric Aggregates
We also provide standard metric aggregates. If no metric has been created, we can click on
Add standard metric aggregates at once button to add these standard metric aggregates quickly.
Here are the introduction of these standard metric aggregates:
Status Code Count
With this metric we can see the distribution of status codes.
select status, count(*) from reqs group by status;
Upstream & Downstream Total Bytes
With this metric we can see the inbound and outbound traffic.
select sum(upstream_byte_total) as upstream_bytes_total, sum(total_size) as downstream_bytes_total from reqs;
QPS & Connections
With this metric we can see the total QPS and the number of connections in different states.
select count(*) as qps, avg(writing_conns), avg(reading_conns), avg(waiting_conns), avg(active_conns) from http;
Cache Bytes of Hit or Miss
With this metric we can see the distribution of the different cache states.
select sum(total_size) as bytes_total, upstream_cache_status, count(*) from reqs where upstream_cache_status != '' group by upstream_cache_status;
Application Dynamic Metrics
Application dynamic metrics are similar to global dynamic metrics, but will only count requests that currently belong to the application.