sjyang18 commented on a change in pull request #3817: NIFI-6583: adding azure log analytics reporting task to nifi-azure-bu… URL: https://github.com/apache/nifi/pull/3817#discussion_r337785670
########## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/main/java/org/apache/nifi/reporting/azure/loganalytics/AzureLogAnalyticsReportingTask.java ########## @@ -0,0 +1,335 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.reporting.azure.loganalytics; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import javax.xml.bind.DatatypeConverter; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.nifi.annotation.configuration.DefaultSchedule; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.controller.status.ConnectionStatus; +import org.apache.nifi.controller.status.ProcessGroupStatus; +import org.apache.nifi.controller.status.ProcessorStatus; +import org.apache.nifi.expression.ExpressionLanguageScope; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.reporting.AbstractReportingTask; +import org.apache.nifi.reporting.ReportingContext; +import org.apache.nifi.reporting.azure.loganalytics.api.AzureLogAnalyticsMetricsFactory; +import org.apache.nifi.scheduling.SchedulingStrategy; +import org.apache.nifi.annotation.lifecycle.OnScheduled; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.metrics.jvm.JmxJvmMetrics; +import org.apache.nifi.metrics.jvm.JvmMetrics; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + + +/** + * ReportingTask to send metrics from Apache NiFi and JVM to Azure Monitor. + */ +@Tags({"reporting", "loganalytics", "metrics"}) +@CapabilityDescription("Sends JVM-metrics as well as Apache NiFi-metrics to a Azure Log Analytics workspace." + + "Apache NiFi-metrics can be either configured global or on process-group level.") +@DefaultSchedule(strategy = SchedulingStrategy.TIMER_DRIVEN, period = "1 min") +public class AzureLogAnalyticsReportingTask extends AbstractReportingTask { + + private static final String JVM_JOB_NAME = "jvm_global"; + private static final Charset UTF8 = Charset.forName("UTF-8"); + private static final String HMAC_SHA256_ALG = "HmacSHA256"; + static final DateTimeFormatter RFC_1123_DATE_TIME = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss O"); + private volatile JvmMetrics virtualMachineMetrics; + + + static final PropertyDescriptor LOG_ANALYTICS_WORKSPACE_ID = new PropertyDescriptor.Builder() + .name("Log Analytics Workspace Id") + .description("Log Analytics Workspace Id") + .required(true) + .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .sensitive(true) + .build(); + static final PropertyDescriptor LOG_ANALYTICS_CUSTOM_LOG_NAME = new PropertyDescriptor.Builder() + .name("Log Analytics Custom Log Name") + .description("Log Analytics Custom Log Name") + .required(false) + .defaultValue("nifimetrics") + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) + .build(); + static final PropertyDescriptor LINUX_PRIMARY_KEY = new PropertyDescriptor.Builder() + .name("Linux Primary Key") + .description("Connected Sources - Linux Primary Key") Review comment: This is the shared key getting from azure log analytic workspace. https://www.systemcenterautomation.com/2018/05/find-azure-log-analytics-keys/ ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
