statistics.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <cc/session.h>
  17. #include <stdint.h>
  18. #include <boost/scoped_ptr.hpp>
  19. class AuthCountersImpl;
  20. /// \brief Set of query counters.
  21. ///
  22. /// \c AuthCounters is set of query counters class. It holds query counters
  23. /// and provides an interface to increment the counter of specified type
  24. /// (e.g. UDP query, TCP query).
  25. ///
  26. /// This class also provides a function to send statistics information to
  27. /// statistics module.
  28. ///
  29. /// This class is designed to be a part of \c AuthSrv.
  30. /// Call \c setStatisticsSession() to set a session to communicate with
  31. /// statistics module like Xfrin session.
  32. /// Call \c inc() to increment a counter for specific type of query in
  33. /// the query processing function. use \c enum \c CounterType to specify
  34. /// the type of query.
  35. /// Call \c submitStatistics() to submit statistics information to statistics
  36. /// module with statistics_session, periodically or at a time the command
  37. /// \c sendstats is received.
  38. ///
  39. /// We may eventually want to change the structure to hold values that are
  40. /// not counters (such as concurrent TCP connections), or seperate generic
  41. /// part to src/lib to share with the other modules.
  42. ///
  43. /// This class uses pimpl idiom and hides detailed implementation.
  44. /// This class is constructed on startup of the server, so
  45. /// construction overhead of this approach should be acceptable.
  46. ///
  47. /// \todo Hold counters for each query types (Notify, Axfr, Ixfr, Normal)
  48. /// \todo Consider overhead of \c AuthCounters::inc()
  49. class AuthCounters {
  50. private:
  51. boost::scoped_ptr<AuthCountersImpl> impl_;
  52. public:
  53. // Enum for the type of counter
  54. enum ServerCounterType {
  55. SERVER_UDP_QUERY, ///< SERVER_UDP_QUERY: counter for UDP queries
  56. SERVER_TCP_QUERY, ///< SERVER_TCP_QUERY: counter for TCP queries
  57. SERVER_COUNTER_TYPES ///< The number of defined counters
  58. };
  59. enum PerZoneCounterType {
  60. ZONE_UDP_QUERY, ///< ZONE_UDP_QUERY: counter for UDP queries
  61. ZONE_TCP_QUERY, ///< ZONE_TCP_QUERY: counter for TCP queries
  62. PER_ZONE_COUNTER_TYPES ///< The number of defined counters
  63. };
  64. /// The constructor.
  65. ///
  66. /// This constructor is mostly exception free. But it may still throw
  67. /// a standard exception if memory allocation fails inside the method.
  68. ///
  69. AuthCounters();
  70. /// The destructor.
  71. ///
  72. /// This method never throws an exception.
  73. ///
  74. ~AuthCounters();
  75. /// \brief Increment the counter specified by the parameter.
  76. ///
  77. /// \param type Type of a counter to increment.
  78. ///
  79. /// \throw std::out_of_range \a type is unknown.
  80. ///
  81. /// usage: counter.inc(AuthCounters::SERVER_UDP_QUERY);
  82. ///
  83. void inc(const ServerCounterType type);
  84. /// \brief Submit statistics counters to statistics module.
  85. ///
  86. /// This method is desinged to be called periodically
  87. /// with \c asio_link::StatisticsSendTimer, or arbitrary
  88. /// by the command 'sendstats'.
  89. ///
  90. /// Note: Set the session to communicate with statistics module
  91. /// by \c setStatisticsSession() before calling \c submitStatistics().
  92. ///
  93. /// This method is mostly exception free (error conditions are
  94. /// represented via the return value). But it may still throw
  95. /// a standard exception if memory allocation fails inside the method.
  96. ///
  97. /// \return true on success, false on error.
  98. ///
  99. /// \todo Do not block message handling in auth_srv while submitting
  100. /// statistics data.
  101. ///
  102. bool submitStatistics() const;
  103. /// \brief Set the session to communicate with Statistics
  104. /// module.
  105. ///
  106. /// This method never throws an exception.
  107. ///
  108. /// Note: this interface is tentative. We'll revisit the ASIO and session
  109. /// frameworks, at which point the session will probably be passed on
  110. /// construction of the server.
  111. ///
  112. /// Ownership isn't transferred: the caller is responsible for keeping
  113. /// this object to be valid while the server object is working and for
  114. /// disconnecting the session and destroying the object when the server
  115. /// is shutdown.
  116. ///
  117. /// \param statistics_session A pointer to the session
  118. ///
  119. void setStatisticsSession(isc::cc::AbstractSession* statistics_session);
  120. /// \brief Get a value of a counter in the AuthCounters.
  121. ///
  122. /// This function returns a value of the counter specified by \a type.
  123. /// This method never throws an exception.
  124. ///
  125. /// Note: Currently this function is for testing purpose only.
  126. ///
  127. /// \param type Type of a counter to get the value of
  128. ///
  129. /// \return the value of the counter specified by \a type.
  130. ///
  131. uint64_t getCounter(const AuthCounters::ServerCounterType type) const;
  132. /// \brief A type of validation function for the specification in
  133. /// isc::config::ModuleSpec.
  134. ///
  135. /// This type might be useful for not only statistics
  136. /// specificatoin but also for config_data specification and for
  137. /// commnad.
  138. ///
  139. typedef boost::function<bool(const isc::data::ConstElementPtr&)>
  140. validator_type;
  141. /// \brief Register a function type of the statistics validation
  142. /// function for AuthCounters.
  143. ///
  144. /// This method never throws an exception.
  145. ///
  146. /// \param validator A function type of the validation of
  147. /// statistics specification.
  148. ///
  149. void registerStatisticsValidator(AuthCounters::validator_type validator) const;
  150. };
  151. #endif // __STATISTICS_H
  152. // Local Variables:
  153. // mode: c++
  154. // End: