statistics.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. 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. /// This constructor is mostly exception free. But it may still throw
  61. /// a standard exception if memory allocation fails inside the method.
  62. ///
  63. AuthCounters();
  64. /// The destructor.
  65. ///
  66. /// This method never throws an exception.
  67. ///
  68. ~AuthCounters();
  69. /// \brief Increment the counter specified by the parameter.
  70. ///
  71. /// \param type Type of a counter to increment.
  72. ///
  73. /// \throw std::out_of_range \a type is unknown.
  74. ///
  75. /// usage: counter.inc(CounterType::COUNTER_UDP_QUERY);
  76. ///
  77. void inc(const CounterType type);
  78. /// \brief Submit statistics counters to statistics module.
  79. ///
  80. /// This method is desinged to be called periodically
  81. /// with \c asio_link::StatisticsSendTimer, or arbitrary
  82. /// by the command 'sendstats'.
  83. ///
  84. /// Note: Set the session to communicate with statistics module
  85. /// by \c setStatisticsSession() before calling \c submitStatistics().
  86. ///
  87. /// This method is mostly exception free (error conditions are
  88. /// represented via the return value). But it may still throw
  89. /// a standard exception if memory allocation fails inside the method.
  90. ///
  91. /// \return true on success, false on error.
  92. ///
  93. /// \todo Do not block message handling in auth_srv while submitting
  94. /// statistics data.
  95. ///
  96. bool submitStatistics() const;
  97. /// \brief Set the session to communicate with Statistics
  98. /// module.
  99. ///
  100. /// This method never throws an exception.
  101. ///
  102. /// Note: this interface is tentative. We'll revisit the ASIO and session
  103. /// frameworks, at which point the session will probably be passed on
  104. /// construction of the server.
  105. ///
  106. /// Ownership isn't transferred: the caller is responsible for keeping
  107. /// this object to be valid while the server object is working and for
  108. /// disconnecting the session and destroying the object when the server
  109. /// is shutdown.
  110. ///
  111. /// \param statistics_session A pointer to the session
  112. ///
  113. void setStatisticsSession(isc::cc::AbstractSession* statistics_session);
  114. /// \brief Get a value of a counter in the AuthCounters.
  115. ///
  116. /// This function returns a value of the counter specified by \a type.
  117. /// This method never throws an exception.
  118. ///
  119. /// Note: Currently this function is for testing purpose only.
  120. ///
  121. /// \param type Type of a counter to get the value of
  122. ///
  123. /// \return the value of the counter specified by \a type.
  124. ///
  125. uint64_t getCounter(const AuthCounters::CounterType type) const;
  126. };
  127. #endif // __STATISTICS_H
  128. // Local Variables:
  129. // mode: c++
  130. // End: