如何将appInsights与HDInsight群集一起使用

时间:2020-07-15 05:37:39

标签: azure azure-application-insights azure-hdinsight

我在天蓝色hdinsight上有一个火花集群。有什么方法可以将Azure的applicationInsights与之集成,以获得所有的监视和日志分析功能。可以根据Microsoft文档通过Azure Monitor日志来完成此操作,但是由于某些原因,我需要仅将hdapp上的spark应用程序与applicationInsights集成。在任何地方都找不到相同的文档或示例。

2 个答案:

答案 0 :(得分:0)

不幸的是,您不能使用Application Insight获取HDInsight群集的日志。

Azure Monitor日志可将由多种资源(例如HDInsight群集)生成的数据收集到一个地方并进行汇总,以实现统一的监视体验。

先决条件是,您需要一个Log Analytics Workspace来存储收集的数据。如果尚未创建一个,则可以按照以下说明操作:Create a Log Analytics Workspace

Azure Monitor,Log Analytics和 应用洞察力?

2018年9月,Microsoft将Azure Monitor,Log Analytics和Application Insights合并到一项服务中,以对应用程序及其依赖的组件提供强大的端到端监视。尽管某些功能已重命名为Azure Monitor,以便更好地反映其新范围,但Log Analytics和Application Insights中的功能并未更改。 Log Analytics的日志数据引擎和查询语言现在称为Azure Monitor日志。参见Azure Monitor terminology updates

我可以将Application Insights与...一起使用吗?

答案 1 :(得分:0)

找到了一种使ApplicationInsights与HdInsight(Spark)集群一起工作的方法。部署在集群上的应用程序是用Scala(基于Maven)编写的Spark应用程序。尽管Microsoft目前还没有适用于Scala的SDK,但我仍然能够使用applicationinsights-logging-log4j依赖关系将应用程序日志以及火花纱日志发送到AppInsights,这是我的最终目标。

方法如下:

  1. 将这些依赖项添加到pom.xml

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>applicationinsights-core</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>applicationinsights-logging-log4j1_2</artifactId>
        <version>2.6.1</version>
    </dependency>
    
  2. 使用ApplicationInsightsAppender类

import org.apache.log4j.{ Logger, Level }
  import com.microsoft.applicationinsights.log4j.v1_2.ApplicationInsightsAppender

    object AppInsightLogger {
    var rootLogger = Logger.getRootLogger()
    var ai = new ApplicationInsightsAppender()
    ai.setInstrumentationKey("your-key")
    ai.activateOptions()


    @transient lazy val logger = Logger.getLogger(this.getClass)
    logger.setLevel(Level.INFO)
    rootLogger.addAppender(ai)
  
    def info(message: String): Unit = {
       logger.info(message)
    }

  }

最后,它可以在应用程序中的任何地方使用,例如:

    AppInsightLogger.info("Streaming messages from EH")

我能够将Spark纱线日志以及自定义日志从HdInsight上部署到AppInsights的应用程序中获取,而无需将SDK用于Scala! (使用这种方法无法看到仪表板和遥测数据。我们将日志记录为具有不同严重性级别的“跟踪”。也可以查看异常(如果有)。使用门户网站上的“搜索”选项查看日志)< / p>

Logs seen on AppInsights

Exception logs seen on AppInsights