文章
· 二月 3, 2023 阅读大约需 5 分钟

第六十五章 使用 SNMP 监控 IRIS - 用户定义的 SNMP 监视器类示例

第六十五章 使用 SNMP 监控 IRIS - 用户定义的 SNMP 监视器类示例

本节介绍如何定义可通过 SNMP 查询的用户应用程序监视器类的示例。应用程序监视器仅包括 SNMP 数据中具有 %Monitor 数据类型的属性。

Example Sample Class

以下是此示例的示例类:

Class SNMP.Example Extends %Monitor.Adaptor
{

  /// Give the application a name. This allows you to group different 
  /// classes together under the same application level in the SNMP MIB.
  /// The default is the same as the Package name.
  Parameter APPLICATION = "MyApp";

  /// This groups a set of properties together at the "table" level of the
  /// SNMP MIB hierarchy. The default is the Class name.
  Parameter GROUPNAME = "MyTable";

  /// An integer metric counter
  Property Counter1 As %Monitor.Integer;

  /// Another integer metric counter
  Property Counter2 As %Monitor.Integer;

  /// A status indicator as a string data type
  Property Status As %Monitor.String;

  /// The method is REQUIRED. It is where the Application Monitor
  /// calls to collect data samples, which then get picked up by the
  /// ^SNMP server process when requested.
  Method GetSample() As %Status
  {
    set ..Counter1=$r(200)
    set ..Counter2=200+$r(100)
    set n=$r(4)
    set ..Status=$s(n=1:"Crashed",n=2:"Warning",n=3:"Error",1:"Normal")
    Quit $$$OK
  }

}

在用户命名空间中编译此类之前, IRIS 必须将支持类加载到命名空间中;需要这些类来存储 SNMP 的数据样本。

要加载这些类,请运行 ^%SYSMONMGR,如本指南“使用系统监视器”一章中使用 ^%SYSMONMGR 管理应用程序监视器中所述,并执行以下操作:
- 选择选项 2,管理监视器类。
- 选择选项 3Register Monitor System Classes

编译示例类时,它会创建 SNMP.Sample.Example 类来存储示例数据。

重要提示:不要明确删除生成的示例类;如果同时选择删除应用监控和生成的示例类,虽然删除了监控类例程,但示例类例程仍然存在,这会导致错误。为确保正确删除所有示例类例程,只删除生成它的应用程序监视器类;当您删除监视器类时,监视器类和生成的示例类以及这两个类的相关例程都会被删除。例如,要删除示例类(例如 SNMP.Sample.Example),请使用管理门户删除生成它的监视器类(即 SNMP.Example)。

运行 ^%SYSMONMGR 以激活示例类并启动应用程序监视器以收集示例:

  1. 选择选项 2,管理监视器类。
  2. 选择选项 1,激活/停用监视器类。
  3. 要查看已注册监视器类的编号列表,请输入 ?
  4. 输入要激活的监控类的数量;例如,要激活名为 SNMP.Example 的用户定义类,请在类名旁边输入数字。
  5. 选择选项 6,Exit(返回到 Application Monitor 主菜单)。
  6. 选择选项 1,管理应用程序监视器。
  7. 选择选项 1,启动应用程序监视器。
  8. 选择选项 5,Exit(返回到 Application Monitor 主菜单)。
  9. 选择选项 6,Exit(退出 Application Monitor 主菜单)。

注意:有关配置和使用应用程序监视器的信息,请参阅本指南“使用系统监视器”一章中的应用程序监视器。

Example of Creating a User MIB

要创建 SNMP MIB,请从 %SYS 命名空间运行 MonitorTools.SNMP:CreateMIB 方法

该方法的输入参数类似于以下内容:

CreateMIB("MyApp","USER",99990,1,"mycorp","myapp","mc","MC-MYAPP","Unknown",1)

重要提示:请勿使用 99990 作为生产企业 ID;每个组织都应向 IANA 注册自己的 ID

USER>set $namespace = "%SYS"

%SYS>Do ##class(MonitorTools.SNMP).CreateMIB("MyApp","USER",99990,1,"mycorp",
"myapp","mc","MC-MYAPP","Unknown",1)


Create SNMP structure for Application - MyApp

     Group - MyTable
          Counter1 = Integer
          Counter2 = Integer
          Status = String


Create MIB file for MyApp

     Generate table MyTable
          Add object Counter1
          Add object Counter2
          Add object Status


%SYS>

这会在默认目录 (install-dir\mgr\User) 中创建 MC-MYAPP.MIB 文件,可以将其加载到 SNMP 管理应用程序中。

注意:可能需要在系统上重新启动 SNMP 主代理和 IRIS ^SNMP 服务,然后才能识别此 MIB

--
-- MIB file generated for mcMyApp product.
--
-- Sep 16, 2008
--

MC-MYAPP DEFINITIONS ::= BEGIN

IMPORTS

  MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE,
  Counter32, Gauge32, Integer32
  FROM SNMPv2-SMI
  DisplayString
  FROM SNMPv2-TC
  enterprises
  FROM RFC1155-SMI
  cacheSysIndex
  FROM ISC-IRIS;


mcMyApp MODULE-IDENTITY
    LAST-UPDATED "200809161700Z"
    ORGANIZATION "mycorp"
    CONTACT-INFO "
                    Unknown"
    DESCRIPTION ""
    ::= { mycorp 1 }

mycorp OBJECT IDENTIFIER ::= { enterprises 16563 }

myappObjects OBJECT IDENTIFIER ::= { mcMyApp 1 }

--
-- Begin tables
--

-- Table myappMyTable

myappMyTable         OBJECT-TYPE
       SYNTAX        SEQUENCE OF myappMyTableR
       MAX-ACCESS    not-accessible
       STATUS        current
       DESCRIPTION
       ""
   ::= { myappObjects 1 }

myappMyTableR        OBJECT-TYPE
       SYNTAX        myappMyTableR
       MAX-ACCESS    not-accessible
       STATUS        current
       DESCRIPTION
       "Conceptual row for MyTable table."
       INDEX  { cacheSysIndex }
   ::= { myappMyTable 1 }

myappMyTableR ::=
       SEQUENCE {
        myappCounter1   Integer32
        myappCounter2   Integer32
        myappStatus   DisplayString
       }

myappCounter1        OBJECT-TYPE
       SYNTAX        Integer32
       MAX-ACCESS    read-only
       STATUS        current
       DESCRIPTION
       ""
       ::= { myappMyTableR 1 }

myappCounter2        OBJECT-TYPE
       SYNTAX        Integer32
       MAX-ACCESS    read-only
       STATUS        current
       DESCRIPTION
       ""
       ::= { myappMyTableR 2 }

myappStatus          OBJECT-TYPE
       SYNTAX        DisplayString
       MAX-ACCESS    read-only
       STATUS        current
       DESCRIPTION
       "Status"
       ::= { myappMyTableR 3 }

--  End of MyTable table

myappTraps  OBJECT IDENTIFIER ::= { mcMyApp 2 }

-------------------------------------------------------------
 END
讨论 (0)1
登录或注册以继续