tencent cloud

Feedback

Template Variables

Last updated: 2022-03-24 16:20:05
    Variable Type Description Effective Scope
    Data source A data source variable allows you to batch switch data sources of charts in the dashboard. It is suitable for scenarios where a dashboard is applied to multiple log topics, data on the dashboard is compared in blue and green, and more. Charts that use the variable on the dashboard
    Quick filtering A quick filtering variable allows you to filter data of all charts on the dashboard by specified fields, which is equivalent to adding filter criteria in chart query statements. All charts on the dashboard

    Configuring a Data Source Variable

    Directions

    1. Log in to the CLS console.
    2. On the left sidebar, click Dashboard to enter the dashboard management page.
    3. Click the ID/name of the target dashboard to enter the dashboard details page.
    4. Click at the top to enter the configuration page.
    5. Click Template Variable and click Create.
    6. In the pop-up window, configure the template variable information and click Submit.
      ParameterDescription
      Variable TypeVariable category. Different categories correspond to different configuration items and application scenarios. Here, select **Data Source**.
      Variable NameName of the variable in the query/search statement. The value can contain only letters and digits.
      Display NameName of the variable displayed on the dashboard. This parameter is optional. If it is empty, the system automatically uses the variable name as the display name.
      Data Source ScopeValue range of the variable. Currently, only option **All Log Topics** is supported, that is, there is no limit on the data source range.
      Default Log TopicLog topic used by default.
    7. On the dashboard details page, click More > Edit to edit charts.
      Note:

      If there are no charts on your dashboard, please add charts.

    8. At the top of the edited chart, click Log Topic, select Use Data Source Variable, and select the template variable created just now.
    9. Click Save.
    10. On the dashboard details page, click the Data Source drop-down list and select another log topic. Then the system changes automatically changes the data source of the chart using the variable accordingly.

    FAQs

    Why does a configured data source variable not take effect or take effect only on some charts?

    A data source variable does not apply directly to all charts on the dashboard. It applies only to those charts that use it on the chart editing page.

    Configuring a Quick Filtering Variable

    1. Log in to the CLS console.
    2. On the left sidebar, click Dashboard to enter the dashboard management page.
    3. Click the ID/name of the target dashboard to enter the dashboard details page.
    4. Click at the top to enter the configuration page.
    5. Click Template Variable and click Create.
    6. In the pop-up window, configure the template variable information and click Submit.
      ParameterDescription
      Variable TypeVariable category. Different categories correspond to different configuration items and application scenarios. Here, select **Quick Filtering**.
      Display NameName of the variable control on the UI. This parameter is optional. If it is empty, the system automatically uses the variable name as the display name.
      Log TopicSource log topic of the variable field.
      Select FieldFilter field.
      Support Multiple-SelectionIf this parameter is toggled on, you can select multiple variable values as filter conditions.
    7. On the dashboard details page, click the variable console and select the filter field. Then the data on the dashboard is refreshed to the filtered content.

    Examples

    Analyzing performance metrics of different APIs on the dashboard (quick variable filtering)

    Requirement

    Log topic A stores NGINX access logs of an application, and you are to use the dashboard to view the throughput, number of error requests, and response time of the entire application and a specified API. The following is the sample log information:

    body_bytes_sent:1344
    client_ip:127.0.0.1
    host:www.example.com
    http_method:POST
    http_referer:www.example.com
    http_user_agent:Mozilla/5.0
    proxy_upstream_name:proxy_upstream_name_4
    remote_user:example
    req_id:5EC4EE87A478DA3436A79550
    request_length:13506
    request_time:1
    http_status:201
    time:27/Oct/2021:03:25:24
    upstream_addr:219.147.70.216
    upstream_response_length:406
    upstream_response_time:18
    upstream_status:200
    interface:proxy/upstream/example/1
    

    Solution

    1. Create a dashboard.
    2. Create three charts (sequence diagrams) based on the application performance metrics. The corresponding query statements are as follows:
    • Throughput

      * | select histogram( cast(__TIMESTAMP__ as timestamp),interval 1 minute) as analytic_time, count(*) as pv group by analytic_time order by analytic_time limit 1000
      
    • Number of error requests

      http_status:>=400 | select histogram( cast(__TIMESTAMP__ as timestamp),interval 1 minute) as analytic_time, count(*) as pv_lost group by analytic_time order by analytic_time limit 1000
      
    • Average response time

      * | select histogram( cast(__TIMESTAMP__ as timestamp),interval 1 minute) as analytic_time, avg(request_time) as response_time group by analytic_time order by analytic_time limit 1000
      
    1. Add template variables.
    • Variable Type: Quick Filtering
    • Display Name: API name
    • Log Topic: Log topic A
    • Select field: interface
    1. Go back to the dashboard details page, and you can see this variable on the top of the page.
    • If API Name is not specified, data is not filtered, and the charts on the dashboard display all data, that is, the overall performance metrics of the application.

    • If API Name is specified, all charts on the dashboard use the specified API as the filter condition to filter data and display the performance metrics of the API.

    Viewing the production and test environment performance metrics on the dashboard separately (variable Data Source)

    Requirement

    An application has a production environment and a test environment, and logs are collected to Log topic A (production environment) and Log topic B (test environment). Therefore, during application development, testing, and Ops, you need to pay attention to the performance metrics of the two environments.

    Solution

    1. Create a dashboard.
    2. Add template variables.
    • Variable Type: Data Source
    • Variable Name: env
    • Display Name: Application Environment
    • Data Source Scope: All log topics
    • Default Log Topic: Log topic A (production environment)
    1. Add charts.
      In the Log Topic drop-down list, select Use Data Source Variable and select the ${env} variable created in the previous step. Then, charts will use the value of the variable as the data source, that is, Log topic A (production environment).

    2. Repeat Step 3 to add other charts.

    3. Go back to the dashboard details page, click the data source variable Application Environment at the top of the page, and switch the log topic in the drop-down list of the variable. Then, the charts that use the variable will switch the log topic accordingly.

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support