When you need to use Log Service call statistics records to query and analyze collected function calls in real time and view the monitoring information in a visualized manner, you can import function call statistics to the log repository that you create in real time. You can view the status of function calls in real time through query analysis and chart display in Log Service to better control the service status of functions.

Notice

Due to the reconfiguration of the Function Compute console, the operation configurations related to the log dashboard have been unpublished in the new console. The features of the log dashboard described in this topic are only applicable to the old console.

We apologize for any inconvenience caused.

Operation

Before you begin, make sure that the following operations are complete:

Collect and import logs

  1. Log on to the Function Compute console.
  2. In the top navigation bar, select the region where your Kubernetes cluster is deployed.
  3. In the left-side navigation pane, click Overview.
  4. In the Quick Access section on the Overview page, marked ① in the following figure, click Configure Log Dashboard, marked ② in the following figure. fc-image3
  5. On the Configure Log Dashboard page, click Configure Log Analysis. 2
  6. In the Custom Log Analysis panel, perform the following operations: 3
    1. Select a project and a Logstore that reside in the region from the Log Project and Logstore drop-down lists.
    2. Select one or more services that you want to associate with the Logstore.
    3. Select Create new role from the Role Operation drop-down list and click Authorize.
    4. On the Role Templates page, verify the information and click Confirm Authorization Policy.
    5. In the Custom Log Analysis panel, click OK.

Query and analyze logs

  1. On the Configure Log Dashboard page in the Function Compute console, click the Logstore that contains the logs you want to query.
  2. On the details page of the Logstore, execute a query statement to analyze logs. The following examples are provided:
    • Use the requestID parameter to obtain the details about a request that is called.
      requestID:e9870cbd-2ab2-6c78-3486-cd164015b889
    • Query an asynchronous invocation request.
      mode:async and operation:InvokeFunction
    • Query a request that resulted in an invocation whose duration exceeded 5,000 milliseconds.
      operation:InvokeFunction and durationMs > 5000

    The following table describes the related parameters.

    Column Type Description Example value
    accountID String The ID of the account. 188********23420
    asyncInvocationFinished String Indicates whether the invocation was complete. true
    concurrentCount Long The concurrency when the log was created. 10
    concurrentReqLimit Long The maximum allowed concurrency. 100
    durationMs Double The time used to execute the function. Unit: milliseconds. 5012.025
    errorType String The type of the error that occurred. HandledError
    externalServiceVersion String The version of the service. For more information, see Version operations. 1
    fcStatus Long The internal status code. 200
    forwardedFor String The original IP address. When an Alibaba Cloud CDN event trigger is used, the IP address is the IP address that calls Function Compute. 200.***.***.100
    functionErrors Long Non-system function errors. 0
    functionName String The name of the function. ReservedFunction
    functionTimeoutInSec Long The timeout period for the function. Unit: seconds. 300
    host String The host for the request. 1234567890.cn-shanghai.fc.aliyun-inc.com
    isDarkLaunch String Indicates whether an alias or a canary version was used. For more information, see the following topics: true
    ip String The IP address of the client that sent the request. 172.***.***.118
    isHTTPS String Indicates whether HTTPS was used. false
    isHTTPTrigger String Indicates whether the function was triggered by an HTTP trigger. false
    latency Double The latency of the function invocation. Unit: milliseconds. 5017.347
    maxMemoryUsage Double The maximum memory that the instance used. Unit: MB. 17.25
    memoryLimitInMB Long The maximum memory that the instance can use. Unit: MB. 512
    meteredRespSize Long The amount of billable traffic. Unit: byte. 0
    method String The HTTP request method used for the function invocation. POST
    mode String The function invocation mode. Valid values:
    • sync: synchronous
    • async: asynchronous
    sync
    operation String The log category. InvokeFunction
    path String The URL path of the function invocation. /2016-08-15/services/MeteringService/functions/ReservedFunction/invocations
    qualifier String The information about the service version used. For more information, see Query the version for an executed function. The version number or alias.
    region String The region where the cluster resides. cn-shanghai
    requestID String The ID of the request. e9870cbd-2ab2-6c78-3486-cd164015b889
    requestOriginalURI String The original Uniform Resource Identifier (URI). After a domain name is bound, the return value of this parameter does not include elements such as /2016-08-15. /2016-08-15/services/MeteringService/functions/ReservedFunction/invocations
    requestSize Long The size of the request. Unit: byte. 912
    resolveQualifierLatency Long The time used to parse the service version. 0
    responseSize Long The size of the response. Unit: byte. 0
    runtime String The runtime environment of the function. python2.7
    serviceName String The name of the service. test-service-name
    status Long The HTTP status code received by the client. 200
    timestamp Long The timestamp when the function began to process the request. Unit: seconds. 1538137847
    userAgent String The user agent of the requester. go-sdk-0.1

