19using namespace boost::posix_time;
 
   27    : start_time_(start_time), occurrences_(0),
 
   28      min_duration_(pos_infin), max_duration_(neg_infin),
 
   29      total_duration_(microseconds(0)) {
 
 
   35    if (duration < min_duration_) {
 
   36        min_duration_ = duration;
 
   39    if (duration > max_duration_) {
 
   40        max_duration_ = duration;
 
   43    total_duration_ += duration;
 
 
   52    return (total_duration_ / occurrences_);
 
 
   57    return ((start_time_ == other.start_time_) &&
 
   58            (occurrences_ == other.occurrences_) &&
 
   59            (min_duration_ == other.min_duration_) &&
 
   60            (max_duration_ == other.max_duration_) &&
 
   61            (total_duration_ == other.total_duration_));
 
 
   68                         uint8_t response_type,
 
   69                         const std::string& start_event_label,
 
   70                         const std::string& stop_event_label,
 
   78    if (family != AF_INET && family != AF_INET6) {
 
 
   87    if (family == AF_INET) {
 
  128                             << 
" not valid for query type: " << 
Pkt4::getName(query_type));
 
  158                             << 
" not valid for query type: " << 
Pkt6::getName(query_type));
 
 
  164    if (family == AF_INET) {
 
 
  173    std::ostringstream oss;
 
 
  185    std::ostringstream oss;
 
  195        << 
"." << value_name;
 
 
  224    return (!(*
this == other));
 
 
  246                                     uint8_t response_type,
 
  247                                     const std::string& start_event_label,
 
  248                                     const std::string& stop_event_label,
 
  251    : 
DurationKey(family, query_type, response_type, start_event_label, stop_event_label, subnet_id),
 
  252      interval_duration_(interval_duration),
 
  253      current_interval_(0),
 
  254      previous_interval_(0) {
 
  256        isc_throw(
BadValue, 
"MonitoredDuration - interval_duration " << interval_duration_
 
  257                            << 
", is invalid, it must be greater than 0");
 
 
  264      interval_duration_(interval_duration),
 
  265      current_interval_(0),
 
  266      previous_interval_(0) {
 
  268        isc_throw(
BadValue, 
"MonitoredDuration - interval_duration " << interval_duration_
 
  269                            << 
", is invalid, it must be greater than 0");
 
 
  275      interval_duration_(rhs.interval_duration_),
 
  276      current_interval_(0),
 
  277      previous_interval_(0) {
 
  278    if (rhs.current_interval_) {
 
  279        current_interval_.reset(new DurationDataInterval(*rhs.current_interval_));
 
  282    if (rhs.previous_interval_) {
 
  283        previous_interval_.reset(new DurationDataInterval(*rhs.previous_interval_));
 
 
  289    return (current_interval_ ? current_interval_->getStartTime()
 
 
  296    bool do_report = 
false;
 
  297    if (!current_interval_) {
 
  299    } 
else if ((now - current_interval_->getStartTime()) > interval_duration_) {
 
  300        previous_interval_ = current_interval_;
 
  305    current_interval_->addDuration(sample);
 
 
  311    if (!current_interval_) {
 
  313                                    " - no current interval for: " << 
getLabel());
 
  316    previous_interval_ = current_interval_;
 
  317    current_interval_.reset();
 
 
  322    current_interval_.reset();
 
  323    previous_interval_.reset();
 
 
  330    if (previous_interval_) {
 
  332        element->set(
"occurrences", 
Element::create(
static_cast<long long>(previous_interval_->getOccurrences())));
 
  333        element->set(
"min-duration-usecs", 
Element::create(previous_interval_->getMinDuration().total_microseconds()));
 
  334        element->set(
"max-duration-usecs", 
Element::create(previous_interval_->getMaxDuration().total_microseconds()));
 
  335        element->set(
"total-duration-usecs", 
Element::create(previous_interval_->getTotalDuration().total_microseconds()));
 
  336        element->set(
"mean-duration-usecs", 
Element::create(previous_interval_->getMeanDuration().total_microseconds()));
 
 
  351    static std::list<std::string> column_labels{
 
  359        "min-duration-usecs",
 
  360        "max-duration-usecs",
 
  361        "total-duration-usecs" 
  362        "mean-duration-usecs" 
  369        for (
auto const& label : column_labels) {
 
 
  390    if (previous_interval_) {
 
  392        row->add(
Element::create(
static_cast<long long>(previous_interval_->getOccurrences())));
 
  393        row->add(
Element::create(previous_interval_->getMinDuration().total_microseconds()));
 
  394        row->add(
Element::create(previous_interval_->getMaxDuration().total_microseconds()));
 
  395        row->add(
Element::create(previous_interval_->getTotalDuration().total_microseconds()));
 
  396        row->add(
Element::create(previous_interval_->getMeanDuration().total_microseconds()));
 
 
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
static const char * getName(const uint8_t type)
Returns name of the DHCP message for a given type number.
static const char * getName(const uint8_t type)
Returns name of the DHCPv6 message for a given type number.
static boost::posix_time::ptime now()
Fetch the current UTC system time, microsecond precision.
static boost::posix_time::ptime & MIN_TIME()
Fetches the minimum timestamp.
Embodies a span of time (i.e.
Duration getMeanDuration() const
Get the mean duration for the interval.
DurationDataInterval(const Timestamp &start_time=dhcp::PktEvent::now())
Constructor.
static const Duration & ZERO_DURATION()
Get a duration of zero.
bool operator==(const DurationDataInterval &other) const
Equality operator.
void addDuration(const Duration &duration)
Add a duration to the interval.
Houses the composite key that uniquely identifies a duration:
bool operator!=(const DurationKey &other) const
Inequality operator.
isc::dhcp::SubnetID subnet_id_
Subnet ID of the subnet selected during query fulfillment.
static std::string getMessageTypeLabel(uint16_t family, uint16_t msg_type)
Get a label for a family-specific message type (e.g.
uint8_t response_type_
Response message type (e.g. DHCPOFFER, DHCP6_ADVERTISE).
bool operator<(const DurationKey &other) const
Less than operator.
std::string start_event_label_
Label of the start event which begins the duration.
virtual data::ElementPtr toElement() const
Renders the the duration key as an Element.
bool operator==(const DurationKey &other) const
Equality operator.
DurationKey(uint16_t family, uint8_t query_type, uint8_t response_type, const std::string &start_event_label, const std::string &stop_event_label, dhcp::SubnetID subnet_id)
Constructor.
uint16_t family_
Protocol family AF_INET or AF_INET6.
std::string getStatName(const std::string &value_name) const
Get the StatsMgr formatted compatible name.
static void validateMessagePair(uint16_t family, uint8_t query_type, uint8_t response_type)
Validates that a query and response message type pair is sane.
std::string stop_event_label_
Label of the end event which ends the duration.
std::string getLabel() const
Get a composite label of the member values with text message types.
uint8_t query_type_
Query message type (e.g. DHCPDISCOVER, DHCP6_SOLICIT).
virtual data::ElementPtr toElement() const
Renders the the duration as an Element.
data::ElementPtr toValueRow() const
Renders the the duration as an Element::list of values.
Timestamp getCurrentIntervalStart() const
Get the current interval start time.
bool addSample(const Duration &sample)
Add a sample to the duration's current interval.
void expireCurrentInterval()
Concludes the current interval.
MonitoredDuration(uint16_t family, uint8_t query_type, uint8_t response_type, const std::string &start_event_label, const std::string &stop_event_label, dhcp::SubnetID subnet_id, const Duration &interval_duration)
Constructor.
void clear()
Deletes the current and previous intervals.
static data::ConstElementPtr valueRowColumns()
Fetches a an Element::list of value row column names.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
@ DHCP_NOTYPE
Message Type option missing.
boost::posix_time::time_duration Duration
boost::posix_time::ptime Timestamp
std::ostream & operator<<(std::ostream &os, const DurationKey &key)
std::string ptimeToText(boost::posix_time::ptime t, size_t fsecs_precision=MAX_FSECS_PRECISION)
Converts ptime structure to text.
Defines the logger used by the top-level component of kea-lfc.