CloudMonitor provides monitoring data of the core services of Alibaba Cloud. It can also display your custom monitoring data. In addition to viewing the monitoring data in the CloudMonitor console, you can use the popular data visualization tool Grafana to display the data.

Procedure

  1. Install Grafana.
    Note
    1. Install the Grafana software.
      This topic takes the CentOS Linux operating system as an example. You can install Grafana in CentOS Linux by using one of the following methods:
      • Method 1:

        yum install https://dl.grafana.com/oss/release/grafana-5.3.4-1.x86_64.rpm

      • Method 2:

        wget https://dl.grafana.com/oss/release/grafana-5.3.4-1.x86_64.rpm

        sudo yum localinstall grafana-5.3.4-1.x86_64.rpm

    2. Run the following command to start the Grafana service:
      service grafana-server start
    3. Optional. Install the Grafana panel plug-ins.

      If you need a Grafana panel such as the pie chart panel, run the following command:

      grafana-cli plugins install grafana-piechart-panel

      Note For more information about how to install other Grafana panel plug-ins, see Grafana Plugins.
  2. Install the CloudMonitor data source plug-in.
    1. Find the plug-in directory of Grafana.
      For example, the plug-in directory is /var/lib/grafana/plugins/ in CentOS Linux.
    2. Run the following commands to install the CloudMonitor data source plug-in:

      cd /var/lib/grafana/plugins/

      git clone https://github.com/aliyun/aliyun-cms-grafana.git

    3. Run the following command to restart the Grafana service:
      service grafana-server restart
    You can also download the aliyun-cms-grafana.zip package from GitHub, decompress the package, and upload the plug-in to the /var/lib/grafana/plugins/ directory. Then, restart the Grafana service.
    Note The current version of the CloudMonitor data source plug-in does not support setting alert rules for the monitoring data.
  3. Configure the CloudMonitor data source plug-in.
    Log on to Grafana after it is installed. The default port is 3000, and the default username is admin.
    Notice We recommend that you change the password the first time you log on to Grafana to avoid security risks.
    1. Log on to Grafana.
    2. On the Grafana homepage, choose Configuration > Data Sources in the left-side navigation pane.
    3. On the Data Sources page, click Add data source in the upper-right corner.
    4. Set parameters for the CloudMonitor data source.
      GUI element Description
      Name The name of the data source. You can specify the name as needed.
      Type The type of the data source. Select CMS Grafana Service.
      URL The URL of the data source. Example: http://metrics.cn-shanghai.aliyuncs.com. In this example, metrics is the name of the project and cn-shanghai.aliyuncs.com is the endpoint for the region where the project resides. Replace the project name and the endpoint as needed. For more information about the endpoints for different regions, see the Endpoints for different regions section in Request method.
      Access The method used to access the data source. Retain the default setting.
      Auth The authentication configuration. Retain the default setting.
      cloudmonitor service details The AccessKey ID and AccessKey secret of the account with the read permission on CloudMonitor data. We recommend that you use the AccessKey pair of a Resource Access Management (RAM) user.
      Note Specify the AccessKey pair in the Base64-encoded format. In Linux, run the echo -n "AccessKey" | base64 command to convert the AccessKey ID and AccessKey secret to Base64-encoded strings.
      The following figure shows sample settings for the parameters of the CloudMonitor data source plug-in.Configure the data source plug-in on Grafana
    5. Click Save & Test.
  4. Create a dashboard.
    1. On the Grafana homepage, choose Dashboards > Manage.
      Manage
    2. Click Dashboard to create a dashboard.
      You can also click Folder to create a folder and then click Dashboard. Alternatively, you can click Import to import a dashboard.
    3. Configure a graph.
      1. On the new dashboard, choose New Panel > Add > Graph.
      2. Click Panel Title. In the dialog box that appears, click Edit.
      3. On the Metrics tab, select cms-grafana from the Data Source drop-down list. Set other parameters such as Project, Metric, Period, Dimensions, Y - column, and X - column [time].
        For more information about how to set the Project, Metric, and Period parameters, see QueryMetricList. The following table describes other parameters of a graph.
        Parameter Description
        Group The ID of the application group that is created under your Alibaba Cloud account in CloudMonitor.
        Dimensions The instances from which the latest monitoring data is collected for the specified project and metric. If you set this parameter to Group, monitoring data is collected from all instances in the specified application group.
        Y-column The data to appear in the Y-axis. You can select more than one option.
        X-column The data to appear in the X-axis. Set the value to timestamp.
        Y-column describe The description of each option selected for the Y - column parameter.
        Note
        • For more information about the graph, see Graph panel.
        • You can manually enter values for all the parameters by following the instructions in QueryMetricList.
        • You can enter null to invalidate a parameter.
        • If the value of the Dimensions parameter is incomplete, refresh the page or manually enter the instance IDs in the required format.
        Metrics
        For custom monitoring data, you must manually set the parameters that are described in the following table.
        Parameter Description
        Project The name of the project, in the format of acs_customMetric_ID of your Alibaba Cloud account.
        Metric The name of the custom metric.
        Period The time period for reporting the custom monitoring data.
        Group The ID of the application group for which the custom monitoring data is reported.
        Dimensions The dimension for reporting the custom monitoring data. You must manually enter the parameter value. Only one dimension is supported. If you enter multiple dimensions, only the first one is valid.
        Note If the dimensions in the CloudMonitor console are in the format of env: public, step: 5-ReadFromAlertOnline, you must replace the commas (,) with ampersands (&).
        Y-column The data to appear in the Y-axis. You can select multiple options for aggregating the monitoring data, including Average, Maximum, Minimum, Sum, SampleCount, P10, P20, and P99.
        X-column The data to appear in the X-axis. Set the value to timestamp.
        Custom monitoring
      4. Configure the Singlestat panel.
        1. Choose New Panel > Add > Singlestat.
        2. Click Panel Title. In the dialog box that appears, click Edit.
        3. On the Metrics tab, set relevant parameters.
          Note For more information about Singlestat, see Graph panel.
          Configure the Singlestat panel
    4. Configure variables.
      You can create query variables and custom variables.
      • Add a query variable.
        The following table lists the supported query variables.
        Variable Definition Description Example
        $namespace namespace(filter) Filters the metrics of cloud services by the specified filter conditions. The filter field can be set to null. For more information about the metrics for cloud services, see Overview. namespace(ecs)
        $metric metric($namespace,filter) Filters the metrics of cloud services by the specified namespace and filter conditions. The namespace field can be a variable and is required. The filter field can be set to null. For more information about the metrics for cloud services, see Overview. metric($namespace,disk), metric($namespace,null), and metric(acs_ecs_dashboard,disk)
        $tagsFilter tagsFilter(type, regionId, tagType, tagKey) Queries the keys and values of the tags attached to ApsaraDB for RDS instances or Elastic Compute Service (ECS) resources under the current account. For more information, see ListTagResources and Query tags.

        type: the type of the service. Set the value to ECS or RDS. tagType: the type of the information about tags to query. Set the value to key or value.

        Note You must grant the permissions on ECS and ApsaraDB for RDS to the current account.
        • Sample definition used to query the keys of the tags attached to ApsaraDB for RDS instances in the China (Beijing) region under the current account: tagFilter(RDS, cn-beijing, key, null)
        • Sample definition used to query the keys and values of the tags attached to ApsaraDB for RDS instances in the China (Beijing) region under the current account, in the Key:/:Value format: tagFilter(RDS, cn-beijing, value, null)
        $tags tags(type, regionId, resourceType, resourceId_array, tag_array) Queries the IDs of the ApsaraDB for RDS instances or ECS resources with the specified tags under the current account. For more information, see ListTagResources and Query tags.
        • type: the type of the service. Set the value to ECS or RDS.
        • resourceType: the type of the resources. Set the value to instance if the type field is set to ECS. Set the value to INSTANCE if the type field is set to RDS.
        • resourceId_array: the IDs of the instances to be filtered, in the format of ResourceId.N.

          Example: [instanceId_1,instanceId_2,instanceId_3].

        • tag_array: the keys or key-value pairs of the tags to filter instances.

          Example: [key1:/:value1,key2:/:value2,key3:/:value3] or [key1,key2,key3].

        Note You must grant the permissions on ECS and ApsaraDB for RDS to the current account.
        Sample definition used to query the IDs of the ApsaraDB for RDS instances with the specified tags in the China (Beijing) region under the current account: tag(RDS,cn-beijing, INSTANCE, [instanceId_1,instanceId_2], [key1:/:value1,key2:/:value2])
        $dimension dimension($namespace,metric,filterFirst,filterSecond) Queries the dimensions under the current account.

        filterFirst[g99hxhnnyr;1egdhoza;kty4zk40hh] or /dev/vda1

        filterSecond [g99hxhnnyr;1egdhoza;kty4zk40hh] or /dev/vda1

        • dimension(acs_ecs_dashboard,diskusage_used,i-2zed,/dev/vd),
        • dimension($namespace,$metric,[i-2zed;i-2zeg;i-2zeb],/dev/vda1),
        • dimension($namespace,$metric,i-2zed;i-2zeg;i-2zeb,/dev/vda1),
        • dimension($namespace,$metric,/dev/vda1,[i-2zed;i-2zeg;i-2zeb]),
        • dimension($namespace,$metric,/dev/vda1,null)
        On the created dashboard, click the Dashboard settings icon at the top of the page. In the left-side navigation pane, click Variables. On the Variables page, click New to create a variable and set relevant parameters. The following figure shows sample variables.Variables
        You can edit a variable and use the feature in the Value groups/tags section. The following figure shows the Value groups/tags section.Value Groups
        After the required variables are created, specify the variables as the parameter values in the corresponding panel in the format of $Variable name, as shown in the following figure.Panel
        Note For more information, see the README file in the plug-in. You can view and use the sample code for this example in the json(ecs,rds) file in the src directory.
      • Create a custom variable.
        On the created dashboard, click the Dashboard settings icon at the top of the page. In the left-side navigation pane, click Variables. On the Variables page, click New to create a variable and set relevant parameters. The following figure shows how to edit a custom variable.Variables
        After the required variables are created, specify the variables as the parameter values in the corresponding panel in the format of $Variable name, as shown in the following figure.panel
        Note You can specify custom variables as the values of the Project, Metric, Period, Dimensions, and Y - column parameters. We recommend that you set the names of the variables to project, metric, period, group, dimensions and ycol.
  5. View the monitoring data.
    After the preceding steps are performed, you can view the monitoring data in the created dashboard.DashboardDashboard