Difference between revisions of "Binary protocol"

From collectd Wiki
Jump to: navigation, search
(Well-known numbers: Documented the buffer size option in 4.8.)
Line 20: Line 20:
 
There are two part layouts that are used for a couple of “types”: ''numeric'' (an 8 byte integer) and ''string''.
 
There are two part layouts that are used for a couple of “types”: ''numeric'' (an 8 byte integer) and ''string''.
  
 +
<br style="clear: both" />
 
=== Numeric parts ===
 
=== Numeric parts ===
  
Line 25: Line 26:
 
Numeric integer values, e.&nbsp;g. the [[interval]] and ''time'' values, are transferred using 8&nbsp;byte integers. The ''length'' field of those parts must therefore always be set to ''12''.
 
Numeric integer values, e.&nbsp;g. the [[interval]] and ''time'' values, are transferred using 8&nbsp;byte integers. The ''length'' field of those parts must therefore always be set to ''12''.
  
 +
<br style="clear: both" />
 
=== String parts ===
 
=== String parts ===
  
 
[[Image:Binary protocol part string.png|thumb|Structure of “string” parts. The example shows the encoding of the string “foobar”.]]
 
[[Image:Binary protocol part string.png|thumb|Structure of “string” parts. The example shows the encoding of the string “foobar”.]]
 
Strings are transferred ''including'' a null byte at the end. In the example you can see the encoding of the string “foobar”. The string is six characters long, followed by a null-byte and appended to a four byte header, leading to a length of ''11&nbsp;bytes'' for this part.
 
Strings are transferred ''including'' a null byte at the end. In the example you can see the encoding of the string “foobar”. The string is six characters long, followed by a null-byte and appended to a four byte header, leading to a length of ''11&nbsp;bytes'' for this part.
 +
 +
<br style="clear: both" />
 +
 +
=== Value parts ===
 +
 +
Value parts encode an actual data sample. Preceding time, plugin, plugin instance, type, and type instance parts must have set the context for the data sample. The value part consists of:
 +
* type 0x006
 +
* length
 +
* number of values (16 bit field)
 +
* values, for each one:
 +
** data type code (8 bit field), gauge => 1, counter => 0, derive => 2, absolute => 3
 +
** value (64 bit field), gauge => little endian double, counter/derive/absolute => big endian integer
 +
Many data samples have a single value, such as cpu (see the types.db), but others have multiple values, such as disk_merged, which has read and write values.
  
 
== Part types ==
 
== Part types ==
Line 39: Line 54:
 
  ! Name
 
  ! Name
 
  ! Data type
 
  ! Data type
 +
! Comment
 
  |-
 
  |-
 
  | <code>0x0000</code>
 
  | <code>0x0000</code>
 
  | Host
 
  | Host
 
  | String
 
  | String
 +
| The name of the host to associate with subsequent data values
 
  |-
 
  |-
 
  | <code>0x0001</code>
 
  | <code>0x0001</code>
 
  | Time
 
  | Time
 
  | Numeric
 
  | Numeric
 +
| The timestamp to associate with subsequent data values, unix time format (seconds since epoch)
 
  |-
 
  |-
 
  | <code>0x0002</code>
 
  | <code>0x0002</code>
 
  | Plugin
 
  | Plugin
 
  | String
 
  | String
 +
| The plugin name to associate with subsequent data values, e.g. "cpu"
 
  |-
 
  |-
 
  | <code>0x0003</code>
 
  | <code>0x0003</code>
 
  | Plugin instance
 
  | Plugin instance
 
  | String
 
  | String
 +
| The plugin instance name to associate with subsequent data values, e.g. "1"
 
  |-
 
  |-
 
  | <code>0x0004</code>
 
  | <code>0x0004</code>
 
  | Type
 
  | Type
 
  | String
 
  | String
 +
| The type name to associate with subsequent data values, e.g. "cpu"
 
  |-
 
  |-
 
  | <code>0x0005</code>
 
  | <code>0x0005</code>
 
  | Type instance
 
  | Type instance
 
  | String
 
  | String
 +
| The type instance name to associate with subsequent data values, e.g. "idle"
 
  |-
 
  |-
 
  | <code>0x0006</code>
 
  | <code>0x0006</code>
 
  | Values
 
  | Values
 
  | ''other'' '''(todo)'''
 
  | ''other'' '''(todo)'''
 +
