Tencent Cloud Monitor Grafana App

repository·master·Indexed 41 days ago

https://github.com/tencentcloud/tencentcloud-monitor-grafana-app

A Grafana plugin that integrates Tencent Cloud's monitoring and logging services into dashboards. It utilizes Tencent Cloud Monitor API 3.0 and Cloud Log Service (CLS) API 3.0 to visualize performance metrics for resources like CVM, MySQL, and Load Balancers. The app includes preset dashboard templates and supports template variables for regions and instances. Requires Grafana 7.3 or higher for plugin versions 2.0.0 and above.

Tokens
23.1K
Snippets
65
Records
94
Agent score
51%

What's inside Tencent Cloud Monitor Grafana App

  1. Overview of Tencent Cloud Monitor App for Grafana

    master

    The Tencent Cloud Monitor App is a Grafana plugin that allows users to visualize monitoring and log data from Tencent Cloud. It integrates with:

    1. Tencent Cloud Monitor API 3.0: Provides performance metrics for cloud products like CVM (Cloud Virtual Machine), MySQL, and Load Balancers.
    2. Tencent Cloud Log Service (CLS) API 3.0: Provides log retrieval and analysis capabilities.

    The plugin includes preset Dashboard templates for representative cloud products such as cloud servers, MySQL databases, and load balancers.

  2. Overview of Tencent Cloud Monitor Grafana App

    master

    The Tencent Cloud Monitor Grafana App is an application plugin for Grafana that enables visualization of cloud monitoring and log data.

    Core Capabilities:

    Supported Data Sources:

    • Tencent Cloud Monitoring: Provides load and performance metrics for products like Cloud Virtual Machine (CVM) and Cloud Databases (CDB).
    • Tencent Cloud Log Service (CLS): Provides real-time log collection, storage, search, and analysis.
  3. How Template Variables work in the plugin

    master

    The plugin utilizes Grafana's Template Variables feature to create reusable and interactive Dashboards. This allows users to dynamically change the scope of metrics displayed (e.g., switching between different cloud resources) without modifying the dashboard structure itself.

    Supported Variables: Currently, the app provides variables for:

    • region
    • CVM
    • TencentDB for MySQL instances

    For more detailed information and implementation examples, see the official documentation.

  4. Install the Tencent Cloud Monitor Grafana App

    master

    To install the latest version of the plugin, use the Grafana CLI.

    Prerequisites:

    • Grafana version >= 7.3 is required for plugin version 2.0.0 and above.

    For detailed installation and configuration instructions regarding monitoring data, refer to the monitor document. For log service configuration, refer to the log service document.

    $ grafana-cli plugins install tencentcloud-monitor-app
  5. Set up local development environment

    master

    To develop the Tencent Cloud Monitor Grafana App locally, follow these steps to prepare your environment, install dependencies, and run the application.

    1. Prerequisites

    Ensure you have the following installed:

    2. Installation and Setup

    1. Fork the repository and clone it to your local machine:
      git clone https://github.com/${your-git-username}/tencentcloud-monitor-grafana-app.git
    2. Install dependencies:
      npm install
      go mod vendor

    3. Running the Development Environment

    • Frontend development: Run npm run watch to start the frontend watcher.
    • Backend development: Run mage -v to start the backend environment.
    • Full stack (Docker): Run docker-compose up to run the entire stack. Once running, visit http://localhost:3000 in your browser.
    # Install dependencies
    $ npm install
    $ go mod vendor
    
    # Start frontend
    $ npm run watch
    
    # Start backend
    $ mage -v
    
    # Run full stack
    $ docker-compose up
  6. Use Explore for log retrieval and analysis

    master

    You can use the Grafana Explore feature to query and visualize logs:

    1. Open Explore and select the configured Tencent Cloud Monitor data source. (If both Cloud Monitor and Log Service are enabled, ensure you manually select the Log Service data source).
    2. Provide the following query parameters:
      • 地域 (Region): Select the appropriate region from the dropdown.
      • 日志主题ID (Log Topic ID): Enter the ID of the log topic within the selected region.
      • 查询语句 (Query Statement): Enter your search or analysis query.

    Query Types:

    • Log Retrieval: Use Lucene syntax to find specific log content.
    • Log Analysis: Use SQL to perform statistical analysis and visualize results. The chart type (TimeSeries, BarChart, PieChart, etc.) is automatically inferred from the data type returned.
  7. Configure Template Variables for Log Service

    master

    You can use Grafana template variables ($var or ${VarName}) to make dashboards dynamic. This is useful for switching between different Log Topic IDs or time intervals.

    Query Type Variables

    Use this to populate a variable with values from your logs (e.g., a list of HTTP status codes).

    1. Set variable name (e.g., HttpStatus).
    2. Set type to Query.
    3. Select the Log Service data source.
    4. Use a query like: | select distinct(status).
    5. Reference it in your panel query: status: ${HttpStatus}.

    Custom Type Variables

    Use this for predefined lists (e.g., time intervals).

    1. Set variable name (e.g., Interval).
    2. Set type to Custom.
    3. Enter comma-separated values: 1 MINUTE,5 MINUTE,15 MINUTE.
    4. Reference it in your query: | select ... interval ${Interval}) ....

    Quick Topic ID Switching

    To switch between different log topics quickly:

    1. Create a variable named TopicId (Type: Custom or TextBox).
    2. In your panel's Log Topic ID input field, enter $TopicId.
    -- Example: Using a Custom variable ${Interval}
    | select histogram( cast(__TIMESTAMP__ as timestamp),interval ${Interval}) as time, count(*) as pv group by time order by time
    
    -- Example: Using a Query variable ${HttpStatus}
    status: ${HttpStatus}
  8. Follow the commit message format

    master

    The project follows the Conventional Commit message guidelines. Every commit message must follow this structure:

    <type>[optional scope]: <description>
    
    [optional body]
    
    [optional footer(s)]

    Constraints:

    • The header is mandatory.
    • The scope is optional.
    • No line in the commit message can exceed 100 characters.

    Allowed types:

    • build: Changes that affect the build system or external dependencies
    • ci: Changes to CI configuration files and scripts
    • chore: Other changes that don't modify src or test files
    • docs: Documentation only changes
    • feat: A new feature
    • fix: A bug fix
    • perf: A code change that improves performance
    • refactor: A code change that neither fixes a bug nor adds a feature
    • revert: Reverts a previous commit
    • style: Changes that do not affect the meaning of the code (white-space, formatting, etc)
    • test: Adding missing tests or correcting existing tests
    feat(api): add new monitoring endpoint
    
    This adds the capability to query specific metric groups.
    
    BREAKING CHANGE: the old endpoint is no longer supported.
  9. Install the Tencent Cloud Monitor App via Grafana CLI

    master

    To install the plugin, use the grafana-cli command. Note that from version 2.0.0 onwards, the minimum requirement is Grafana 7.3 or higher. Ensure Grafana is installed before attempting to install the plugin.

    Use the following command to install a specific version (example uses v2.8.6):

    $ grafana-cli --pluginUrl https://github.com/TencentCloud/tencentcloud-monitor-grafana-app/releases/download/2.8.6/tencentcloud-monitor-app-2.8.6.zip plugins install tencentcloud-monitor-app
  10. Configure Log Indexing Rules (RuleInfo)

    master

    When configuring indexing for a log topic, you use RuleInfo to define how data is indexed. You must provide exactly one of the following: FullText (Full-text indexing), KeyValue (Key-Value indexing), or Tag (Metadata/Tag indexing).

    /** 索引规则,FullText、KeyValue、Tag参数必须输入一个有效参数 */
    export interface RuleInfo {
      /** 全文索引配置, 如果为空时代表未开启全文索引 */
      FullText?: FullTextInfo;
      /** 键值索引配置,如果为空时代表未开启键值索引 */
      KeyValue?: RuleKeyValueInfo;
      /** 元字段索引配置,如果为空时代表未开启元字段索引 */
      Tag?: RuleTagInfo;
    }
  11. How the Tencent Cloud Monitor App manages dashboard folders

    master

    The Tencent Cloud Monitor Grafana app automatically manages dedicated folders for its dashboards to ensure organized storage. It uses two specific folders based on the dashboard language:

    1. tencent-cloud-monitor (UID: tencent-cloud-monitor): The default folder for standard dashboards.
    2. Tencent Cloud Monitor (UID: tencent-cloud-monitor-english): The folder for English-language dashboards (identified by files ending in _en_dashboard.json).

    When importing dashboards via the Grafana UI, the app intercepts the /api/dashboards/import request to automatically assign the correct folderId based on the dashboard's file path. Additionally, when the app is enabled or updated, it triggers a reviseDashboard process that moves all existing dashboards associated with the plugin into these specific folders.