This topic describes how to report the monitoring data of hosts that are not provided by Alibaba Cloud to Cloud Monitor by using an NGINX proxy server.

Step 1: Deploy an NGINX proxy server

Note We recommend that you use a Linux server as your proxy server because Cloud Monitor is deployed on a Linux server. In this example, a Linux server that runs CentOS is used.
  1. Download the latest installation package of NGINX, for example, nginx-1.19.6.
    1. Go to the nginx: download page.
    2. Click nginx-1.19.6 to download the nginx-1.19.6.tar.gz package.
  2. Download NGINX patch packages to the specified directory of the proxy server, for example, /opt.
    Note In this example, the proxy_connect_1014.patch patch package is installed.
    1. Log on to the proxy server as the root user.
    2. Run the following commands to download NGINX patch packages:

      cd /opt

      yum install -y git

      git clone https://github.com/chobits/ngx_http_proxy_connect_module.git

      The patch packages in the following figure are downloaded. http_proxy_connect
  3. Run the following commands to install the sample NGINX patch package.

    yum install -y patch pcre pcre-devel

    patch -p1 < ngx_http_proxy_connect_module/patch/proxy_connect_1014.patch

  4. Install NGINX.
    1. Upload the nginx-1.19.6.tar.gz package to the specified directory of the proxy server, such as /usr/local.
    2. Log on to the proxy server as the root user.
    3. Run the following commands to decompress the nginx-1.19.6.tar.gz package to the nginx-1.19.6 directory:

      cd /usr/local

      tar zxvf nginx-1.19.6.tar.gz

    4. Run the following commands to initialize NGINX:

      cd nginx-1.19.6

      ./configure --prefix=/usr/local/nginx-1.19.6 --with-http_stub_status_module --with-http_ssl_module --add-module=ngx_http_proxy_connect_module

    5. Run the following commands to install NGINX:
      make install
      make && make install
    6. Run the following command to start NGINX:
      ./nginx
    7. Check whether NGINX is installed.

      In the address bar of your browser, enter IP address of the proxy server:80. If the following output is displayed, the installation is successful.

      Nginx
  5. Configure an NGINX proxy.
    1. Run the following commands to create a directory named conf.d:

      cd /usr/local/nginx-1.19.6/conf

      mkdir conf.d

    2. Run the following commands to create a file named forward.conf in the conf.d directory.

      cd conf.d

      vi nginx.conf

    3. Configure a forward proxy or a reverse proxy in the forward.conf file.
      • Forward proxy

        If you consider the Internet outside the LAN as a huge resource pool, the clients in the LAN need to access the Internet by using a forward proxy.

        Copy the following code to the forward.conf file. Set the resolver parameter to the IP address of the proxy server and use the default values for other parameters.
        server {
             listen                         80;
         
             # dns resolver used by forward proxying
             resolver                       192.168.XX.XX;  # The IP address of the proxy server. 
         
             # forward proxy for CONNECT request
             proxy_connect;
             proxy_connect_allow            443;
             proxy_connect_connect_timeout  10s;
             proxy_connect_read_timeout     10s;
             proxy_connect_send_timeout     10s;
         
             # forward proxy for non-CONNECT request
             location / {
                 proxy_pass http://$http_host$request_uri;  # The protocol and request URI of the proxy server. 
                 proxy_set_header Host $host;
             }
         }
        Note The forward proxy of NGINX does not support HTTPS.
      • Reverse proxy

        If the LAN provides resources and services to the Internet, the clients on the Internet need to access resources in the LAN by using a reverse proxy.

        Copy the following code to the forward.conf file. Set the server_name parameter to the IP address of the proxy server, the server_name parameter to the URL that the proxy server accesses, the ssl_certificate parameter to the Secure Sockets Layer (SSL) certificate, and the ssl_certificate_key parameter to the key of the SSL certificate. Use the default values for other parameters.
        server {
            listen              443 ssl;
            server_name         192.168.XX.XX; # The IP address of the proxy server. 
            ssl_certificate     XXXX.pem; # The SSL certificate. 
            ssl_certificate_key XXXX.key; # The key of the SSL certificate. 
        
            location / {
                proxy_pass  https://www.aliyun.com; # The URL that the proxy server accesses. 
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header REMOTE-HOST $remote_addr;
                proxy_set_header X-Forward`ed-For $proxy_add_x_forwarded_for;
                }
        }
        Note For more information about how to apply for an SSL certificate, see Apply for a certificate.
    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the forward.conf file.
    5. Run the following commands to open the nginx.conf file:

      cd ..

      vi nginx.conf

    6. Edit the nginx.conf file.
      Copy the following code to the nginx.conf file and set the include parameter to the path to the forward.conf file.
      http {
      .....
      include /usr/local/nginx-1.19.6/conf/conf.d/forward.conf;
      .....
      }
    7. Press the Esc key, enter :wq, and then press the Enter key to save and close the nginx.conf file.
    8. Run the following command to restart the NGINX proxy server:
      nginx -s reload
    9. Check whether the NGINX proxy is configured.
      • Forward proxy

        Run the following command to access a URL. If the URL can be accessed, the NGINX proxy is configured.

        curl -x192.168.XX.XX (IP address of the proxy server)http://www.aliyun.com (Any URL)

      • Reverse proxy

        Run the following command. If you can access only the URL specified in the nginx.conf file, the NGINX proxy is configured.

        curl -x192.168.XX.XX (IP address of the proxy server)https://www.baidu.com (Any URL)

Step 2: Install and configure the Cloud Monitor agent

  1. Install the Cloud Monitor agent on a host that is not provided by Alibaba Cloud.
  2. Configure the NGINX proxy server in the Cloud Monitor agent.
    1. Log on to the host where the Cloud Monitor agent resides as the root user.
    2. Run the following commands to open the agent.properties file.

      cd /usr/local/cloudmonitor/conf

      vi agent.properties

    3. Configure the NGINX proxy server in the configuration file of the Cloud Monitor agent.
      The following code provides an example on how to configure an NGINX proxy server:
      http.proxy.auto=false
      # Manually configure the proxy server
      http.proxy.host=192.168.XX.XX  # The IP address of the NGINX proxy server. 
      http.proxy.port=8080  # The port of the NGINX proxy server. 
      #http.proxy.user=user  # The NGINX proxy server does not require a username for HTTP authentication. 
      # http.proxy.password=password # The NGINX proxy server does not require a password for HTTP authentication. 
    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the agent.properties file.
    5. Run the following command to restart the Cloud Monitor agent:
      ./cloudmonitorCtl.sh restart

Step 3: View the monitoring data of the host not provided by Alibaba Cloud

  1. Log on to the Cloud Monitor console.
  2. In the left-side navigation pane, click Host Monitoring.
  3. On the Instances tab of the Host Monitoring page, click the instance name of the host or click Monitoring Charts in the Actions column.
    View the monitoring data of the host not provided by Alibaba Cloud.