statistics.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __STATISTICS_H
  15. #define __STATISTICS_H 1
  16. #include <dns/opcode.h>
  17. #include <cc/session.h>
  18. #include <stdint.h>
  19. #include <boost/scoped_ptr.hpp>
  20. class AuthCountersImpl;
  21. /// \brief Set of query counters.
  22. ///
  23. /// \c AuthCounters is set of query counters class. It holds query counters
  24. /// and provides an interface to increment the counter of specified type
  25. /// (e.g. UDP query, TCP query).
  26. ///
  27. /// This class also provides a function to send statistics information to
  28. /// statistics module.
  29. ///
  30. /// This class is designed to be a part of \c AuthSrv.
  31. /// Call \c setStatisticsSession() to set a session to communicate with
  32. /// statistics module like Xfrin session.
  33. /// Call \c inc() to increment a counter for specific type of query in
  34. /// the query processing function. use \c enum \c CounterType to specify
  35. /// the type of query.
  36. /// Call \c submitStatistics() to submit statistics information to statistics
  37. /// module with statistics_session, periodically or at a time the command
  38. /// \c sendstats is received.
  39. ///
  40. /// We may eventually want to change the structure to hold values that are
  41. /// not counters (such as concurrent TCP connections), or seperate generic
  42. /// part to src/lib to share with the other modules.
  43. ///
  44. /// This class uses pimpl idiom and hides detailed implementation.
  45. /// This class is constructed on startup of the server, so
  46. /// construction overhead of this approach should be acceptable.
  47. ///
  48. /// \todo Hold counters for each query types (Notify, Axfr, Ixfr, Normal)
  49. /// \todo Consider overhead of \c AuthCounters::inc()
  50. class AuthCounters {
  51. private:
  52. boost::scoped_ptr<AuthCountersImpl> impl_;
  53. public:
  54. // Enum for the type of counter
  55. enum ServerCounterType {
  56. SERVER_UDP_QUERY, ///< SERVER_UDP_QUERY: counter for UDP queries
  57. SERVER_TCP_QUERY, ///< SERVER_TCP_QUERY: counter for TCP queries
  58. SERVER_COUNTER_TYPES ///< The number of defined counters
  59. };
  60. enum PerZoneCounterType {
  61. ZONE_UDP_QUERY, ///< ZONE_UDP_QUERY: counter for UDP queries
  62. ZONE_TCP_QUERY, ///< ZONE_TCP_QUERY: counter for TCP queries
  63. PER_ZONE_COUNTER_TYPES ///< The number of defined counters
  64. };
  65. /// The constructor.
  66. ///
  67. /// This constructor is mostly exception free. But it may still throw
  68. /// a standard exception if memory allocation fails inside the method.
  69. ///
  70. AuthCounters();
  71. /// The destructor.
  72. ///
  73. /// This method never throws an exception.
  74. ///
  75. ~AuthCounters();
  76. /// \brief Increment the counter specified by the parameter.
  77. ///
  78. /// \param type Type of a counter to increment.
  79. ///
  80. /// \throw std::out_of_range \a type is unknown.
  81. ///
  82. /// usage: counter.inc(AuthCounters::SERVER_UDP_QUERY);
  83. ///
  84. void inc(const ServerCounterType type);
  85. /// \brief Increment the counter of a per opcode counter.
  86. ///
  87. /// \note This is a tentative interface. See \c getCounter().
  88. ///
  89. /// \param opcode The opcode of the counter to increment.
  90. ///
  91. /// \throw None
  92. void inc(const isc::dns::Opcode opcode);
  93. /// \brief Submit statistics counters to statistics module.
  94. ///
  95. /// This method is desinged to be called periodically
  96. /// with \c asio_link::StatisticsSendTimer, or arbitrary
  97. /// by the command 'sendstats'.
  98. ///
  99. /// Note: Set the session to communicate with statistics module
  100. /// by \c setStatisticsSession() before calling \c submitStatistics().
  101. ///
  102. /// This method is mostly exception free (error conditions are
  103. /// represented via the return value). But it may still throw
  104. /// a standard exception if memory allocation fails inside the method.
  105. ///
  106. /// \return true on success, false on error.
  107. ///
  108. /// \todo Do not block message handling in auth_srv while submitting
  109. /// statistics data.
  110. ///
  111. bool submitStatistics() const;
  112. /// \brief Set the session to communicate with Statistics
  113. /// module.
  114. ///
  115. /// This method never throws an exception.
  116. ///
  117. /// Note: this interface is tentative. We'll revisit the ASIO and session
  118. /// frameworks, at which point the session will probably be passed on
  119. /// construction of the server.
  120. ///
  121. /// Ownership isn't transferred: the caller is responsible for keeping
  122. /// this object to be valid while the server object is working and for
  123. /// disconnecting the session and destroying the object when the server
  124. /// is shutdown.
  125. ///
  126. /// \param statistics_session A pointer to the session
  127. ///
  128. void setStatisticsSession(isc::cc::AbstractSession* statistics_session);
  129. /// \brief Get the value of a counter in the AuthCounters.
  130. ///
  131. /// This function returns a value of the counter specified by \a type.
  132. /// This method never throws an exception.
  133. ///
  134. /// Note: Currently this function is for testing purpose only.
  135. ///
  136. /// \param type Type of a counter to get the value of
  137. ///
  138. /// \return the value of the counter specified by \a type.
  139. uint64_t getCounter(const AuthCounters::ServerCounterType type) const;
  140. /// \brief Get the value of a per opcode counter.
  141. ///
  142. /// This method returns the value of the per opcode counter for the
  143. /// specified \c opcode.
  144. ///
  145. /// \note This is a tentative interface as an attempt of experimentally
  146. /// supporting more statistics counters. This should eventually be more
  147. /// generalized. In any case, this method is mainly for testing.
  148. ///
  149. /// \throw None
  150. /// \param opcode The opcode of the counter to get the value of
  151. /// \return the value of the counter.
  152. uint64_t getCounter(const isc::dns::Opcode opcode) const;
  153. /// \brief A type of validation function for the specification in
  154. /// isc::config::ModuleSpec.
  155. ///
  156. /// This type might be useful for not only statistics
  157. /// specificatoin but also for config_data specification and for
  158. /// commnad.
  159. ///
  160. typedef boost::function<bool(const isc::data::ConstElementPtr&)>
  161. validator_type;
  162. /// \brief Register a function type of the statistics validation
  163. /// function for AuthCounters.
  164. ///
  165. /// This method never throws an exception.
  166. ///
  167. /// \param validator A function type of the validation of
  168. /// statistics specification.
  169. ///
  170. void registerStatisticsValidator(AuthCounters::validator_type validator) const;
  171. };
  172. #endif // __STATISTICS_H
  173. // Local Variables:
  174. // mode: c++
  175. // End: