什么是通过SNMP显示浮点数的好方法? [英] What is a good way to show a floating point number via SNMP?
问题描述
我有几个选项:
- 截断数字。
- 乘以一个常量。
- 询问Stackoverflow。
如果我截断了这个数字,我就会失去很多我需要的信息。
如果我乘以不变,那么经理将会显示最终用户不希望看到的奇怪单位。 (克而不是公斤)。
因此,我正在做选项3.我该怎么做? 解决方案
通常的标准方法是定义一个整型(如Integer32或Unsigned32)的TEXTUAL-CONVENTION和一个带dN格式的DISPLAY-HINT,其中N是小数点应该移动的位数,用于显示目的。
因此,对于一个小数位数(从0.0到10.0)的值,使用Unsigned32(0..100)型的TEXTUAL-CONVENTION和DISPLAY-HINT的d-1。在线路上,取值范围为0到100,但管理员(通过加载的MIB模块)会将小数点后一位移到显示范围0.0到10.0之间。
这样做的其他方式不利于互操作性。
I am coding an SNMP Agent. I need to send values that have a decimal point to an SNMP Manager.
I have a couple options:
- Truncate the number.
- Multiply by a constant.
- Ask Stackoverflow.
If I truncate the number I lose a lot of information that I need.
If I multiply by a constant, then the manager will display strange units that the end-user would rather not see. (grams instead of kilograms).
So, I'm doing option 3. What do I do?
The usual, standard way this is done is to define a TEXTUAL-CONVENTION with an integral type (such as Integer32 or Unsigned32) and a DISPLAY-HINT with "d-N" format, where N is the number of places the decimal should be shifted for display purposes.
Thus, for a value with a single decimal place ranging from (say) 0.0 to 10.0, you would use a TEXTUAL-CONVENTION of type Unsigned32(0..100) and a DISPLAY-HINT of "d-1". On the wire, the value ranges from 0 to 100, but the manager (by way of the MIB module being loaded) will shift the decimal one place to display a range of 0.0 to 10.0.
Other ways of doing it are not conducive to interoperability.
这篇关于什么是通过SNMP显示浮点数的好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!