stats.xml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 since
  11. 0.9.2-beta version. Working DHCP server encounters various events
  12. that can influence certain statistics to be collected. For
  13. example, a DHCPv4 server may receive a packet (pkt4-received
  14. statistic increased by one) that after parsing was identifier as
  15. DHCPDISCOVER (pkt4-discover-received). Server processed it and
  16. decided to send DHCPOFFER representing its answer (pkt4-offer-sent
  17. and pkt4-sent statistics increased 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 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. recoding 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. recoding statistics in textual forma. 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 DHCPv4 and DHCPv6 list of 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 statistic, all statistics, reset (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 Statistics Manager module is working. 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. statistic change, related statistic will be created. In a general case
  69. 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> is 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 records a given statistic the next
  82. time. <command>statistic-remove</command> and
  83. <command>statistic-remove-all</command> commands are intended to remove
  84. statistics that is 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, system administrator may want to remove pkt4-decline-received
  89. statistic, so it won't be reported anymore. If duplicate address is
  90. detected ever again, the server will add this statistic back.
  91. </para>
  92. </section>
  93. <section id="command-stats">
  94. <title>Commands for manipulating statistics</title>
  95. <para>
  96. There are several commands defined that can be used for accessing (-get),
  97. resetting to zero or neutral value (-reset) or even removing a statistic
  98. completely (-remove). The difference between reset and remove is somewhat
  99. subtle. Reset command sets value of the statistic to zero or neutral
  100. value. After this operation, statistic will have value of 0 (integer), 0.0
  101. (float), 0h0m0s0us (duration) or "" (string). When asked for, statistic
  102. with the values metioned will be returned. Remove removes a statistic
  103. completely, so the statistic will not be reported anymore. Please note
  104. that
  105. </para>
  106. <section id="command-statistic-get">
  107. <title>statistic-get command</title>
  108. <para>
  109. <emphasis>statistic-get</emphasis> command retrieves a single
  110. statistic. It takes a single string parameter called
  111. <command>name</command> that specifies the statistic name. An example
  112. command may look like this:
  113. <screen>
  114. {
  115. "command": "statistic-get",
  116. "arguments": {
  117. "name": "<userinput>pkt4-received</userinput>"
  118. }
  119. }
  120. </screen>
  121. </para>
  122. <para>
  123. The server will respond with details of requested statistic, with result
  124. set to 0 indicates success and specified statistic as the value of
  125. "arguments" parameter. If requested statistic is not found, the response
  126. will contain an empty map, i.e. only { } as argument, but the status
  127. code will still be set to success (0).
  128. </para>
  129. </section> <!-- end of command-statistic-get -->
  130. <section id="command-statistic-reset">
  131. <title>statistic-reset command</title>
  132. <para>
  133. <emphasis>statistic-reset</emphasis> command sets specified statistic to
  134. its neutral value: 0 for integer, 0.0 for float, 0h0m0s0us for time
  135. duration and "" for string type. It takes a single string parameter
  136. called <command>name</command> that specifies the statistic name. An
  137. example command may look like this:
  138. <screen>
  139. {
  140. "command": "statistic-reset",
  141. "arguments": {
  142. "name": "<userinput>pkt4-received</userinput>"
  143. }
  144. }
  145. </screen>
  146. </para>
  147. <para>
  148. If specific statistic is found and reset was successful,
  149. the server will respond with status of 0, indicating success and empty
  150. parameters field. If error is encountered (e.g. requested statistic
  151. was not found), the server will return status code of 1 (error)
  152. and text field will contain the error description.
  153. </para>
  154. </section> <!-- end of command-statistic-reset -->
  155. <section id="command-statistic-remove">
  156. <title>statistic-remove command</title>
  157. <para>
  158. <emphasis>statistic-remove</emphasis> command attempt to delete a single
  159. statistic. It takes a single string parameter called
  160. <command>name</command> that specifies the statistic name. An example
  161. command may look like this:
  162. <screen>
  163. {
  164. "command": "statistic-remove",
  165. "arguments": {
  166. "name": "<userinput>pkt4-received</userinput>"
  167. }
  168. }
  169. </screen>
  170. </para>
  171. <para>
  172. If specific statistic is found and its removal was successful,
  173. the server will respond with status of 0, indicating success and empty
  174. parameters field. If error is encountered (e.g. requested statistic
  175. was not found), the server will return status code of 1 (error)
  176. and text field will contain the error description.
  177. </para>
  178. </section> <!-- end of command-statistic-reset -->
  179. <section id="command-statistic-get-all">
  180. <title>statistic-get-all command</title>
  181. <para>
  182. <emphasis>statistic-get-all</emphasis> command retrieves a single
  183. statistic. An example
  184. command may look like this:
  185. <screen>
  186. {
  187. "command": "statistic-get-all",
  188. "arguments": { }
  189. }
  190. </screen>
  191. </para>
  192. <para>
  193. The server will respond with details of all recorded statistics, with result
  194. set to 0 indicating that it iterated over all statistics (even when
  195. the total number of statistics is zero).
  196. </para>
  197. </section> <!-- end of command-statistic-get-all -->
  198. <section id="command-statistic-reset-all">
  199. <title>statistic-reset-all command</title>
  200. <para>
  201. <emphasis>statistic-reset</emphasis> command sets all statistics to
  202. their neutral values: 0 for integer, 0.0 for float, 0h0m0s0us for time
  203. duration and "" for string type. An example command may look like this:
  204. <screen>
  205. {
  206. "command": "statistic-reset-all",
  207. "arguments": { }
  208. }
  209. </screen>
  210. </para>
  211. <para>
  212. If the operation is successful, the server will respond with status of
  213. 0, indicating success and empty parameters field. If error is
  214. encountered, the server will return status code of 1 (error) and text
  215. field will contain the error description.
  216. </para>
  217. </section> <!-- end of command-statistic-reset-all -->
  218. <section id="command-statistic-remove-all">
  219. <title>statistic-remove-all command</title>
  220. <para>
  221. <emphasis>statistic-remove-all</emphasis> command attempt to delete all
  222. statistics. An example command may look like this:
  223. <screen>
  224. {
  225. "command": "statistic-remove-all",
  226. "arguments": { }
  227. }
  228. </screen>
  229. </para>
  230. <para>
  231. If removal of all statistics was successful, the server will respond
  232. with status of 0, indicating success and empty parameters field. If
  233. error is encountered, the server will return status code of 1 (error)
  234. and text field will contain the error description.
  235. </para>
  236. </section> <!-- end of command-statistic-remove-all -->
  237. </section>
  238. </chapter>