すべてのプロダクト
Search
ドキュメントセンター

Function Compute:モニタリングデータ

最終更新日:Jul 25, 2024

このトピックでは、CloudMonitor APIを使用してFunction Computeメトリクスをクエリする方法について説明します。 関連するAPI操作を呼び出し、異なるリクエストパラメーターを使用してFunction Computeのモニタリングデータを取得できます。 これらのパラメータには、Project、StartTime、EndTime、Dimensions、Period、およびMetricが含まれます。

API操作の詳細については、「関数別の操作の一覧」をご参照ください。

プロジェクト

すべてのFunction Computeメトリクスは、acs_fcプロジェクトでクエリに使用できます。

次のサンプルコードは、SDK for Javaを使用してプロジェクトを設定する方法を示しています。

QueryMetricRequest request = new QueryMetricRequest();
request.setProject("acs_fc"); 

StartTime と EndTime

CloudMonitorでは、(StartTime, EndTime) フォームのStartTimeパラメーターとEndTimeパラメーターによって時間範囲が定義されます。 時間範囲は、StartTimeに関して排他的であり、EndTimeに関して包括的である。

説明

CloudMonitorは31日間データを保持します。 このため、StartTimeとEndTimeの間の時間範囲は31日を超えることはできず、31日より前のデータを照会することはできません。

その他の時間パラメーターの詳細については、「関数別の操作のリスト」をご参照ください。

次のサンプルコードは、SDK for Javaを使用してプロジェクトを設定する方法を示しています。

request.setStartTime("2023-08-26 08:00:00");
request.setEndTime("2023-08-26 09:00:00"); 

ディメンション

Function Computeのモニタリングサービスは、Function Computeのメトリクスをリージョン、サービス、および関数のディメンションで分割します。 各ディメンションは、ディメンションパラメーターの値に異なる形式を使用します。

  • リージョナルメトリックのディメンションパラメーターは、次の形式です。

    {"region": "${your_region}"}
  • 関数メトリックのDimensionsパラメーターは、次の形式です。

    {"region": "${your_region}", "functionName": "${your_functionName}"}
説明

すべてのFunction Computeメトリクスのディメンションパラメーターの値は、単一のキーと値のペアを含むJSON文字列です。 次のサンプルコードは、SDK for Javaを使用してプロジェクトを設定する方法を示しています。

request.setDimensions("{\" region\":\" your_region\"}");

期間

Function Computeメトリクスの集計期間の粒度は60秒である必要があります。

次のサンプルコードは、SDK for Javaを使用してプロジェクトを設定する方法を示しています。

request.setPeriod("60");

メトリック

次のサンプルコードは、SDK for Javaを使用してプロジェクトを設定する方法を示しています。

request.setMetric("your_metric");

次の表に、Function Computeのドキュメントで説明されているメトリックを示します。

寸法

メトリック

説明

リージョン

RegionTotalInvocations

TotalInvocations

RegionBillableInvocations

BillableInvocations

RegionThrottles

Throttles

RegionClientErrors

ClientErrors

RegionServerErrors

ServerErrors

RegionBillableInvocationsRate

BillableInvocationsの比率。

RegionThrottlesRate

スロットル比。

RegionClientErrorsRate

クライアントのエラー率。

RegionServerErrorsRate

サーバーエラー率。

サービス

ServiceTotalInvocations

TotalInvocations

ServiceBillableInvocations

BillableInvocations

ServiceThrottles

Throttles

ServiceClientErrors

ClientErrors

ServiceServerErrors

ServerErrors

ServiceBillableInvocationsRate

課金可能な呼び出し率。

ServiceThrottlesRate

スロットル比。

ServiceClientErrorsRate

クライアントのエラー率。

ServiceServerErrorsRate

サーバーエラー率。

機能

FunctionTotalInvocations

TotalInvocations

FunctionBillableInvocations

BillableInvocations

FunctionThrottles

Throttles

FunctionErrors

FunctionErrors

FunctionClientErrors

ClientErrors

FunctionServerErrors

ServerErrors

FunctionBillableInvocationsRate

課金可能な呼び出し率。

FunctionThrottlesRate

スロットル比。

FunctionErrorsRate

関数エラー率。

FunctionClientErrorsRate

クライアントのエラー率。

FunctionServerErrorsRate

サーバーエラー率。

FunctionAvgDuration

平均期間。

FunctionMaxMemoryUsage

最大メモリ使用量。

サンプルコード

次のテキストは、サンプルのpom.xmlファイルを示しています。

...
    <dependencies>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-cms</artifactId>
            <version>5.0.1</version>
        </dependency>
    </dependencies>
...
            

サンプルコード:

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.cms.model.v20170301.QueryMetricListRequest;
import com.aliyuncs.cms.model.v20170301.QueryMetricListResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class MonitorService {
    public static void main(String[] args) {
        /*
        The AccessKey pair of an Alibaba Cloud account can be used to access all API operations. Using these credentials to perform operations in Function Compute is a high-risk operation. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. 
        We recommend that you do not save the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account may be compromised. 
        In this example, the AccessKey pair is saved to the environment variables for authentication. 
        Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables in your local environment before you run sample code. 
        In Function Compute runtimes, the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are automatically configured after you configure the execution permissions. 
        */
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessSecretKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKey, accessSecretKey);
        IAcsClient client = new DefaultAcsClient(profile);


        QueryMetricListRequest request = new QueryMetricListRequest();
        request.setProject("acs_fc");
        request.setPeriod("60");
        request.setStartTime("2023-08-26 16:20:00");
        request.setEndTime("2023-08-26 16:30:00");
        request.setAcceptFormat(FormatType.JSON);

        try {
            // Region dimension. JSONObject dim = new JSONObject();
            request.setMetric("RegionTotalInvocations");  // Specify the metric. 
            dim.put("region", "<your_region>");  //Example: cn-shanghai
            request.setDimensions(dim.toJSONString());
            QueryMetricListResponse response = client.getAcsResponse(request);
            System.out.println(response.getCode());
            System.out.println(response.getMessage());
            System.out.println(response.getRequestId());
            System.out.println(response.getDatapoints());

            // Function dimension. dim = new JSONObject();
            request.setMetric("FunctionTotalInvocations");  // Specify the metric. 
            dim.put("region", "<your_region>");
            dim.put("functionName", "<your_function_name>");
            request.setDimensions(dim.toJSONString());
            response = client.getAcsResponse(request);
            System.out.println(response.getCode());
            System.out.println(response.getMessage());
            System.out.println(response.getRequestId());
            System.out.println(response.getDatapoints());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}