You can call this operation to query the metrics of Application Monitoring.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Description

You can call QueryMetric to query the metrics of Application Monitoring and Browser Monitoring. This topic describes how to query the metrics of Application Monitoring.

Operation Request Response
QueryMetric QueryMetricRequest QueryMetricResponse

Request parameters

Request parameters include common parameters and operation-specific parameters.

Common request parameters

For more information about common request parameters, see Common parameters.

Operation-specific parameters

Alibaba Cloud encapsulates all request parameters in a request, and returns a response.

Parameter Type Setting method Description Required Remarks
StartTime Long setStartTime The beginning of the time range to query. Yes N/A
EndTime Long setEndTime The end of the time range to query. Yes N/A
Metric String setMetric The metric to be queried. Yes N/A
Measures List[String] setMesures The measurement data of the metric. Yes N/A
Dimensions List[String] setDimensionss The dimension by which the data is queried. No N/A
Filters List[Filter] setFilters The filtering condition for the query. Yes N/A
IntervalInSec Integer setIntervalInSec The time interval between the data shards to be queried. Unit: millisecond. No N/A
OrderBy String setOrderBy The basis of sorting. No N/A
Limit Integer setLimit The limit to the number of returned results. No N/A
Order String setOrder Specifies whether the data is sorted in ascending or descending order. No ASC specifies an ascending order, whereas DESC specifies a descending order.
SecurityToken String setSecurityToken The security token generated by Security Token Service (STS) for the Resource Access Management (RAM) role. No You must set this parameter if you use a RAM role.

Fields in filters

Parameter Type Setting method Description Example
key String setKey The name of the dimension. appId
value String setValue The dimension value. 11
Notice To query any metric of Application Monitoring, you must add pid and regionId in filters.

How to obtain the pid of an application

In the left-side navigation pane, choose Application Monitoring > Applications. On the Applications page, click the name of the target application to go to the overview page of this application.

The URL in the browser address bar contains the pid of this application in the format of pid=xxx. The browser is encoded, and therefore you need to modify the pid of all applications except for those in in Enterprise Distributed Application Service (EDAS). For example, if the pid in the URL is xxx%4074xxx, you need to replace %40 with @. That is, the pid is modified to xxx@74xxx.

Response parameters

Response data is returned as JSON strings. You can run QueryMetricResponse.getdata() to query the response data.

Parameter Description Remarks
data The data point returned. N/A

Queryable Application Monitoring metrics

You can call the QueryMetric operation to query the following metrics of Application Monitoring.

Note If you know the specific query conditions, add the value to the filters parameter to restrict the range of query results. If you do not know the specific query conditions, pass the dimensions in the following table to the dimensions parameter to obtain a list of all possible values of the dimension. For example, if you know the ip_country_id of a country, but do not know the ip_region_id of each region of this country, you can pass ip_country_id to the filters parameter and pass ip_region_id to the dimensions parameter. In this way, you can obtain the ip_region_id of every region of this country and can then use the specific ip_region_id to make a more precise query.
Metric Description Dimension Measurement data
appstat.vm Common metrics, which correspond to the JVM monitoring chart in application details, including the garbage collection (GC), heap memory, non-heap memory, and number of threads.
  • pid
  • rootIp
GC:
  • youngGcCount//number of young GC events monitored in the JVM
  • oldGcCount//number of full GC events monitored in the JVM
  • youngGcTime//total time for young GC monitored in the JVM
  • oldGcTime//total time for full GC monitored in the JVM
  • youngGcCountInstant//instantaneous value of the number of young GC events monitored in the JVM
  • oldGcCountInstant//instantaneous value of the number of full GC events monitored in the JVM
  • youngGcTimeInstant//instantaneous value of the total time for young GC monitored in the JVM
  • oldGcTimeInstant//instantaneous value of the total time for young GC monitored in the JVM
Detailed information about heap memory and non-heap memory:
  • EdenSpace//young generation - Eden space
  • OldGen//old generation
  • survivorSpace//young generation - survivor space
  • metaSpace
  • nonHeapCommitted//non-heap memory
  • nonHeapInit//initial value of non-heap memory
  • nonHeapMax//maximum value of non-heap memory
  • nonHeapUsed//non-heap memory usage
  • directUsed//direct buffer
  • directCapacity//direct buffer
Number of threads:
  • threadCount
  • threadNewCount
  • threadDeadlockCount
  • threadRunnableCount
  • threadTerminatedCount
  • threadTimedWaitCount
  • threadWaitCount
  • threadBlockedCount
appstat.host Host monitoring metrics, which include the number of instances, CPU, physical memory, disk, load, network traffic (in bytes), and number of network packets. pidrootIp Number of instances:
  • instanceCount
CPU:
  • systemCpuIdle//not displayed on the page - CPU idle
  • systemCpuSystem
  • systemCpuUser
  • systemCpuIoWait
Physical memory:
  • systemMemFree
  • systemMemUsed
  • SystemMemTotal//not displayed on the page - total system memory
  • systemMemBuffers
  • SystemMemCached//page cache
Disk:
  • systemDiskFree
  • systemDiskUsed
  • SystemDiskTotal//not displayed on the page in the Alibaba Cloud console - total system disk
Load:
  • systemLoad
Network:
  • systemNetInPackets
  • systemNetOutPackets
  • systemNetInErrs
  • systemNetOutErrs
  • systemNetInBytes
  • systemNetOutBytes
appstat.database Database call
  • pid
  • rpcType//call type
  • endpoint//database address: localhost: 3306
  • destId//database name: arms
  • rt//response time
  • count//number of requests
  • error//number of errors
appstat.txn API call
  • pid
  • rpcType
  • rpc//interface: /demo/oracleTwo
  • rt
  • count
  • error
  • errRate//error rate
appstat.incall Application details
  • pid
  • rpcType
  • rootIp
  • rpc
  • ppid
  • rt
  • count
  • error
  • exception
appstat.exception Exception
  • pid
  • rpc
  • endpoint
  • excepType
  • excepInfo
  • rt
  • count
  • error
appstat.sql Slow SQLs
  • pid
  • rpc
  • endpoint
  • sqlId
  • rt
  • count
  • error
  • slow
appstat.mq.send Message Queue (MQ) message sending N/A
  • rt
  • count
  • error
appstat.mq.receive MQ message receiving N/A
  • rt
  • count
  • error

Sample code