| Data values, see below
 
  |-
 
  |-
 
  | <code>0x0007</code>
 
  | <code>0x0007</code>
 
  | Interval
 
  | Interval
 
  | Numeric
 
  | Numeric
 +
| Sampling interval
 
  |-
 
  |-
 
  | <code>0x0100</code>
 
  | <code>0x0100</code>
 
  | Message (notifications)
 
  | Message (notifications)
 
  | String
 
  | String
 +
|
 
  |-
 
  |-
 
  | <code>0x0101</code>
 
  | <code>0x0101</code>
 
  | Severity
 
  | Severity
 
  | Numeric
 
  | Numeric
 +
|
 
  |-
 
  |-
 
  | <code>0x0200</code>
 
  | <code>0x0200</code>
 
  | Signature (HMAC-SHA-256)
 
  | Signature (HMAC-SHA-256)
 
  | ''other'' '''(todo)'''
 
  | ''other'' '''(todo)'''
 +
|
 
  |-
 
  |-
 
  | <code>0x0210</code>
 
  | <code>0x0210</code>
 
  | Encryption (AES-256/OFB/SHA-1)
 
  | Encryption (AES-256/OFB/SHA-1)
 
  | ''other'' '''(todo)'''
 
  | ''other'' '''(todo)'''
 +
|
 
  |-
 
  |-
 
  |}
 
  |}
 +
 +
  
 
==Implementations==
 
==Implementations==

Revision as of 08:13, 17 January 2010

Until the network plugin has been factorized out into a library, it is useful to have some documentation to reimplement it.

Well-known numbers

Default UDP port
25826
Default IPv4 Multicast group
239.192.74.66
Default IPv6 multicast group
ff18::efc0:4a42
Maximum packet size
1024 bytes (payload only, not including UDP / IP headers)
In versions 4.0 through 4.7, the receive buffer has a fixed size of 1024 bytes. When longer packets are received, the trailing data is simply ignored. Since version 4.8, the buffer size can be configured.

Protocol structure

Beginning of each “part”: Type and length.

Each packet consists of one or more so called “parts”. Each part starts with the same four bytes: Two bytes that specify the “part type” (what kind of information is enclosed in the part) and two bytes which specify the length of the part, including the four header bytes itself. The maximum length of payload in any part is therefore 65531 bytes.

Using this layout, clients can determine the length of a part they don't know and lets them skip unknown data. This makes the protocol forward compatible so that new features can be added easily.

There are two part layouts that are used for a couple of “types”: numeric (an 8 byte integer) and string.


Numeric parts

Structure of the “number” parts

Numeric integer values, e. g. the interval and time values, are transferred using 8 byte integers. The length field of those parts must therefore always be set to 12.


String parts

Structure of “string” parts. The example shows the encoding of the string “foobar”.

Strings are transferred including a null byte at the end. In the example you can see the encoding of the string “foobar”. The string is six characters long, followed by a null-byte and appended to a four byte header, leading to a length of 11 bytes for this part.


Value parts

Value parts encode an actual data sample. Preceding time, plugin, plugin instance, type, and type instance parts must have set the context for the data sample. The value part consists of:

  • type 0x006
  • length
  • number of values (16 bit field)
  • values, for each one:
    • data type code (8 bit field), gauge => 1, counter => 0, derive => 2, absolute => 3
    • value (64 bit field), gauge => little endian double, counter/derive/absolute => big endian integer

Many data samples have a single value, such as cpu (see the types.db), but others have multiple values, such as disk_merged, which has read and write values.

Part types

The following numeric types are currently used to identify the type of a “part”. Defines are available from src/network.h.

ID Name Data type Comment
0x0000 Host String The name of the host to associate with subsequent data values
0x0001 Time Numeric The timestamp to associate with subsequent data values, unix time format (seconds since epoch)
0x0002 Plugin String The plugin name to associate with subsequent data values, e.g. "cpu"
0x0003 Plugin instance String The plugin instance name to associate with subsequent data values, e.g. "1"
0x0004 Type String The type name to associate with subsequent data values, e.g. "cpu"
0x0005 Type instance String The type instance name to associate with subsequent data values, e.g. "idle"
0x0006 Values other (todo) Data values, see below
0x0007 Interval Numeric Sampling interval
0x0100 Message (notifications) String
0x0101 Severity Numeric
0x0200 Signature (HMAC-SHA-256) other (todo)
0x0210 Encryption (AES-256/OFB/SHA-1) other (todo)


Implementations

See also