为活动应用程序监视配置适配器

通用日志适配器提供了一个输出程序类,该类可以将适配器生成的公共基本事件对象发送至记录代理程序。可使用“日志和跟踪分析器”来连接至记录代理程序以便以实时方式监视和分析应用程序日志。

先决条件:

执行下列步骤来配置适配器,以便进行监视。

配置输出程序组件

注意:当创建新的适配器配置文件时,缺省情况下会将它配置为使用 CBELogOutputter 类。如果您未更改此设置,则可以跳过此过程。

您需要将适配器配置文件中的输出程序组件更新为使用 CBELogOutputter 类,该类将公共基本事件对象写至记录代理程序。您可以更新现有的输出程序组件,也可以添加新的输出程序组件。

要添加新的输出程序组件:

  1. 要编辑适配器配置文件,请在“导航器”窗格中选择适配器配置文件。单击鼠标右键,然后选择打开方式 > 适配器配置编辑器。该文件就会在编辑器中打开。
  2. 在“适配器配置编辑器”窗口中,展开适配器 > 配置 > 上下文实例节点。
  3. 右键单击“上下文实例”,然后选择添加 > 输出程序。这就在“上下文实例”中创建了新的输出程序。
  4. 输出程序类型字段中,选择 LoggingAgentOutputter
  5. 单击 agentName 属性。属性详细信息将显示在右窗格中。
  6. 将该属性值更新为期望的记录代理程序名。该名称就是您在“日志和跟踪分析器”中将看到的所要监视的记录代理程序的名称。
  7. 如果要让输出程序在将公共基本事件写至记录代理程序前等待一段时间,请添加名为 waitUntilLoggingTime 的属性并将该属性的值设置为以毫秒计的时间。要添加该属性,右键单击新创建的输出程序并选择添加 > 属性。这就在新的“输出程序”节点下面创建了一个新属性。
  8. 要启用 CBELogOutputter 类,需要在“上下文基本上下文实现”中创建相关联的输出程序组件。打开上下文 > 上下文基本实现上下文
  9. 右键单击上下文基本实现上下文并选择添加 > 组件。这就将一个新组件添加至上下文。
  10. 使用下列值配置新组件:
    名称: 上下文中的输出程序名称
    描述: 对此输出程序执行的任务的描述
    可执行的类: org.eclipse.hyades.logging.adapter.outputters.CBELogOutputter
    记录级别:输出程序组件应使用的内部记录级别。
    值 99 表示输出程序将不记录任何消息。
    值 0 表示输出程序将记录所有严重性的消息。
    建议值是 50,这表示只记录“紧急”或“致命”内部输出程序错误消息。
    角色: 输出程序
    唯一标识: 必须指向步骤 3 中在“上下文实例”中定义的输出程序。使用浏览按钮来选择正确的标识。
  11. 保存适配器配置文件更改。

配置上下文实例

如果要让日志解析器连续地监视日志文件,则需要更新适配器配置文件的上下文实例属性以执行连续操作。

  1. 要编辑适配器配置文件,请在“导航器”透视图中选择该适配器配置文件。单击鼠标右键,然后选择打开方式 > 适配器配置编辑器。该文件就会在编辑器中打开。
  2. 在编辑器窗口中,选择适配器 > 配置 > 上下文实例。“上下文实例”详细信息将显示在右窗格中。
  3. 选择连续操作复选框。
  4. 根据需要配置“最大空闲时间”和“暂停时间间隔”字段。
  5. 保存适配器配置文件更改。

启动 Java 进程以运行适配器

可以从批处理文件(在 Windows 环境中)或 shell 脚本(在非 Windows 环境中)以外部方式运行您创建的日志适配器。下列样本文件可用来启动将运行日志适配器的 Java 进程。
注意:要连接并监视由通用日志适配器创建的记录代理程序,必须在要运行通用日志适配器的系统上安装 Hyades 代理控制器,并且必须在启动通用日志适配器之前启动该代理控制器。

Windows 批处理文件:

@rem USAGE: runregex
@rem PURPOSE: Illustrates the functional capabilities of the Generic Log Adapter (GLA)
@rem run-time using an example adapter file and sample log file.
@rem ASSUMPTIONS: This batch file assumes the GLA run-time and required files are
@rem stored in the following directory structure:
@rem %GLA_HOME%\config - GLA adapter configuration files
@rem %GLA_HOME%\lib - GLA run-time and required jars
@rem %GLA_HOME%\schema - GLA adapter configuration schema files
@rem INSTRUCTIONS:
@rem If the GLA run-time and required files are stored as indicated in the
@rem assumptions section above, change the value of the %GLA_HOME%
@rem environment variable to the absolute path where the GLA run-time
@rem and required files are stored.
@rem If the GLA run-time files are stored in a plug-in (e.g. Eclipse)
@rem environment, perform the following instructions:
@rem 1) Create a temporary directory to store the GLA run-time and required files.
@rem 2) Create the config, lib, and schema directories in the temporary
@rem directory creatd in step 1)
@rem 3) Change the value of the %GLA_HOME% environment variable to the
@rem absolute path of the temporary directory created in step 1)
@rem 4) Copy the adapter files you want to run into the %GLA_HOME%\config directory.
@rem For example if you want to run the Apache adapter files then copy the
@rem Apache directory of the org.eclipse.hyades.logging.adapter.config
@rem plug-in and all of its contents to the %GLA_HOME%\config directory.
@rem 5) Copy the contents of the schema directory of
@rem org.eclipse.hyades.logging.adapter plug-in to the %GLA_HOME%\schema directory.
@rem 6) Copy the following jar files to the %GLA_HOME%\lib directory
@rem Plug-in | JAR
@rem ---------------------------------------------------
@rem org.eclipse.hyades.logging.adapter | hgla.jar
@rem org.eclipse.hyades.logging.core | hlcbe101.jar 
@rem org.eclipse.hyades.logging.core | hlcore.jar 
@rem org.eclipse.hyades.execution.remote | hexr.jar 
@rem org.eclipse.emf.ecore | ecore.jar 
@rem org.eclipse.emf.common | common.jar 

SET GLA_HOME=d:\GenericLogAdapter 
SET CONFIG_FILE=%GLA_HOME%\config\my.adapter 
@PUSHD %GLA_HOME%\config\ 
java -DGLA_HOME="%GLA_HOME%" -classpath "%GLA_HOME%\lib\hgla.jar;%GLA_HOME%\lib\hexr.jar;%GLA_HOME%\lib\hlcbe101.jar;%GLA_HOME%\lib\ecore.jar;%GLA_HOME%\lib\common.jar;%GLA_HOME%\lib\hlcore.jar" org.eclipse.hyades.logging.adapter.Adapter -ac "%CONFIG_FILE%" -cc "%CONFIG_FILE%" 
POPD