The following is the sample code for calling the QueryMetric operation to query the data about the old generation and the Eden space of the JVM of an application:

  1. import com.aliyuncs.DefaultAcsClient;
  2. import com.aliyuncs.IAcsClient;
  3. import com.aliyuncs.exceptions.ClientException;
  4. import com.aliyuncs.exceptions.ServerException;
  5. import com.aliyuncs.profile.DefaultProfile;
  6. import com.google.gson.Gson;
  7. import java.util.*;
  8. import com.aliyuncs.arms.model.v20190808.*;
  9. public class ARMSDemo {
  10. public static void main(String[] args) {
  11. //the accessKey ID of your cloud account or RAM account, or the accessKey ID of the temporary token of your RAM account
  12. String accessKeyId = "xxx";
  13. //the accessKey Secret of your cloud account or RAM account, or the accessKey Secret of the temporary token of your RAM account
  14. String accessKeySecret = "xxx";
  15. //The value of region and endpoint are the same, refering to the regions supported by ARMS.
  16. String endpoint = "xxx";//eg. cn-hangzhou
  17. String region = "xxx";//eg. cn-hangzhou
  18. //The value of productName is uniform ARMS.
  19. String productName = "ARMS";
  20. //Replace cn-hangzhou with your region, for example cn-beijing.
  21. String domain = "arms.cn-hangzhou.aliyuncs.com";
  22. DefaultProfile profile = DefaultProfile.getProfile(region, accessKeyId, accessKeySecret);
  23. try {
  24. DefaultProfile.addEndpoint(endpoint, region, productName, domain);
  25. } catch (ClientException e) {
  26. e.printStackTrace();
  27. }
  28. IAcsClient client = new DefaultAcsClient(profile);
  29. QueryMetricRequest request = new QueryMetricRequest();
  30. request.setStartTime(1555482869888L);
  31. request.setEndTime(1555488869888L);
  32. request.setMetric("APPSTAT.JVM");
  33. List<String> measuresList = new ArrayList<String>();
  34. measuresList.add("EDENSPACE");
  35. measuresList.add("OLDGEN");
  36. request.setMeasuress(measuresList);
  37. List<QueryMetricRequest.Filters> filtersList = new ArrayList<QueryMetricRequest.Filters>();
  38. QueryMetricRequest.Filters filters1 = new QueryMetricRequest.Filters();
  39. filters1.setKey("pid");
  40. filters1.setValue("xxx");
  41. filtersList.add(filters1);
  42. QueryMetricRequest.Filters filters2 = new QueryMetricRequest.Filters();
  43. filters2.setKey("regionId");
  44. filters2.setValue("cn-hangzhou");
  45. filtersList.add(filters2);
  46. request.setFilterss(filtersList);
  47. List<String> dimensionsList = new ArrayList<String>();
  48. dimensionsList.add("rootIp");
  49. request.setDimensionss(dimensionsList);
  50. try {
  51. QueryMetricResponse response = client.getAcsResponse(request);
  52. System.out.println(new Gson().toJson(response));
  53. } catch (ServerException e) {
  54. e.printStackTrace();
  55. } catch (ClientException e) {
  56. System.out.println("ErrCode:" + e.getErrCode());
  57. System.out.println("ErrMsg:" + e.getErrMsg());
  58. System.out.println("RequestId:" + e.getRequestId());
  59. }
  60. }
  61. }
  1. const Core = require('@alicloud/pop-core');
  2. var client = new Core({
  3. accessKeyId: '<accessKeyId>',
  4. accessKeySecret: '<accessKeySecret>',
  5. endpoint: 'http://arms.cn-hangzhou.aliyuncs.com',
  6. apiVersion: '2019-08-08'
  7. });
  8. var params = {
  9. "Measures.1": "EDENSPACE",
  10. "Measures.2": "OLDGEN",
  11. "Filters.1.Key": "pid",
  12. "Filters.1.Value": "xxx",
  13. "Filters.2.Key": "regionId",
  14. "Filters.2.Value": "cn-hangzhou",
  15. "Metric": "APPSTAT.JVM",
  16. "Dimensions.1": "rootIp",
  17. "StartTime": 1555482869888,
  18. "EndTime": 1555488869888
  19. }
  20. var requestOption = {
  21. method: 'POST'
  22. };
  23. client.request('QueryMetric', params, requestOption).then((result) => {
  24. console.log(result);
  25. }, (ex) => {
  26. console.log(ex);
  27. })
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/services/arms"
  5. )
  6. func main() {
  7. client, err := arms.NewClientWithAccessKey("cn-hangzhou", "<accessKeyId>", "<accessKeySecret>")
  8. request := arms.CreateQueryMetricRequest()
  9. request.EndTime = "1555488869888"
  10. request.StartTime = "1555482869888"
  11. request.Metric = "APPSTAT.JVM"
  12. request.Measures = &[]string{"EDENSPACE", "OLDGEN"}
  13. request.Filters = &[]arms.QueryMetricFilters{
  14. {
  15. Key: "pid",
  16. Value: "xxx",
  17. },
  18. {
  19. Key: "regionId",
  20. Value: "cn-hangzhou",
  21. },
  22. }
  23. request.Dimensions = &[]string{"rootIp"}
  24. response, err := client.QueryMetric(request)
  25. if err ! = nil {
  26. fmt.Print(err.Error())
  27. }
  28. fmt.Printf("response is %#v\n", response)
  29. }
  1. <? php
  2. use AlibabaCloud\Client\AlibabaCloud;
  3. use AlibabaCloud\Client\Exception\ClientException;
  4. use AlibabaCloud\Client\Exception\ServerException;
  5. // Download:https://github.com/aliyun/openapi-sdk-php-client
  6. // Usage:https://github.com/aliyun/openapi-sdk-php-client/blob/master/README-CN.md
  7. AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessKeySecret>')
  8. ->regionId('cn-hangzhou') // replace regionId as you need
  9. ->asGlobalClient();
  10. try {
  11. $result = AlibabaCloud::rpcRequest()
  12. ->product('ARMS')
  13. // ->scheme('https') // https | http
  14. ->version('2019-08-08')
  15. ->action('QueryMetric')
  16. ->method('POST')
  17. ->options([
  18. 'query' => [
  19. 'Measures.1' => 'EDENSPACE',
  20. 'Measures.2' => 'OLDGEN',
  21. 'Filters.1.Key' => 'pid',
  22. 'Filters.1.Value' => 'xxx',
  23. 'Filters.2.Key' => 'regionId',
  24. 'Filters.2.Value' => 'cn-hangzhou',
  25. 'Dimensions.1' => "rootIp",
  26. 'Metric' => 'APPSTAT.JVM',
  27. 'StartTime' => '1555482869888',
  28. 'EndTime' => '1555488869888',
  29. ],
  30. ])
  31. ->request();
  32. print_r($result->toArray());
  33. } catch (ClientException $e) {
  34. echo $e->getErrorMessage() . PHP_EOL;
  35. } catch (ServerException $e) {
  36. echo $e->getErrorMessage() . PHP_EOL;
  37. }
  1. #! /usr/bin/env python
  2. #coding=utf-8
  3. from aliyunsdkcore.client import AcsClient
  4. from aliyunsdkcore.acs_exception.exceptions import ClientException
  5. from aliyunsdkcore.acs_exception.exceptions import ServerException
  6. from aliyunsdkarms.request.v20190808.QueryMetricRequest import QueryMetricRequest
  7. client = AcsClient('<accessKeyId>', '<accessKeySecret>', 'cn-hangzhou')
  8. request = QueryMetricRequest()
  9. request.set_accept_format('json')
  10. request.set_EndTime(1555488869888)
  11. request.set_StartTime(1555482869888)
  12. request.set_Metric("APPSTAT.JVM")
  13. request.set_Measuress(["EDENSPACE","OLDGEN"])
  14. request.set_Filterss([
  15. {
  16. "Key": "pid",
  17. "Value": "xxx"
  18. },
  19. {
  20. "Key": "regionId",
  21. "Value": "cn-hangzhou"
  22. }
  23. ])
  24. request.set_Dimensionss(["rootIp"])
  25. response = client.do_action_with_exception(request)
  26. # python2: print(response)
  27. print(str(response, encoding='utf-8'))
  1. using System;
  2. using System.Collections.Generic;
  3. using Aliyun.Acs.Core;
  4. using Aliyun.Acs.Core.Exceptions;
  5. using Aliyun.Acs.Core.Profile;
  6. using Aliyun.Acs.ARMS.Model.V20190808;
  7. namespace ARMSDemo
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<accessKeyId>", "<accessKeySecret>");
  14. DefaultAcsClient client = new DefaultAcsClient(profile);
  15. var request = new QueryMetricRequest();
  16. request.EndTime = 1555488869888;
  17. request.StartTime = 1555482869888;
  18. request.Metric = "APPSTAT.JVM";
  19. var measuresList = new List<String>();
  20. measuresList.Add("EDENSPACE");
  21. measuresList.Add("OLDGEN");
  22. request.Measuress = measuresList;
  23. var filtersList = new List<QueryMetricRequest.Filters>();
  24. var filters1 = new QueryMetricRequest.Filters();
  25. filters1.Key = "pid";
  26. filters1.Value = "xxx";
  27. filtersList.Add(filters1);
  28. var filters2 = new QueryMetricRequest.Filters();
  29. filters2.Key = "regionId";
  30. filters2.Value = "cn-hangzhou";
  31. filtersList.Add(filters2);
  32. request.Filterss = filtersList;
  33. var dimensionsList = new List<String>();
  34. dimensionsList.Add("rootIp");
  35. request.Dimensionss = dimensionsList;
  36. try {
  37. var response = client.GetAcsResponse(request);
  38. Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
  39. }
  40. catch (ServerException e)
  41. {
  42. Console.WriteLine(e);
  43. }
  44. catch (ClientException e)
  45. {
  46. Console.WriteLine(e);
  47. }
  48. }
  49. }
  50. }
  1. # gem install aliyunsdkcore
  2. require 'aliyunsdkcore'
  3. client = RPCClient.new(
  4. access_key_id: '<accessKeyId>',
  5. access_key_secret: '<accessKeySecret>',
  6. endpoint: 'https://arms.aliyuncs.com',
  7. api_version: '2019-08-08'
  8. )
  9. response = client.request(
  10. action: 'QueryMetric',
  11. params: {
  12. "Measures.1": "EDENSPACE",
  13. "Measures.2": "OLDGEN",
  14. "Filters.1.Key": "pid",
  15. "Filters.1.Value": "xxx",
  16. "Filters.2.Key": "regionId",
  17. "Filters.2.Value": "cn-hangzhou",
  18. "Dimensions.1": "rootIp",
  19. "Metric": "APPSTAT.JVM",
  20. "StartTime": 1555482869888,
  21. "EndTime": 1555488869888
  22. },
  23. opts: {
  24. method: 'POST'
  25. }
  26. )
  27. print JSON.parse(response.body)