edit-icon download-icon

Custom monitoring

Last Updated: Feb 06, 2018

The container monitoring service integrates with the Alibaba Cloud CloudMonitor service and provides you with monitoring and alarm services for containers, applications, clusters, and nodes. The container monitoring service meets the basic requirements for container monitoring. However, in many business scenarios, you might need custom monitoring to meet the monitoring requirements of your systems and applications. Therefore, besides the basic monitoring capabilities, the container monitoring service provides two custom monitoring modes, allowing you to report custom monitoring data by writing data and collecting scripts on your own or exposing your HTTP monitoring data interface. Container Service monitoring framework collects data every one minute by running the script or calling the HTTP interface.

Prerequisites

Before using the custom monitoring feature, you must integrate the container monitoring service with third-party monitoring solutions (for more information, see Integrate with third-party monitoring solutions).

Note: Currently, Container Service monitoring integration only supports InfluxDB and Prometheus by default.

Your custom monitoring data is reported to your InfluxDB or Prometheus, and then connected with your data presentation and analysis service.

Report monitoring data by using custom monitoring scripts

  1. Create a Docker image and add a custom data collection script to this image.

    The output data of this collection script must comply with the InfluxDB data format protocol.

    1. weather,location=us-midwest temperature=82 1465839830100400200
    2. | -------------------- -------------- |
    3. | | | |
    4. | | | |
    5. +-----------+--------+-+---------+-+---------+
    6. |measurement|,tag_set| |field_set| |timestamp|
    7. +-----------+--------+-+---------+-+---------+

    For more information about the data format protocol, see InfluxDB line protocol.

  2. Log on to the Container Service console. Create an application by using an orchestration template. Use the aliyun.monitoring.script label to declare the data collection script used by the monitoring service.

    The sample template is as follows:

    1. custom-script:
    2. image: 'Your own image repository address'
    3. labels:
    4. aliyun.monitoring.script: "sh gather_mem.sh"

    The aliyun.monitoring.script label defines the command in the application container that monitoring service runs to collect the monitoring data. The label is configured as follows:

    1. labels:
    2. aliyun.monitoring.script: "command used to run the script"
  3. Open the web interface of InfluxDB to view the database tables named after data indexes.

    For information about how to view the database tables, see Integrate with third-party monitoring solutions.

Collect data by using the custom HTTP monitoring data interface

  1. Create a Docker image and expose the HTTP interface in the application.

    This interface outputs the monitoring data. You can customize the monitoring data format by conforming to the JSON syntax. In addition, the system cannot determine whether the JSON data returned from the custom HTTP interface is a data index field or a metadata tag of the data index. Therefore, use another configuration to specify what type of JSON data has the tag attribute. For more information, see Telegraf JSON data format.

  2. Log on to the Container Service console and create an application by using an orchestration template. In the template, add the aliyun.monitoring.http label to declare the data collection interface, and use aliyun.monitoring.tags: "your tag attribute name 1, your tag attribute name 2, ……" to declare what data fields returned from the HTTP data interface have the tag attribute.

    Sample template:

    1. nodejsapp:
    2. command: "bash /run.sh"
    3. ports:
    4. - "3000:3000"
    5. image: 'Your own image repository address'
    6. labels:
    7. aliyun.monitoring.http: "http://container:3000/metrics/data"
    8. aliyun.monitoring.tags: "tag1,tag2"

    The data returned from the data interface http://container:3000/metrics/data exposed by the application nodejsapp is as follows:

    1. {
    2. "tag1": "tag1value",
    3. "tag2": "tag2value",
    4. "field1": 1,
    5. "field2": 2,
    6. "field3": true,
    7. "field4": 1.5
    8. }

    The aliyun.monitoring.tags: "tag1,tag2" label defines that in the reported JSON data, attributes tag1 and tag2 are the tags of the reported data.

  3. Open the web interface of InfluxDB to view the database tables whose names consist of the httpjson_ prefix and the container name.

    For example, if the container name is nodejsapp_nodejsapp_1, the name of the database table in InfluxDB is httpjson_nodejsapp_nodejsapp_1.

    For more information about how to view the database tables, see Integrate with third-party monitoring solutions.

Thank you! We've received your feedback.