What is a good way to show a floating point number via SNMP?
Asked Answered
A

3

10

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:

  1. Truncate the number.
  2. Multiply by a constant.
  3. 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?

Anthozoan answered 26/1, 2010 at 20:9 Comment(0)
E
13

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.

Enrol answered 27/1, 2010 at 2:7 Comment(0)
I
3

as an octect-stream in IEEE-754 format (8 Octets). See: http://en.wikipedia.org/wiki/IEEE_754-2008

Impedance answered 26/1, 2010 at 20:15 Comment(1)
That is in fact one of the representations in FLOAT-TC-MIB. This mib is described in tools.ietf.org/html/rfc6340 , and was released in 2011.Miniaturize
F
1

I rather send that data via OCTET STRING/DisplayString. Numbers such as "1.5" can be sent easily.

However, if the data need to be accurate, you may use Kyle's suggestion by sending bytes (octets). Noticeably that is also sent via OCTET STRING as it is a perfect byte container.

Faustena answered 29/1, 2010 at 11:16 Comment(1)
My concern of sending the test representation is that the SNMP Manager can't do any calculations with that data.Anthozoan

© 2022 - 2024 — McMap. All rights reserved.