Outline
Purpose
Provide a protocol to publish recorded metric values.
Classes
- See also
Description
This component defines a protocol class balm::Publisher
used for publishing metric values. The protocol's primary method is publish
, which takes a balm::MetricSample
. The precise meaning of publish
is left to derived classes to specify.
Alternative Systems for Telemetry
Bloomberg software may alternatively use the GUTS telemetry API, which is integrated into Bloomberg infrastructure.
Usage
This section illustrates intended use of this component.
Example 1: Implementing the balm::Publisher Protocol
The following example demonstrates a simple implementation of the balm::Publisher
protocol. This implementation publishes the metric records to an output stream provided on construction.
bsl::ostream& d_stream;
SimpleStreamPublisher(const SimpleStreamPublisher& );
SimpleStreamPublisher& operator=(const SimpleStreamPublisher& );
public:
SimpleStreamPublisher(bsl::ostream& stream);
virtual ~SimpleStreamPublisher();
};
SimpleStreamPublisher::SimpleStreamPublisher(bsl::ostream& stream)
: d_stream(stream)
{
}
SimpleStreamPublisher::~SimpleStreamPublisher()
{
}
{
return;
}
<< metricValues.
numRecords() <<
" Records" << bsl::endl;
for (; sIt != metricValues.
end(); ++sIt) {
d_stream << "\tElapsed Time: "
<< sIt->elapsedTime().totalSecondsAsDouble()
<< "s" << bsl::endl;
for (; gIt != sIt->end(); ++gIt) {
<<
" [count = " << gIt->
count()
<<
", total = " << gIt->
total()
<<
", min = " << gIt->
min()
<<
", max = " << gIt->
max() <<
"]" << bsl::endl;
}
}
}
Definition balm_metricrecord.h:217
int & count()
Definition balm_metricrecord.h:406
double & total()
Definition balm_metricrecord.h:412
double & max()
Definition balm_metricrecord.h:418
MetricId & metricId()
Definition balm_metricrecord.h:400
double & min()
Definition balm_metricrecord.h:424
Definition balm_metricsample.h:342
const_iterator end() const
Definition balm_metricsample.h:691
const_iterator begin() const
Definition balm_metricsample.h:685
const bdlt::DatetimeTz & timeStamp() const
Return a reference to the non-modifiable timestamp for this sample.
Definition balm_metricsample.h:679
int numRecords() const
Definition balm_metricsample.h:703
bsl::vector< MetricSampleGroup >::const_iterator const_iterator
Definition balm_metricsample.h:364
Definition balm_publisher.h:276
Example 2: Using the balm::Publisher Protocol
The following example defines a trivial EventManager
class that uses the balm::Publisher
protocol to publish metrics related to the incoming event. Note that this event manager does no actual processing and is intended only to illustrate how the publisher protocol might be used.
class EventManager {
EventManager(const EventManager& );
EventManager& operator=(const EventManager& );
public:
: d_eventMessageSize(messageSizeId)
, d_lastPublish(
bdlt::CurrentTime::nowAsDatetimeUTC(), 0)
{}
int handleEvent(
int eventId,
const bsl::string& eventMessage)
{
static_cast<double>(eventMessage.
size()));
(void)eventId;
return 0;
}
Definition balm_collector.h:152
void update(double value)
Definition balm_collector.h:271
Definition balm_metricid.h:162
Definition bdlt_datetimetz.h:308
Definition bslstl_string.h:1281
size_type size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6592
Definition bbldc_basicisma30360.h:112
We use a balm::Publisher
to publish the metrics recorded by this event manager. Note that most of the functionality illustrated here is normally provided by the balm::MetricsManager
.
{
d_lastPublish = now;
}
};
void loadAndReset(MetricRecord *record)
Definition balm_collector.h:260
void setTimeStamp(const bdlt::DatetimeTz &timeStamp)
Definition balm_metricsample.h:639
void appendGroup(const MetricSampleGroup &group)
Definition balm_metricsample.h:645
virtual void publish(const MetricSample &metricValue)=0
Definition bdlt_datetimeinterval.h:201
int milliseconds() const
Definition bdlt_datetimeinterval.h:1137
bsls::Types::Int64 totalSeconds() const
Definition bdlt_datetimeinterval.h:1170
Datetime utcDatetime() const
Definition bdlt_datetimetz.h:678
Definition bsls_timeinterval.h:301
Example 3: Publishing Collected Metrics Using EventManager
In this final example, we publish metrics collected for the EventManager
object (defined above).
We start by creating a balm::MetricId
object by hand, but in practice, an id should be obtained from a balm::MetricRegistry
object (such as the one owned by a balm::MetricsManager
).
Definition balm_category.h:151
Definition balm_metricdescription.h:158
Now we create a EventManager
object and supply it the metric id we have created.
EventManager eventManager(eventMessageSizeId);
We use the EventManager
object to process two events and then publish the metrics for those events with a SimpleStreamPublisher
object (also defined above).
eventManager.handleEvent(0, "123");
eventManager.handleEvent(0, "456789");
SimpleStreamPublisher myPublisher(bsl::cout);
eventManager.publishMetrics(publisher);
Note that we have delivered two events, with the messages "123" and "456789", so the count should be 2, the total message size should be 9, the minimum should be 3, and the maximum should be 6. The output to the console should be:
05FEB2009_19:49:30.173+0000 1 Records
Elapsed Time: 1e-09s
MyCategory.EventMessageSize [count = 2, total = 9, min = 3, max = 6]