大型企业上云时会面临大规模的多类型的云产品资源运维监控问题。使用云监控的应用分组功能,可以按照业务、部署环境等角度对云产品资源进行跨云产品、跨地域的分组管理。使用报警模板功能,可以快速规模化的对分组的资源构建报警体系,迅速提升运维效率。

产品架构

具体架构如下图所示:



相关API

通过使用以下API创建管理多种云资源的报警规则。
API名称 说明
PutContact 创建联系人:添加联系人姓名、手机号、邮箱等用于接收报警通知的信息。
PutContactGroup 创建联系人组:创建包含多个联系人的联系人组,发送报警通知时以联系人组为单位通知。
CreateMonitorGroup 创建应用分组:按照业务维度、开发环境维度等角度创建应用分组,方便管理资源。
CreateMonitorGroupInstances 向应用分组中添加资源:向创建好的应用分组中添加相应的实例,如ECS VM 、RDS 实例。
CreateMetricRuleTemplate 创建报警模板:创建一个可应用于分组上的报警模板,模板中可以包含多种云产品的多种监控项。
ApplyMetricRuleTemplate 报警模板应用到组:选择将报警模板应用于指定的分组后,将根据模板中的描述创建出相应的报警规则。

典型案例

以下代码示例展示了从添加联系人到最终对应用分组创建出报警规则的完整链路。

  1. 创建报警联系人。
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.exceptions.ServerException;
    import com.aliyuncs.profile.DefaultProfile;
    import com.google.gson.Gson;
    import java.util.*;
    import com.aliyuncs.cms.model.v20190101.*;
    
    public class CmsDemo {
    
        public static void main(String[] args) {
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
            IAcsClient client = new DefaultAcsClient(profile);
    
            PutContactRequest request = new PutContactRequest();
            request.setDescribe("数据组负责人");
            request.setContactName("李雷");
    
            List<String> channelsList = new ArrayList<String>();
            channelsList.add("*******");
            channelsList.add("*******");
            request.setChannelss(channelsList);
    
            try {
                PutContactResponse response = client.getAcsResponse(request);
                System.out.println(new Gson().toJson(response));
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                System.out.println("ErrCode:" + e.getErrCode());
                System.out.println("ErrMsg:" + e.getErrMsg());
                System.out.println("RequestId:" + e.getRequestId());
            }
    
        }
    }
  2. 创建报警联系人组。
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.exceptions.ServerException;
    import com.aliyuncs.profile.DefaultProfile;
    import com.google.gson.Gson;
    import java.util.*;
    import com.aliyuncs.cms.model.v20190101.*;
    
    public class CmsDemo {
    
        public static void main(String[] args) {
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
            IAcsClient client = new DefaultAcsClient(profile);
    
            PutContactGroupRequest request = new PutContactGroupRequest();
            request.setDescribe("数据组(ES)");
            request.setContactGroupName("数据组");
    
            List<String> contactNamesList = new ArrayList<String>();
            contactNamesList.add("李雷");
            request.setContactNamess(contactNamesList);
    
            try {
                PutContactGroupResponse response = client.getAcsResponse(request);
                System.out.println(new Gson().toJson(response));
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                System.out.println("ErrCode:" + e.getErrCode());
                System.out.println("ErrMsg:" + e.getErrMsg());
                System.out.println("RequestId:" + e.getRequestId());
            }
    
        }
    }
  3. 创建一个应用分组。
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.exceptions.ServerException;
    import com.aliyuncs.profile.DefaultProfile;
    import com.google.gson.Gson;
    import java.util.*;
    import com.aliyuncs.cms.model.v20190101.*;
    
    public class CmsDemo {
    
        public static void main(String[] args) {
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
            IAcsClient client = new DefaultAcsClient(profile);
    
            CreateMonitorGroupRequest request = new CreateMonitorGroupRequest();
            request.setContactGroups("数据组");
            request.setGroupName("数据测试环境");
    
            try {
                CreateMonitorGroupResponse response = client.getAcsResponse(request);
                System.out.println(new Gson().toJson(response));
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                System.out.println("ErrCode:" + e.getErrCode());
                System.out.println("ErrMsg:" + e.getErrMsg());
                System.out.println("RequestId:" + e.getRequestId());
            }
    
        }
    }
  4. 向分组中添加ECS实例。
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.exceptions.ServerException;
    import com.aliyuncs.profile.DefaultProfile;
    import com.google.gson.Gson;
    import java.util.*;
    import com.aliyuncs.cms.model.v20190101.*;
    
    public class CmsDemo {
    
        public static void main(String[] args) {
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
            IAcsClient client = new DefaultAcsClient(profile);
    
            CreateMonitorGroupInstancesRequest request = new CreateMonitorGroupInstancesRequest();
            request.setGroupId(47428**);
    
            List<CreateMonitorGroupInstancesRequest.Instances> instancesList = new ArrayList<CreateMonitorGroupInstancesRequest.Instances>();
    
            CreateMonitorGroupInstancesRequest.Instances instances1 = new CreateMonitorGroupInstancesRequest.Instances();
            instances1.setCategory("ECS");
            instances1.setInstanceId("*******");
            instances1.setRegionId("cn-beijing");
            instancesList.add(instances1);
            request.setInstancess(instancesList);
    
            try {
                CreateMonitorGroupInstancesResponse response = client.getAcsResponse(request);
                System.out.println(new Gson().toJson(response));
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                System.out.println("ErrCode:" + e.getErrCode());
                System.out.println("ErrMsg:" + e.getErrMsg());
                System.out.println("RequestId:" + e.getRequestId());
            }
    
        }
    }
  5. 将报警模板应用到分组。
    import com.aliyuncs.DefaultAcsClient;
    import com.aliyuncs.IAcsClient;
    import com.aliyuncs.exceptions.ClientException;
    import com.aliyuncs.exceptions.ServerException;
    import com.aliyuncs.profile.DefaultProfile;
    import com.google.gson.Gson;
    import java.util.*;
    import com.aliyuncs.cms.model.v20190101.*;
    
    public class CmsDemo {
    
        public static void main(String[] args) {
            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
            IAcsClient client = new DefaultAcsClient(profile);
    
            ApplyMetricRuleTemplateRequest request = new ApplyMetricRuleTemplateRequest();
            request.setTemplateIds("1370**");
            request.setGroupId(47428);
    
            try {
                ApplyMetricRuleTemplateResponse response = client.getAcsResponse(request);
                System.out.println(new Gson().toJson(response));
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                System.out.println("ErrCode:" + e.getErrCode());
                System.out.println("ErrMsg:" + e.getErrMsg());
                System.out.println("RequestId:" + e.getRequestId());
            }
    
        }
    }

相关文档

安装Alibaba Cloud SDK for Java

云监控API参考