Alibaba Cloud Log Service (SLS) enables you to call statistical records, query and analyze Function Compute invocations that are logged in SLS, and view this data in a graphical interface. To do so, you must create your Logstore, so that function call statistics can be automatically imported into your Logstore in real time. SLS offers querying, analysis, and graphical visualization capabilities with which you can see in real time how functions are being called and have better control over the service status of Function Compute.

Prerequisites

Collect and import logs

  1. Log on to the Function Compute console. In the top navigation bar, select your region from the Region drop-down list, such as China (Hangzhou).
  2. In the left-side navigation pane, click Overview.
  3. Find the Quick Access section in the lower right of the Overview page, marked ① in the figure. In this section, click Configure Log Dashboard, marked ② in the figure.Path
  4. On the Configure Log Dashboard page, click Configure Log Analysis.2
  5. In the Custom Log Analysis dialog box, configure the parameters.3
    1. From the Log Project and Logstore drop-down lists, select the Log Service project and Logstore that you created in the region.
    2. Select one or more services that you want to associate with your Logstore.
    3. From the Role Operation drop-down list, select Create new role and click Authorize.
    4. On the Role Templates page, review the information and click Confirm Authorization Policy.4
    5. In the Custom Log Analysis dialog box, click OK.

Query and analyze logs

  1. In the Function Compute console, click Configure Log Dashboard. On the page that appears, click the Logstore that contains the logs you want to query.
  2. On the Logstore page, execute a query statement to analyze logs. The following examples are provided:
    • Use the requestID parameter to obtain details about a specific request:
      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.

    Parameter Type Description Example
    accountID String The account ID. 188********23420
    asyncInvocationFinished String Indicates whether the invocation was completed. true
    concurrentCount Long The concurrency when the log was created. 10
    concurrentReqLimit Long The maximum allowed concurrency. 100
    durationMs Double The time for which the function was executed. Unit: milliseconds. 5012.025
    errorType String The type of the error that occurred. HandledError
    externalServiceVersion String For more information about service versions, see Function versions. 1
    fcStatus Long The internal status code. 200
    forwardedFor String The original IP address. When a CDN event trigger is used, it 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 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 canary version was used. For more information, see the following documents: 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 function instance used. Unit: MB. 17.25
    memoryLimitInMB Long The maximum allowed memory usage for the function instance. Unit: MB. 512
    meteredRespSize Long The amount of billed traffic. Unit: bytes. 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 Using version in context. 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 URI. After a domain name is bound, the returned 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: bytes. 912
    resolveQualifierLatency Long The time used to parse the service version. 0
    responseSize Long The size of the response. Unit: bytes. 0
    runtime String The function runtime. python2.7
    serviceName String The service name. 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 data indicators

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Overview.
  3. Find the Quick Access section in the lower right of the Overview page, marked ① in the figure. In this section, click Configure Log Dashboard, marked ② in the figure.Path
  4. On the Configure Log Dashboard page, find the target log, and click Analyze Log in the Actions column. The following charts are displayed.
    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 memory used by the function instance is multiplied by the time for which the function was executed.
    Outbound Data Transfer (Internet) Billable traffic generated by the response of the function. This value 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 function failures 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 function failures caused by throttling. These errors involve 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 function failures 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 actually occurred and were billable.
    • Function errors: the number of invocations that actually occurred but resulted in function failures 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): The memory used by a function instance is multiplied by the time taken to execute the function.
    • Outbound Traffic (GB): billable traffic generated by the response of the function. This value 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 refer to them later. For more information, see the following topics:
Notice The following query statements and charts are for reference only. 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           
      Map of China
    • 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/region", approx_distinct(IF(forwardedFor = '', ip, forwardedFor)) AS"request"GROUP BY"country/region"LIMIT 50  
      World Map
    • 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         
      Heatmap
  • 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 the DingTalk chatbot to help you understand the status of your functions. The chatbot uses SLS alert rules to monitor service health. For more information, see Create an alert rule.