stats.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2014;" >
  5. ]>
  6. <chapter id="stats">
  7. <title>Statistics</title>
  8. <section>
  9. <title>Statistics Overview</title>
  10. <para>Both Kea DHCP servers support statistics gathering.
  11. A working DHCP server encounters various events
  12. that can cause certain statistics to be collected. For
  13. example, a DHCPv4 server may receive a packet (pkt4-received
  14. statistic increases by one) that after parsing was identified as a
  15. DHCPDISCOVER (pkt4-discover-received). The Server processed it and
  16. decided to send a DHCPOFFER representing its answer (pkt4-offer-sent
  17. and pkt4-sent statistics increase by one). Such events happen
  18. frequently, so it is not uncommon for the statistics to have
  19. values in high thousands. They can serve as an easy and powerful
  20. tool for observing a server's and network's health. For example,
  21. if pkt4-received statistic stops growing, it means that the
  22. clients' packets are not reaching the server.</para>
  23. <para>There are four types of statistics:
  24. <itemizedlist>
  25. <listitem>
  26. <simpara><emphasis>integer</emphasis> - this is the most common type. It
  27. is implemented as 64 bit integer (int64_t in C++), so it can hold any
  28. value between -2^63 to 2^63 -1.</simpara>
  29. </listitem>
  30. <listitem>
  31. <simpara><emphasis>floating point</emphasis> - this type is intended to
  32. store floating point precision. It is implemented as double C++ type.
  33. </simpara>
  34. </listitem>
  35. <listitem>
  36. <simpara><emphasis>duration</emphasis> - this type is intended for
  37. recording time periods. It uses boost::posix_time::time_duration type,
  38. which stores hours, minutes, seconds and microseconds.</simpara>
  39. </listitem>
  40. <listitem>
  41. <simpara><emphasis>string</emphasis> - this type is intended for
  42. recording statistics in textual form. It uses std::string C++ type.
  43. </simpara>
  44. </listitem>
  45. </itemizedlist>
  46. </para>
  47. <para>
  48. During normal operation, DHCPv4 and DHCPv6 servers gather statistics.
  49. For a list of DHCPv4 and DHCPv6 statistics, see <xref
  50. linkend="dhcp4-stats"/> and <xref linkend="dhcp6-stats"/>, respectively.
  51. </para>
  52. <para>
  53. To extract data from the statistics module, the control channel can be
  54. used. See <xref linkend="ctrl-channel" /> for details. It is possible to
  55. retrieve a single or all statistics, reset statistics (i.e. set to neutral
  56. value, typically zero) or even remove completely a single or all
  57. statistics. See section <xref linkend="command-stats"/> for a list of
  58. statistic oriented commands.
  59. </para>
  60. </section>
  61. <section id="stats-lifecycle">
  62. <title>Statistics Lifecycle</title>
  63. <para>
  64. It is useful to understand how the Statistics Manager module works. When
  65. the server starts operation, the manager is empty and does not have any
  66. statistics. When <command>statistic-get-all</command> is executed, an
  67. empty list is returned. Once the server performs an operation that causes
  68. a statistic to change, the related statistic will be created. In the general
  69. case, once a statistic is recorded even once, it is kept in the manager, until
  70. explicitly removed, by <command>statistic-remove</command> or
  71. <command>statistic-remove-all</command> being called or the server is shut
  72. down. Per subnet statistics are explicitly removed when reconfiguration
  73. takes place.
  74. </para>
  75. <para>
  76. Statistics are considered run-time properties, so they are not retained
  77. after server restart.
  78. </para>
  79. <para>
  80. Removing a statistic that is updated frequently makes little sense as it
  81. will be re-added when the server code next records that statistic.
  82. The <command>statistic-remove</command> and
  83. <command>statistic-remove-all</command> commands are intended to remove
  84. statistics that are not expected to be observed in the near future. For
  85. example, a misconfigured device in a network may cause clients to report
  86. duplicate addresses, so the server will report increasing values of
  87. pkt4-decline-received. Once the problem is found and the device is
  88. removed, the system administrator may want to remove the
  89. pkt4-decline-received statistic, so it won't be reported anymore. If a
  90. duplicate address is detected ever again, the server will add this
  91. statistic back.
  92. </para>
  93. </section>
  94. <section id="command-stats">
  95. <title>Commands for Manipulating Statistics</title>
  96. <para>
  97. There are several commands defined that can be used for accessing (-get),
  98. resetting to zero or neutral value (-reset) or even removing a statistic
  99. completely (-remove). The difference between reset and remove is somewhat
  100. subtle. The reset command sets the value of the statistic to zero or neutral
  101. value. After this operation, the statistic will have a value of 0 (integer),
  102. 0.0 (float), 0h0m0s0us (duration) or "" (string). When asked for, a statistic
  103. with the values mentioned will be returned. <command>Remove</command> removes
  104. a statistic completely, so the statistic will not be reported anymore. Please
  105. note that the server code may add it back if there's a reason to record
  106. it.
  107. </para>
  108. <note><para>
  109. The following sections describe commands that can be sent to the server: the
  110. examples are not fragments of a configuration file. For more information on
  111. sending commands to Kea, see <xref linkend="ctrl-channel"/>.
  112. </para></note>
  113. <section id="command-statistic-get">
  114. <title>statistic-get command</title>
  115. <para>
  116. <emphasis>statistic-get</emphasis> command retrieves a single
  117. statistic. It takes a single string parameter called
  118. <command>name</command> that specifies the statistic name. An example
  119. command may look like this:
  120. <screen>
  121. {
  122. "command": "statistic-get",
  123. "arguments": {
  124. "name": "<userinput>pkt4-received</userinput>"
  125. }
  126. }
  127. </screen>
  128. </para>
  129. <para>
  130. The server will respond with details of the requested statistic, with result
  131. set to 0 indicating success and the specified statistic as the value of
  132. "arguments" parameter. If the requested statistic is not found, the response
  133. will contain an empty map, i.e. only { } as argument, but the status
  134. code will still be set to success (0).
  135. </para>
  136. </section> <!-- end of command-statistic-get -->
  137. <section id="command-statistic-reset">
  138. <title>statistic-reset command</title>
  139. <para>
  140. <emphasis>statistic-reset</emphasis> command sets the specified statistic
  141. to its neutral value: 0 for integer, 0.0 for float, 0h0m0s0us for time
  142. duration and "" for string type. It takes a single string parameter
  143. called <command>name</command> that specifies the statistic name. An
  144. example command may look like this:
  145. <screen>
  146. {
  147. "command": "statistic-reset",
  148. "arguments": {
  149. "name": "<userinput>pkt4-received</userinput>"
  150. }
  151. }
  152. </screen>
  153. </para>
  154. <para>
  155. If the specific statistic is found and reset was successful, the
  156. server will respond with a status of 0, indicating success and an empty
  157. parameters field. If an error is encountered (e.g. requested statistic
  158. was not found), the server will return a status code of 1 (error)
  159. and the text field will contain the error description.
  160. </para>
  161. </section> <!-- end of command-statistic-reset -->
  162. <section id="command-statistic-remove">
  163. <title>statistic-remove command</title>
  164. <para>
  165. <emphasis>statistic-remove</emphasis> command attempts to delete a single
  166. statistic. It takes a single string parameter called
  167. <command>name</command> that specifies the statistic name. An example
  168. command may look like this:
  169. <screen>
  170. {
  171. "command": "statistic-remove",
  172. "arguments": {
  173. "name": "<userinput>pkt4-received</userinput>"
  174. }
  175. }
  176. </screen>
  177. </para>
  178. <para>
  179. If the specific statistic is found and its removal was successful, the
  180. server will respond with a status of 0, indicating success and an empty
  181. parameters field. If an error is encountered (e.g. requested statistic
  182. was not found), the server will return a status code of 1 (error)
  183. and the text field will contain the error description.
  184. </para>
  185. </section> <!-- end of command-statistic-reset -->
  186. <section id="command-statistic-get-all">
  187. <title>statistic-get-all command</title>
  188. <para>
  189. <emphasis>statistic-get-all</emphasis> command retrieves all statistics
  190. recorded. An example command may look like this:
  191. <screen>
  192. {
  193. "command": "statistic-get-all",
  194. "arguments": { }
  195. }
  196. </screen>
  197. </para>
  198. <para>
  199. The server will respond with details of all recorded statistics, with result
  200. set to 0 indicating that it iterated over all statistics (even when
  201. the total number of statistics is zero).
  202. </para>
  203. </section> <!-- end of command-statistic-get-all -->
  204. <section id="command-statistic-reset-all">
  205. <title>statistic-reset-all command</title>
  206. <para>
  207. <emphasis>statistic-reset</emphasis> command sets all statistics to
  208. their neutral values: 0 for integer, 0.0 for float, 0h0m0s0us for time
  209. duration and "" for string type. An example command may look like this:
  210. <screen>
  211. {
  212. "command": "statistic-reset-all",
  213. "arguments": { }
  214. }
  215. </screen>
  216. </para>
  217. <para>
  218. If the operation is successful, the server will respond with a status of
  219. 0, indicating success and an empty parameters field. If an error is
  220. encountered, the server will return a status code of 1 (error) and the text
  221. field will contain the error description.
  222. </para>
  223. </section> <!-- end of command-statistic-reset-all -->
  224. <section id="command-statistic-remove-all">
  225. <title>statistic-remove-all command</title>
  226. <para>
  227. <emphasis>statistic-remove-all</emphasis> command attempts to delete all
  228. statistics. An example command may look like this:
  229. <screen>
  230. {
  231. "command": "statistic-remove-all",
  232. "arguments": { }
  233. }
  234. </screen>
  235. </para>
  236. <para>
  237. If the removal of all statistics was successful, the server will respond
  238. with a status of 0, indicating success and an empty parameters field. If
  239. an error is encountered, the server will return a status code of 1 (error)
  240. and the text field will contain the error description.
  241. </para>
  242. </section> <!-- end of command-statistic-remove-all -->
  243. </section>
  244. </chapter>