カスタム・メトリックの公開

カスタム・メトリックは、データを収集および分析するために設計するメトリックです。

次を参照してください:

カスタム・メトリックの公開の前提条件

  • 次の必要なポリシーを追加します。環境の変数を置換してネームスペースを作成し、メトリックをモニタリング・サービスにプッシュする権限をユーザー・グループに付与します。

    • グループ<group-name>に、target.metrics.namespace='<namespace-name>'のテナンシでのメトリックの使用を許可します
    • グループ<group-name>にテナンシのメトリックの読取りを許可します
    • グループ<group-name>にテナンシのメトリックの検査を許可します
    • グループ<group-name>に、target.metrics.namespace='<namespace-name>'のテナンシのメトリックの管理を許可します
  • APIキーの生成。ビッグ・データ・サービスは、ユーザー・プリンシパル認証を使用して、REST APIまたはSDKを介してOCIモニタリング・サービスと通信します。

  • Ambari APIを使用して必要なメトリックをフェッチするためのAmbariユーザー資格証明。

カスタム・メトリックの公開の例

  1. サービスAPIを監視するために必要なペイロードを構築し、前提条件の一部として作成されたユーザー資格証明を使用してメトリック・ペイロードをモニタリング・サービスにプッシュします。
  2. Ambari API / Ambari-Metric-Collectorを使用してメトリックをフェッチするには、次のサンプル・コードを参照してください。「必要なメトリックのフェッチ」を参照してください。
    // Pass all the required user creds (Generated in pre-requisite step1) to AuthProvider.
     
    AuthenticationDetailsProvider provider =
                    SimpleAuthenticationDetailsProvider.builder()
                            .tenantId(TENANCY_ID)
                            .userId(USER_ID)
                            .fingerprint(FINGERPRINT)
                            .passPhrase(PASS_PHRASE)
                            .privateKeySupplier(
                                    () -> {
                                        try {
                                            return new FileInputStream(PRIVATE_KEY_PATH);
                                        }
                                        catch (IOException ie) {
                                            throw new RuntimeException(
                                                    String.format("Unable to find private key file %s", PRIVATE_KEY_PATH), ie);
                                        }
                                    })
                            .build();
     
            MonitoringClient monitoringClient = new MonitoringClient(provider);
            monitoringClient.setRegion(REGION);
     
    // Set the monitoring service end point : https://telemetry-xyz.com
     
            monitoringClient.setEndpoint(MONITORING_CLIENT_ENDPOINT);
            
    // Fetch metrics using Ambari API. Pass all the required userInfo to get Metrics from Ambari metric API. 
       Here Url can be any service metrics url : https://<Ambari>:<port>/api/v1/clusters/ClusterName/services/HDFS/components/NAMENODE. 
       This API returns json as response. User can extract required metrics example metrics/jvm/memHeapCommittedM,metrics/jvm/memHeapUsedM; 
       convert it to any Object. Ex: Here it is  Map<url,Map<MetricName, MetricData>>
     
            Map<String, Map<String, MetricData>> metrics = getMetrics(url, sslContext, userInfo);
     
    // Iterate over the metric data, construct the payload and push to monitoring service
     
            List<MetricDataDetails> metricDataDetailsList = new ArrayList<>();
            for (Map.Entry<String, Map<String, MetricData>> entry : metrics.entrySet()) {
                String url = entry.getKey();
                Map<String, MetricData> metricMap = entry.getValue();
                for (Map.Entry<String, MetricData> metricMapEntry : metricMap.entrySet()) {
                    HashMap<String, String> dimensions = Maps.newHashMap();
                    String metricName = metricMapEntry.getKey();
                    MetricData md = metricMapEntry.getValue();
                   // These dimensions can be used to filter metrics in OCI metric monitoring console
                    dimensions.put("resourceId", md.getResourceId());
                    dimensions.put("nodeHostName", md.getHostname());
                    dimensions.put("metricType", md.getMetrictype()); // Can be Cluster/Host/Component/Host-Component.
                    dimensions.put("clusterName", md.getClusterName());
                    dimensions.put("serviceName", md.getServiceName()); // Ex: HDFS
                    dimensions.put("componentName", md.getComponentName()); // Ex: DATANODE,NAMENODE
                    metricDataDetailsList.add(MetricDataDetails.builder()
                            .namespace(METRIC_NAMESPACE) // This is the custom namespace where user wants to push the metrics
                            .compartmentId(COMPARTMENT_ID) // Compartment Id in tenancy.
    //                        .resourceGroup("resourceGroup1") // optional, replace with your resource group
                            .name(metricName) // Name of the metric
                            .dimensions(dimensions) // Dimensions of metric like resourceId, hostname etc.,
                            .datapoints(Arrays.asList(Datapoint.builder().timestamp(md.getTimestamp())
                                    .value(Double.valueOf(md.getValue())).count(1).build())) // data points like value, timestamp, 
                                       count of the metric.
                            .build());
                }
            }
     
    // Create MetricData request.
            PostMetricDataRequest postMetricDataRequest =
                    PostMetricDataRequest.builder()
                            .postMetricDataDetails(
                                    PostMetricDataDetails.builder()
                                            .metricData(metricDataDetailsList)
                                            .build())
                            .build();
     
    // Push the metrics to monitoring service using client.
     
            PostMetricDataResponse response = monitoringClient.postMetricData(postMetricDataRequest);
        }
     
    // url is Ex:https://<Ambari>:<port>/api/v1/clusters/ClusterName/services/HDFS/components/NAMENODE. sslcontext, UserInfo objects to 
       communicate with Ambari server API.
       private String getMetrics(String url, SSLContext sslContext, UserInfo ambariServerInfo)
                throws IOException
        {
            URL obj = new URL(url);
            HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
     
            con.setSSLSocketFactory(sslContext.getSocketFactory());
            con.setRequestMethod("GET");
            con.setRequestProperty("Authorization", "Basic " + encodeCredentials(ambariServerInfo.getUsername(), ambariServerInfo.getPassword()));
     
            int responseCode = con.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();
     
                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();
     
                return response.toString();
            }
            else {
                throw new IOException("HTTP GET request failed with error code: " + responseCode);
            }
        }   
  3. OCIモニタリング・コンソールからメトリックを表示します。公開済メトリックの表示を参照してください。
    ノート

    前提条件に記載されている必要なポリシー・ステートメントを更新すると、メトリックをモニタリング・サービスにプッシュすると、カスタムの新しいネームスペースが自動的に作成されます。

公開済メトリックの表示

OCIモニタリング・サービス・コンソールのメトリック・エクスプローラから、公開されたメトリックを表示します。

公開されているメトリックを表示するには、問合せの作成を参照してください。

カスタム・メトリックのアラームを作成するには、カスタム・メトリック・チャートからのアラームの作成を参照してください。