Connect a private service to Prometheus monitoring

更新时间:
复制 MD 格式

Private services support Prometheus monitoring, allowing service providers and users to view resource and application dashboards and access monitoring data. This topic describes how to connect a private service to Managed Service for Prometheus.

Background

A Prometheus instance is a logical unit in Managed Service for Prometheus that manages data collection, storage, and analysis. Each Prometheus instance provides data collection configurations, a time series database instance, dashboards, and alert configurations. For more information, see What is Managed Service for Prometheus?.

Prerequisites

Before you create a private service that supports Prometheus monitoring, you must create an integration component and a RemoteWrite Prometheus instance.

  1. Create an integration component.

    Provide the Prometheus access information to the Compute Nest technical support team (DingTalk group ID: 31045016300). The support team then creates a Prometheus integration component for your service. For more information about the access information that you must provide, see Compute Nest service: Configuration document for connecting to Alibaba Cloud Prometheus (for ISVs).

    Important

    The support team will provide the component's name and configuration parameters. Save this information for service creation.

  2. Create a RemoteWrite Prometheus instance.

    Enable the ARMS service in your service provider account. Then, create a RemoteWrite Prometheus instance on the ARMS console. For instructions on creating a RemoteWrite Prometheus instance, see Prometheus instance for general-purpose scenarios.

    Note
    • After you create the RemoteWrite Prometheus instance, copy and save the generated internal Remote Write endpoint.

    • A service provider can create a dedicated RemoteWrite Prometheus instance for each service or use a single instance for multiple services. Compute Nest does not restrict the mapping between services and Prometheus instances.

Create a private service with Prometheus monitoring

  1. Log on to the Compute Nest console.

  2. In the left-side navigation pane, choose My Services. On the My Services page, choose Created Services and click Create Service.

  3. On the Create Service page, select a private service and configure the service information.

    This section lists only the parameters that require special configuration for custom O&M. For other parameters, see Create a private service.

    1. In the Template section, enter the template content in the Template Content area. For more information about the template, see Template example.

      To allow the Prometheus instance to pull data, the service template must define a security group that opens the required port.

      • For forward access, open the port for internal network access. The source is the CIDR block of the VPC.

      • For reverse access, allow the Prometheus console to access the agent. The source is the fixed CIDR block 100.64.0.0/10.

        SecurityGroup:
          Type: ALIYUN::ECS::SecurityGroup
          Properties:
            SecurityGroupName: securityGroup
            VpcId:
              Ref: VpcId
            SecurityGroupIngress:
              - PortRange: '-1/-1'
                Priority: 1
                IpProtocol: all
                SourceCidrIp: 192.168.0.0/24
                NicType: intranet
              - PortRange: '-1/-1'
                Priority: 1
                IpProtocol: all
                SourceCidrIp: 100.64.0.0/10
                NicType: intranet

      If users need to create a new VPC, add an ALIYUN::ARMS::ManagedPrometheus resource to the template. If users select an existing VPC, do not add this resource. For more information, see ALIYUN::ARMS::ManagedPrometheus.

    2. In the O & M section, select Obtain Permissions, and then select All Permissions or Monitoring Permissions.

      Note

      The service provider can view the user's monitoring data only after the user grants All Permissions or Monitoring Permissions.

    3. In the Monitoring section, enable Prometheus Service.

    4. For Integration Component Name, enter the component name provided by the Compute Nest technical support team when the integration component was created.

    5. For Integration Component Configurations, enter the parameters provided by Compute Nest technical support in Step 1 of the Prerequisites section.

    6. For RemoteWrite URL, select the region for the RemoteWrite configuration and enter the internal Remote Write endpoint that you created in Step 2 of the Prerequisites section.

      Note
      • The RemoteWrite region must be one of the service's Regions.

      • The service provider must create at least one Prometheus RemoteWrite instance in each deployment region. You can view monitoring data only for deployment regions that have a configured Remote Write address.

      After you turn on the Prometheus Monitoring switch, enter the Integration Component Name, add a configuration template in the Integrated Component Configuration Parameters section, and edit the parameter code. To configure multiple addresses, click + Add RemoteWrite configuration.

  4. Click Create a service., and then click OK in the confirmation dialog box.

    After the service is created, its Prometheus monitoring configuration is available on the service details page. On the Monitoring tab, the Prometheus Monitoring status changes to Enabled, and the configured RemoteWrite Address is displayed, along with a View Dashboard Data link that opens the Grafana dashboard for the Remote Write instance.

Create and view a service instance

