【问题标题】:How can I use appInsights with HDInsight cluster如何将 appInsights 与 HDInsight 群集一起使用
【发布时间】:2020-08-03 17:32:17
【问题描述】:

我在 azure hdinsight 上有一个火花簇。有什么方法可以将 azure applicationInsights 与其集成以获取所有监视和日志分析功能。这可以根据 Microsoft 文档通过 Azure Monitor Logs 完成,但由于某种原因,我需要专门将 hdinsight 上的 spark 应用程序与 applicationInsights 集成。在任何地方都找不到相同的文档或示例。

【问题讨论】:

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


    【解决方案1】:

    很遗憾,您无法使用 Application Insight 获取 HDInsight 群集的日志。

    Azure Monitor 日志可将 HDInsight 集群等多种资源生成的数据收集并聚合在一个地方,以实现统一的监控体验。

    作为先决条件,您需要一个 Log Analytics 工作区来存储收集的数据。如果您还没有创建,可以按照此处的说明进行操作:Create a Log Analytics Workspace

    Azure Monitor、Log Analytics 和 应用洞察?

    2018 年 9 月,Microsoft 将 Azure Monitor、Log Analytics 和 Application Insights 合并到一个服务中,为您的应用程序及其所依赖的组件提供强大的端到端监控。 Log Analytics 和 Application Insights 中的功能没有改变,但某些功能已更名为 Azure Monitor,以更好地反映其新范围。 Log Analytics 的日志数据引擎和查询语言现在称为 Azure Monitor Logs。见Azure Monitor terminology updates

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

    【讨论】:

    • 感谢您的回答。我已经回答了我的问题并提到了使用 applicationinsights-logging-log4j 依赖项从 hdInsight 集群获取 scala+spark 应用程序日志到 AppInsights 的方法。
    【解决方案2】:

    找到了一种使 ApplicationInsights 与 HdInsight (Spark) 集群配合使用的方法。部署在集群上的应用程序是一个用 Scala(基于 maven)编写的 Spark 应用程序。尽管微软目前还没有适用于 Scala 的 SDK,但我能够使用 applicationinsights-logging-log4j 依赖项将应用程序日志以及 spark yarn 日志发送到 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")
    

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

    Logs seen on AppInsights

    Exception logs seen on AppInsights

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      • 2020-03-09
      相关资源
      最近更新 更多