statistics.h 5.4 KB

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