Use dashboard charts and interpret metrics

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Overview.
  3. In the Quick Access section on the Overview page, marked ① in the following figure, click Configure Log Dashboard, marked ② in the following figure. Path
  4. On the Configure Log Dashboard page, find the log that you want to analyze and click Analyze Log in the Actions column. The following figure shows the displayed charts.
    5
    Parameter Description
    Billable Invocations The number of times your function was executed. This value includes invocations that were successful and invocations that resulted in an internal error.
    Resource Usage The amount of used resources, which is calculated based on the following formula: Memory used by the instance × Time used to execute the function.
    Outbound Data Transfer (Internet) Billable traffic generated by the response of the function. This traffic does not include traffic generated by requests that are initiated from TCP or UDP clients within the function.
    Inbound Data Traffic Inbound traffic generated when the function accepts a request. This traffic is not billable.
    Errors
    • User error rate: the percentage of failures to execute the function that were not caused by the system. These non-system errors include errors in function execution and HTTP client errors 400 to 499, excluding HTTP 429. A value of 0 indicates normal operation.
    • Throttling error rate: the percentage of failures to execute the function that were caused by throttling. These errors include throttling initiated by Function Compute and throttling that were not caused by exceeding the system quota. Throttling initiated by Function Compute generates the HTTP 503 response, and non-system throttling generates the HTTP 429 response. A value of 0 indicates normal operation.
    • System error rate: the percentage of failures to execute the function that were caused by Function Compute. These system errors include HTTP server errors 500 to 599, excluding HTTP 503. A value of 0 indicates normal operation.
    Billable Invocations and Function Errors
    • Billable invocations: the number of function invocations that occurred and were billable.
    • Function errors: the number of function invocations that occurred but failed due to non-system reasons.
    Duration (Milliseconds) Average: the average duration for which functions were executed in a time period.
    Concurrency
    • Concurrency limit: the concurrency quota for your account in the current region.
    • Actual concurrency: the highest concurrency used in a time period.
    HTTP Status
    • The HTTP status code returned to the client after an HTTP function was executed.
    • Each status code class shows the number of responses that contain a status code from that class. For example, the Status_4xx class shows the total number of HTTP status codes from 400 to 499 that were returned in a time period.
    Top N Functions By default, functions are sorted by resource usage from large to small.
    • Resource Usage (GB-second): Memory used by the instance × Time used to execute the function.
    • Outbound Traffic (GB): billable traffic generated by the response of the function. This traffic does not include traffic generated by requests that are initiated from TCP or UDP clients within the function.
    • Billable Invocations: the number of times the function was invoked and executed.
    • Function Errors: the number of function errors.
    • Max Memory Usage (MB): the maximum amount of memory used by the function.

Customize dashboards

You can use query statements to create new charts. These charts can be added as new dashboards so that you can view them later. For more information, see the following articles:
Notice The following query statements and charts are only for reference. Exercise caution if you decide to use these statements for commercial purposes.
  • Source analysis of user IP addresses

    • Access distribution within China

      Execute the following query statement and select map of China as the chart type:

      operation:InvokeFunction | SELECT ip_to_province(IF(forwardedFor = '', ip, forwardedFor)) AS"Province", approx_distinct(IF(forwardedFor = '', ip, forwardedFor)) AS"Request"GROUP BY"Province"LIMIT 50           
    • Access distribution worldwide

      Execute the following query statement and select world map as the chart type:

      operation:InvokeFunction | SELECT ip_to_country(IF(forwardedFor = '', ip, forwardedFor)) AS"Country", approx_distinct(IF(forwardedFor = '', ip, forwardedFor)) AS"Request"GROUP BY"Country"LIMIT 50  
    • Heatmap

      Execute the following query statement and select heatmap as the chart type:

      operation:InvokeFunction | SELECT ip_to_geo(IF(forwardedFor = '', ip, forwardedFor)) AS geo, count(1) AS count GROUP BY geo order BY count desc LIMIT 30         
  • User agent ratio

    Execute the following query statement and select pie chart as the chart type:

    operation:InvokeFunction | SELECT userAgent, COUNT(userAgent) AS count GROUP BY userAgent ORDER BY count DESC LIMIT 20
    User pie chart
  • Top 20 URLs to HTTP functions

    Execute the following query statement and select table as the chart type:

    operation:InvokeFunction and isHTTPTrigger:true | SELECT requestOriginalURI, COUNT(requestOriginalURI) AS count GROUP BY requestOriginalURI ORDER BY count LIMIT 20

Configure alert rules

You can add a DingTalk chatbot to help you monitor the health status of your functions. The chatbot uses alert rules in Log Service to monitor the health status of your functions. For more information, see Configure an alert rule.