非 Windows 批处理文件:
#!/bin/sh
# USAGE: runregex.sh 
# PURPOSE: Illustrates the functional capabilities of the Generic Log Adapter (GLA) 
# run-time using an example adapter file and sample log file. 
# ASSUMPTIONS: This shell file assumes the GLA run-time and required files are 
# stored in the following directory structure: 
# %GLA_HOME%/config - GLA adapter configuration files 
# %GLA_HOME%/lib - GLA run-time and required jars 
# %GLA_HOME%/schema - GLA adapter configuration schema files 
# INSTRUCTIONS: 
# If the GLA run-time and required files are stored as indicated in the 
# assumptions section above, change the value of the %GLA_HOME% 
# environment variable to the absolute path where the GLA run-time 
# and required files are stored. 
# If the GLA run-time files are stored in a plug-in (e.g. Eclipse) 
# environment, perform the following instructions: 
# 1) Create a temporary directory to store the GLA run-time and required files. 
# 2) Create the config, lib, and schema directories in the temporary 
# directory creatd in step 1) 
# 3) Change the value of the %GLA_HOME% environment variable to the 
# absolute path of the temporary directory created in step 1) 
# 4) Copy the adapter files you want to run to the %GLA_HOME%/config directory. 
# For example, if you want to run the Apache adapter files then copy the 
# Apache directory of the org.eclipse.hyades.logging.adapter.config 
# plug-in and all of its contents to the %GLA_HOME%/config directory. 
# 5) Copy the contents of the schema directory of 
# org.eclipse.hyades.logging.adapter plug-in to the %GLA_HOME%/schema directory. 
# 6) Copy the following jar files to the %GLA_HOME%/lib directory 
# Plug-in | JAR 
# --------------------------------------------------- 
# org.eclipse.hyades.logging.adapter | hgla.jar 
# org.eclipse.hyades.logging.core | hlcbe101.jar 
# org.eclipse.hyades.logging.core | hlcore.jar 
# org.eclipse.hyades.execution.remote | hexr.jar 
# org.eclipse.emf.ecore | ecore.jar 
# org.eclipse.emf.common | common.jar 

GLA_HOME=/home/eclipse/GenericLogAdapter 
export GLA_HOME 

CONFIG_FILE="$GLA_HOME/config/my.adapter" 
export CONFIG_FILE

CUR_DIR=`pwd`
export CUR_DIR

cd "$GLA_HOME/config" 

java -DGLA_HOME="$GLA_HOME" -classpath "$GLA_HOME/lib/hgla.jar:$GLA_HOME/lib/hexr.jar:$GLA_HOME/lib/hlcbe101.jar:$GLA_HOME/lib/ecore.jar:$GLA_HOME/lib/common.jar:$GLA_HOME/lib/hlcore.jar" org.eclipse.hyades.logging.adapter.Adapter -ac "$CONFIG_FILE" -cc "$CONFIG_FILE" 

cd "$CUR_DIR"
根据需要配置文件以启动将运行适配器的 Java 进程。

监视活动应用程序日志

您现在可以监视活动应用程序日志了。

  1. 确保在首选项中启用了记录。
    1. 从主工具栏中选择窗口 > 首选项。这就打开了“首选项”向导。
    2. 从左窗格中选择概要分析和记录。这将在右窗格中装入“概要分析和记录”首选项。
    3. 在“概要分析和记录”选项下面选择启用记录

      在“概要分析和记录”的首选项窗格中选取了“启用记录”复选框

    4. 选择确定以应用更改。
  2. 在“概要分析和记录”透视图中,单击工具栏中的“概要分析”概要分析工具的图标 并选择概要分析。这就打开了“概要分析”向导。
  3. 选择连接 - Java 进程并单击列表底部的新建按钮。这就会创建新的 Java 进程配置。
  4. 单击主机选项卡并选择应用程序日志所在的主机。
    注意:要监视活动应用程序日志,代理控制器与应用程序必须在同一个系统上运行。
  5. 单击代理程序选项卡并使用方向键来选择您配置的记录代理程序。

    在概要分析首选项向导中,用户创建的记录代理程序位于左窗格中

  6. 单击应用
  7. 单击概要分析以连接至记录代理程序。
  8. 在“概要分析监视器”视图的“概要分析和记录”透视图中,选择记录代理程序。
  9. 右键单击该代理程序并选择开始监视
  10. 右键单击该代理程序并选择打开方式 > 日志视图。这就将应用程序日志中的日志事件装入到了“日志”视图中。
    注意:如果您在“日志”视图中看不到任何日志记录,请单击“概要分析监视器”窗格顶部的刷新视图按钮。

 

相关概念
通用日志适配器概述
公共基本事件格式规范

相关任务
创建日志解析器

相关参考
适配器配置文件结构
适配器配置编辑器
正则表达式语法