Create and view a service instance as a user to verify the Prometheus monitoring feature of the service.

  1. Create a service instance.

    This section describes only the parameters that require special configuration. For more information about how to create a service instance, see Create a private service instance.

    1. In the Prometheus Configurations section, turn on the Enable switch to enable Prometheus monitoring.

      Note
      • This setting affects only the user's view and does not impact the service provider's monitoring capabilities.

      • The Prometheus monitoring feature is billed separately. For more information, see Billing overview.

    2. Click Next: Confirm Order. On the confirmation page, verify the dependency check information. After the service instance is created, on the instance details page, go to the Dependency Check section and confirm that all dependency checks pass (including Prometheus monitoring and the AliyunServiceRoleForARMS role permissions). In the Service Instance Information section, you can view the instance's configuration parameters, such as its region, instance type, billing method, vSwitch availability zone, VPC ID, and vSwitch ID.

  2. View the service instance

    After the service instance is created, you can view the Prometheus monitoring configuration on the service instance details page. On this page, you can enable or disable Prometheus monitoring for the user. If monitoring is enabled, you can click View Dashboard Data to open the Grafana dashboard.

    Note

    When an existing service instance is upgraded to a version that includes Prometheus monitoring, the feature is automatically enabled for that instance.

Template example

ROSTemplateFormatVersion: '2015-09-01'
Description:
  en: Use an existing VPC and vSwitch to create one SLB instance and two ECS instances, and attach all ECS instances to the SLB instance.
  zh-cn: 使用已有VPC、VSWitch,创建1个SLB、2个ECS实例,并将所有ECS实例绑定到SLB上。
Parameters:
  ZoneId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::ZoneId
    AssociationPropertyMetadata:
      ComputeNestNetworkConfigZone: true
    Label:
      en: vSwitch Availability Zone
      zh-cn: 交换机可用区
  VpcId:
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
    Type: String
    Description:
      en: The ID of the existing virtual private cloud (VPC). You can find the ID, which starts with vpc-, in the Virtual Private Cloud console.
      zh-cn: 现有虚拟专有网络的实例ID
    Label:
      en: VPC ID
      zh-cn: 专有网络VPC实例ID
  VSwitchId:
    AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      VpcId: ${VpcId}
      ZoneId: ${ZoneId}
    Type: String
    Description:
      en: The ID of the existing vSwitch in the business network. You can find the ID in the Virtual Private Cloud console.
      zh-cn: 现有业务网络交换机的实例ID
    Label:
      en: vSwitch ID
      zh-cn: 交换机实例ID
  EcsInstanceType:
    Type: String
    Label:
      en: Instance Type
      zh-cn: 实例类型
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: ${ZoneId}
      InstanceChargeType: ${InstanceChargeType}
  InstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: The logon password for the server. It must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
      zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
    AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
    Label:
      en: Instance Password
      zh-cn: 实例密码
    ConstraintDescription:
      en: The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
      zh-cn: 长度 8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
    MinLength: 8
    MaxLength: 30
    AssociationProperty: ALIYUN::ECS::Instance::Password
  PayType:
    Type: String
    Label:
      en: ECS Instance Billing Method
      zh-cn: 付费类型
    Default: PostPaid
    AllowedValues:
      - PostPaid
      - PrePaid
    AssociationProperty: ChargeType
    AssociationPropertyMetadata:
      LocaleKey: InstanceChargeType
  PayPeriodUnit:
    Type: String
    Description:
      en: The unit of the subscription period. <br>Valid values: Week and Month. <br>Default value: Month.<br><b><font color='red'> This parameter is valid only when ECS Instance Billing Method is set to PrePaid.</b></font>
      zh-cn: 购买资源时长的周期。<br>Week为周,Month为月<br>默认值为月<br><b><font color='red'>当ECS实例类型为PrePaid有效</b></font>
    Label:
      en: Subscription Period Unit
      zh-cn: 购买资源时长周期
    Default: Month
    AllowedValues:
      - Month
      - Year
    AssociationProperty: PayPeriodUnit
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${PayType}
              - PostPaid
  PayPeriod:
    Type: Number
    Label:
      en: Subscription Duration
      zh-cn: 购买资源时长
    Default: 1
    AllowedValues:
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
    AssociationProperty: PayPeriod
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${PayType}
              - PostPaid
  LoadBalancerSpec:
    Type: String
    AssociationProperty: ALIYUN::SLB::Instance::InstanceType
    Label:
      en: SLB Instance Specification
      zh-cn: 负载均衡实例规格
    AssociationPropertyMetadata:
      ZoneId: ${ZoneId}
