This topic describes how to use Managed Service for Prometheus to monitor an Elastic Compute Service (ECS) instance deployed in a VPC.

Prerequisites

Note The parameter values in this topic are provided for reference. You can modify them based on your business requirements.

Procedure

  1. Download Prometheus Node Exporter.
    • Download Prometheus Node Exporter from the official website of Prometheus .
    • Download Prometheus Node Exporter by running the following command.
      wget https://github.com/prometheus/node_exporter/releases/download/v1.2.0/node_exporter-1.2.0.linux-amd64.tar.gz
  2. Install Prometheus Node Exporter.
    1. Decompress the downloaded file.
      tar -zvxf node_exporter-1.2.0.linux-amd64.tar.gz -C /usr/local/
    2. Rename the decompressed file.
      mv /usr/local/node_exporter-1.2.0.linux-amd64 /usr/local/node_exporter
    3. Start Prometheus Node Exporter.
      cd /usr/local/node_exporter
      nohup ./node_exporter &
    4. Check whether port 9100 is in use.
      ss -naltp | grep 9100

      The following command output indicates that port 9100 is not in use.

      LISTEN 0      4096               *:9100             *:*    users:(("node_exporter",pid=1420**,fd=3))    

      If port 9100 is in use, run the following command to change the port: For example, the port can be changed to 9999.

      nohup ./node_exporter  --web.listen-address=":9999"&
  3. Check the connectivity of Prometheus Node Exporter.
    After Prometheus Node Exporter is started, use the Command Line Interface (CLI) to access the following URL:
    curl http://localhost:9100/metrics
    Note
    • Replace the localhost and port in the command based on your business requirements.
    • We recommend that you try to access http:// [ECS IP]:9100/metrics from other ECS instances to check whether the network connectivity is blocked by a security group rule.

    If connectivity is available, the following command output is returned.

    # HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
    # TYPE go_gc_duration_seconds summary
    go_gc_duration_seconds{quantile="0"} 0
    go_gc_duration_seconds{quantile="0.25"} 0
    go_gc_duration_seconds{quantile="0.5"} 0
    go_gc_duration_seconds{quantile="0.75"} 0
    go_gc_duration_seconds{quantile="1"} 0
    go_gc_duration_seconds_sum 0
    go_gc_duration_seconds_count 0
    # HELP go_goroutines Number of goroutines that currently exist.
    # TYPE go_goroutines gauge
    go_goroutines 7
    # HELP go_info Information about the Go environment.
    # TYPE go_info gauge
    go_info{version="go1.16.6"} 1
    # HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
    # TYPE go_memstats_alloc_bytes gauge
    go_memstats_alloc_bytes 1.386192e+06
    # HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
    # TYPE go_memstats_alloc_bytes_total counter
    go_memstats_alloc_bytes_total 1.386192e+06
    # HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
    # TYPE go_memstats_buck_hash_sys_bytes gauge
    go_memstats_buck_hash_sys_bytes 4562
    # HELP go_memstats_frees_total Total number of frees.
    # TYPE go_memstats_frees_total counter
    go_memstats_frees_total 754
  4. Create a service discovery.
    1. Log on to the Managed Service for Prometheus console.
    2. In the left-side navigation pane, click Monitoring List.
    3. Click the name of the Prometheus instance.
    4. In the left-side navigation pane, click Service Discovery. Then, click the Configurations tab.
    5. On the Configurations tab, you can create a service discovery by using one of the following methods:

      Method 1: Modify a default service discovery

      1. On the Default Service Discovery tab, find vpc-ecs-service-discovery and click Details.
      2. In the YAML configuration dialog box, complete the following configurations and click Confirmation.

        Change the default port 9100 to a port based on your business requirements.

        The metric data of all ECS instances at the /metrics endpoint in the current VPC is collected over port 9100.

        If you want to collect the metrics of only specific ECS instances, you can configure tag_filters to filter ECS instances by tag.
        # Specify the key-value pair   
           tag_filters: 
               - key: 'testKey'
                 values: ['testValue']

        Then, you need to add a tag to the ECS instance in the ECS console. For more information, see Edit the tags of an instance.

      Method 2: Create a custom service discovery

      1. On the Custom Service Discovery tab, click Add in the upper-right corner.
      2. In the dialog box that appears, enter the configurations and click OK.
  5. Create a Grafana dashboard
    1. In the left-side navigation pane, click Dashboards.
    2. In the upper-right corner of the Dashboards page, click Create Dashboard in Grafana Service Pro Edition.
    3. In the left-side navigation pane, choose + > Import.
    4. On the Import page, enter 12884, which is the ID of the JVM Grafana template provided by Prometheus, in the Import via grafna.com field and click Load next to the field.
      Note To obtain other Grafana dashboard templates, visit Grafana Labs.
    5. In the Prometheus drop-down list, select a data source in your VPC, and then click Import.

      The name of the data source in the VPC is in the vpc-**** format.

      After the data source is imported, you can view the metrics of the data source on the Grafana dashboard.