`
mryufeng
  • 浏览: 982699 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Making a Mnesia Table SNMP Accessible

阅读更多
原文地址: http://www.drxyzzy.org/mnesia-snmp/index.html
手册写的巨明白

Contents

Introduction
Define a Mnesia Table
Create the MIB File
Create the .funcs File
Compile the MIB for OTP
Create sys.config and .conf Files
Create MIB Header for Mnesia
Create Data Directory for Mnesia
Create Erlang Program
Start OTP with Mnesia and SNMP agent
Access the Table from net-snmp
References
Introduction

We occasionally make mnesia data readable via SNMP. Here's a cookbook summary of the process. Certainly the Ericsson guide listed in the references should be consulted - this page merely gives extensive detail for a sample case.

Complete directions are given for creating a sample table, configuring the MIB, relating the two, and accessing the table from a net-snmp client.

Limitations of this tutorial.

SNMP versions 1&2, but not 3, are used.
SMIv1 is used to write the MIB.
The SNMP agent listens on non-privileged port 9161, instead of 161.
Code was compiled and executed using FreeBSD-5.0, OTP-R9B1, and Net-SNMP-5.0.8_1.

Define a Mnesia Table

For this example, use a table for several servers which handle telephone calls. Each row contains the server name, plus two counters - the number of inbound calls and the number of outbound calls. Here's an .hrl file defining the record type:

serverTable.hrl.

Create the MIB File

This example places the monitored data in the SNMP OID tree under iso.org.dod.internet.private.enterprises. Filename must end with ".mib". We use a fictional enterprise name of "bazmatic" with enterprise number 99999. See references below if you need an official enterprise number. Server names will be read-only from SNMP. Call counters will be writable from SNMP.

SAMPLE-MIB.mib.

Create the .funcs File

Since default mnesia functions are used, this step could probably be omitted if RowStatus were used.

SAMPLE-MIB.funcs.

Compile the MIB for OTP

Shell command for compiling the MIB.

/usr/home/xxx/otp-snmp>erl
Erlang (BEAM) emulator version 5.2.3.3 [source] [hipe] [threads:0]

Eshell V5.2.3.3  (abort with ^G)
1> snmp:c("SAMPLE-MIB", [{db, mnesia}]).
{ok,"./SAMPLE-MIB.bin"}
Result is binary file SAMPLE-MIB.bin.

Create sys.config and .conf Files

Continuing the previous erl session:

2> snmp:config().

Simple SNMP configuration tool (v3.0)
----------------------------------------------
Note: Non-trivial configurations still has to be done manually.
IP addresses may be entered as dront.ericsson.se (UNIX only) or 123.12.13.23

1. System name (sysName standard variable) [xxx's agent]sample agent
2. Engine ID (snmpEngineID standard variable)[xxx's engine]sample engine
3. The UDP port the agent listens to. (standard 161) [4000]9161
4. IP address for the agent (only used as id
   when sending traps) []127.0.0.1
5. IP address for the manager (only this manager will have access
   to the agent, traps are sent to this one) []127.0.0.1
6. To what UDP port at the manager should traps
   be sent (standard 162)? [5000]9162
7. What SNMP version should be used (1,2,3,1&2,1&2&3,2&3)? [3]1&2
8. Do you want a none- minimum- or semi-secure configuration?
   Note that if you chose v1 or v2, you won't get any security for these
   requests (none, minimum, semi) [minimum]
9. Where is the configuration directory (absolute)? [/usr/home/xxx/otp-snmp]
10. Current configuration files will now be overwritten. Ok [y]/n?y
------------------------
Info: 1. SecurityName "initial" has noAuthNoPriv read access and authenticated write access to the "restricted" subtree.
      2. SecurityName "all-rights" has noAuthNoPriv read/write access to the "internet" subtree.
      3. Standard traps are sent to the manager.
      4. Community "public" is mapped to security name "initial".
      5. Community "all-rights" is mapped to security name "all-rights".
The following files were written: agent.conf, community.conf,
   standard.conf, target_addr.conf, target_params.conf,
   notify.conf vacm.conf, sys.config
------------------------
ok
Result is the following files: agent.conf, community.conf, context.conf, notify.conf, standard.conf, sys.config, target_addr.conf, target_params.conf, vacm.conf.

Create MIB Header for Mnesia

3> snmp:mib_to_hrl("SAMPLE-MIB").
"SAMPLE-MIB.hrl" written.
ok
Result is file SAMPLE-MIB.hrl.

Create Data Directory for Mnesia

Will use non-volatile storage (disc_copies) for convenience. Designate a directory on disk where the table will be stored.
mkdir /tmp/db
Create Erlang Program

Here is a tiny Erlang module with functions to create the table in Mnesia, get and set values in the table, and start the snmp agent.

snmp_sample.erl.

Start OTP with Mnesia and SNMP agent

Here is the transcript of an Erlang shell session starting things up:

erl -mnesia dir '"/tmp/db"' -config ./sys -name sample
(sample@xyz.com)1> c(snmp_sample).
{ok,snmp_sample}
(sample@xyz.com)2> mnesia:create_schema([node()]).
ok
(sample@xyz.com)3> mnesia:start().
ok
(sample@xyz.com)4> snmp_sample:create_table().
{atomic,ok}
(sample@xyz.com)5> snmp_sample:set_counts("srv01",3,44).
ok
(sample@xyz.com)6> snmp_sample:get_counts().           
[[{serverTable,"srv01",3,44}]]
(sample@xyz.com)7> snmp_sample:init_snmp().
<0.140.0>
(sample@xyz.com)8> snmp_mgr:g([[1,3,6,1,2,1,1,1,0]]).
ok
* Got PDU: v1, CommunityName = "public"
Response,         Request Id:112362370
(sample@xyz.com)9> snmp_mgr:gn([[1,3,6,1,4,1,99999,1]]). 
ok
* Got PDU: v1, CommunityName = "public"
Response,         Request Id:38817076
  [name,5,115,114,118,48,49] = "srv01"
(sample@xyz.com)10>
Access the Table from net-snmp

Here is an example of a Bourne shell script reading and setting counter values.

First, the script:

# snmpops.sh

# Point MIBDIRS at directory containing the MIB for this example.
MIBDIRS=+/home/xxx/otp-snmp
MIBS=+SAMPLE-MIB
export MIBDIRS MIBS

snmpwalk -Ob -Cc -v 1 -c public localhost:9161 \
  .iso.org.dod.internet.private.enterprises.bazmatic

snmpget -Os -v 1 -c public localhost:9161 \
  .iso.org.dod.internet.private.enterprises.bazmatic.serverTable.serverEntry.callsIn.5.115.114.118.48.49

snmpset -Os -v 1 -c all-rights localhost:9161 \
  .iso.org.dod.internet.private.enterprises.bazmatic.serverTable.serverEntry.callsIn.5.115.114.118.48.49 = 22

snmpget -Os -v 1 -c public localhost:9161 \
  .iso.org.dod.internet.private.enterprises.bazmatic.serverTable.serverEntry.callsIn.5.115.114.118.48.49
Then, the results:

SAMPLE-MIB::name.5.115.114.118.48.49 = STRING: "srv01"
SAMPLE-MIB::callsIn.5.115.114.118.48.49 = INTEGER: 3
SAMPLE-MIB::callsOut.5.115.114.118.48.49 = INTEGER: 44
callsIn."srv01" = INTEGER: 3
callsIn."srv01" = INTEGER: 22
callsIn."srv01" = INTEGER: 22
References

Application for Private Enterprise Number
Erlang/OTP SNMP User's Guide See Chapter 6 - Implementation Example
Standard Names for Versions of the SNMP Protocol
revised Jul 22, 2003 - Hal Snyder & Josh Snyder
分享到:
评论

相关推荐

    Mnesia table fragmentation 过程及算法分析

    为了解决这个问题,Mnesia 提供了表分片(table fragmentation)的功能。通过使用 Linear Hashing 算法,Mnesia 可以将大表分散存储在多个节点上,从而提高表的可扩展性和性能。 在分析 Mnesia 表分片的过程和算法...

    Mnesia User's Guide

    session, specify a Mnesia database directory, initialize a database schema, start Mnesia, and create tables. Initial prototyping of record definitions is also discussed. • Build a Mnesia Database ...

    erlang——Mnesia用户手册.pdf

    8.附录.A:Mnesia.错误信息 8.1.Mnesia.中的错误 9.附录.B:备份回调函数接口 9.1.Mnesia.备份回调行为 10.附录.C:作业存取回调接口 10.1.Mnnesia.存取回调行为 11.附录.D:分片表哈希回调接口 11.1....

    Mnesia用户手册 4.4.10版.rar

    8 附录 A : Mnesia 错误信息 . . .. . . 75 8.1 Mnesia 中的错误 . . . . .. . 75 9 附录 B :备份回调函数接口 . . .. . .. . . .. . 76 9.1 Mnesia 备份回调行为 . . .. . . . .. . 76 10 附录 C :作业存取...

    amnesia:失忆备忘录

    B站视频地址: 做了文字校验,已经成功上线,有兴趣的小伙伴可以扫码体验:可以微信搜索:失忆备忘录一、失忆的由来之所以开发这款软件,是因为在那段时间事情很多,但是经常忘记。虽然市面上类似的功能很多,我之前...

    amnesia-开源

    AMNESIA是一个基于Erlang编程语言的开源库,专门设计用于简化与关系数据库管理系统(RDBMS)的交互。Erlang以其并发处理、容错性和高效性能在分布式系统领域备受推崇,而AMNESIA则进一步扩展了Erlang的功能,使...

    Api-Social-Amnesia.zip

    Api-Social-Amnesia.zip,忘记过去。社交健忘症确保你的社交媒体帐户只显示你最近的历史,而不是5年前“那个阶段”的帖子。,一个api可以被认为是多个软件设备之间通信的指导手册。例如,api可用于web应用程序之间的...

    Mnesia用户手册.zip

    《Mnesia用户手册》是专为理解和操作Erlang编程语言中的Mnesia数据库管理系统而编写的详尽指南。Mnesia是Erlang OTP (Open Telephony Platform) 库中的一个核心组件,它是一个强大的分布式数据库系统,特别适用于...

    Mnesia 用户手册中文版 pdf

    除此之外,Mnesia支持与SNMP(简单网络管理协议)的结合,使得可以监控和管理网络设备。 Mnesia的错误信息处理、备份回调函数接口、作业访问回调接口和分片表哈希回调接口分别在附录中进行了详细说明,这些都是使用...

    Mnesia用户手册(docx版)

    - **数据模型**:Mnesia 支持两种主要的数据模型:*正交表(Table)* 和 *活动数据表(Active Data Table, ADT)*。正交表用于存储静态数据,而ADT则用于动态数据,支持实时更新和查询。 - **启动 Mnesia**:启动...

    Chrome Amnesia-crx插件

    语言:English (United States) 遗忘的延伸 Chrome失忆症是一个Chrome扩展程序,可让您有选择地不记得自己的任何浏览历史记录。...有关更多信息,请访问https://github.com/DanielBok/chrome-amnesia。

    mnesia数据库文档

    ### Mnesia数据库:Erlang中的分布式数据库管理系统 #### 引言 Mnesia,作为Erlang编程语言的一部分,是一款由爱立信公司开发的分布式数据库管理系统(DBMS)。自1997年以来,Mnesia一直是Open Telecom Platform...

    Amnesia-开源

    失忆症是一种提醒,允许您定义警报,贴纸(贴子)以提醒您一些重要的内容以及有关所需内容的注释。 可以将警报编程为在给定时间显示,可以在桌面上放置贴纸以随时查看。

    Erlang Mnesia

    ### Erlang Mnesia:分布式数据库管理系统 #### 一、引言与概述 Mnesia是一款由爱立信(Ericsson)开发并维护的分布式数据库管理系统(DBMS),它被设计用于支持电信应用以及其他需要持续运行和具备软实时特性的...

    Amnesia

    "Amnesia"是一个可能与计算机安全或数据丢失相关的主题,暗示了系统或用户可能遭遇了某种形式的记忆丧失,即数据无法访问或丢失的情况。在IT领域,这种情况通常涉及到磁盘故障、病毒攻击、误操作或者软件错误。"Post...

Global site tag (gtag.js) - Google Analytics