Resources:
  SecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      SecurityGroupName: securityGroup
      VpcId:
        Ref: VpcId
      SecurityGroupIngress:
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          SourceCidrIp: 192.168.0.0/24
          NicType: intranet
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          SourceCidrIp: 100.64.0.0/10
          NicType: intranet
  WaitCondition:
    Type: ALIYUN::ROS::WaitCondition
    Properties:
      Count: 1
      Handle:
        Ref: WaitConditionHandle
      Timeout: 300
  EcsInstanceGroup:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      InstanceChargeType:
        Ref: PayType
      PeriodUnit:
        Ref: PayPeriodUnit
      Period:
        Ref: PayPeriod
      IoOptimized: optimized
      SystemDiskCategory: cloud_essd
      SystemDiskSize: 200
      DiskMappings:
        - Category: cloud_essd
          Size: 200
      VpcId:
        Ref: VpcId
      ZoneId:
        Ref: ZoneId
      SecurityGroupId:
        Ref: EcsSecurityGroup
      VSwitchId:
        Ref: VSwitchId
      MaxAmount: 2
      ImageId: centos_7
      InstanceType:
        Ref: EcsInstanceType
      Password:
        Ref: InstancePassword
      AllocatePublicIP: false
      UserData:
        Fn::Sub:
          - |
            #!/bin/bash
            # Mount the disk to /disk1
            cat >> /root/InitDataDisk.sh << "EOF"
            #!/bin/bash
            echo "p
            n
            p
            w
            " |  fdisk -u /dev/vdb
            EOF
            /bin/bash /root/InitDataDisk.sh
            rm -f /root/InitDataDisk.sh
            rm -f InitDataDisk.sh
            mkfs -t ext4 /dev/vdb1
            cp /etc/fstab /etc/fstab.bak
            mkdir /disk1
            echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\\\"//g'` /disk1 ext4 defaults 0 0 >> /etc/fstab
            mount -a

            # Configure the installation script here
            yum install -y nginx
            # Configure the startup script
            systemctl start nginx.service

            # Execute the success callback to end the WaitCondition wait
            ${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
          - CurlCli:
              Fn::GetAtt:
                - WaitConditionHandle
                - CurlCli
  Slb:
    Type: ALIYUN::SLB::LoadBalancer
    Properties:
      VpcId:
        Ref: VpcId
      VSwitchId:
        Ref: VSwitchId
      LoadBalancerName:
        Fn::Join:
          - '-'
          - - slb
            - Ref: ALIYUN::StackName
      PayType:
        Ref: PayType
      PricingCycle:
        Ref: PayPeriodUnit
      Duration:
        Ref: PayPeriod
      AddressType: intranet
      LoadBalancerSpec:
        Ref: LoadBalancerSpec
      AutoPay: true
  EipSlbAddress:
    Type: ALIYUN::VPC::EIP
    Properties:
      Name:
        Ref: ALIYUN::StackName
      InternetChargeType: PayByTraffic
      Bandwidth: 100
  EipSlbAddressAssociation:
    Type: ALIYUN::VPC::EIPAssociation
    Properties:
      InstanceId:
        Ref: Slb
      AllocationId:
        Ref: EipSlbAddress
  SlbBackendServerAttachment:
    DependsOn:
      - EcsInstanceGroup
    Type: ALIYUN::SLB::BackendServerAttachment
    Properties:
      BackendServerList:
        Fn::GetAtt:
          - EcsInstanceGroup
          - InstanceIds
      LoadBalancerId:
        Ref: Slb
      BackendServerWeightList:
        - 100
        - 100
  SlbListener:
    DependsOn:
      - Slb
    Type: ALIYUN::SLB::Listener
    Properties:
      Persistence:
        CookieTimeout: 60
        StickySession: 'on'
        PersistenceTimeout: 180
        XForwardedFor: 'off'
        StickySessionType: insert
      ListenerPort: 80
      Bandwidth: -1
      HealthCheck:
        HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
        HealthCheckType: tcp
        UnhealthyThreshold: 3
        Timeout: 5
        HealthyThreshold: 3
        Port: 80
        URI: /
        Interval: 2
      LoadBalancerId:
        Ref: Slb
      BackendServerPort: 80
      Protocol: tcp
Outputs:
  Endpoint:
    Description:
      zh-cn: 对外暴露的公网IP地址
      en: The public IP address.
    Value:
      Fn::Sub:
        - http://${ServerAddress}
        - ServerAddress:
            Fn::GetAtt:
              - EipSlbAddress
              - EipAddress
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - ZoneId
        Label:
          default:
            zh-cn: 可用区配置
            en: Zone Configuration
      - Parameters:
          - VpcId
          - VSwitchId
        Label:
          default:
            zh-cn: 选择已有基础资源配置
            en: Existing Infrastructure Configuration
      - Parameters:
          - PayType
          - PayPeriodUnit
          - PayPeriod
        Label:
          default:
            en: Billing Configuration
            zh-cn: 付费类型
      - Parameters:
          - EcsInstanceType
          - InstancePassword
        Label:
          default:
            en: Instance Configuration
            zh-cn: ECS实例配置
      - Parameters:
          - LoadBalancerSpec
        Label:
          default:
            en: SLB Configuration
            zh-cn: 负载均衡配置