BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balm_streampublisher.h
Go to the documentation of this file.
1/// @file balm_streampublisher.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// balm_streampublisher.h -*-C++-*-
8#ifndef INCLUDED_BALM_STREAMPUBLISHER
9#define INCLUDED_BALM_STREAMPUBLISHER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup balm_streampublisher balm_streampublisher
15/// @brief Provide a `balm::Publisher` implementation that writes to a stream.
16/// @addtogroup bal
17/// @{
18/// @addtogroup balm
19/// @{
20/// @addtogroup balm_streampublisher
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#balm_streampublisher-purpose"> Purpose</a>
25/// * <a href="#balm_streampublisher-classes"> Classes </a>
26/// * <a href="#balm_streampublisher-description"> Description </a>
27/// * <a href="#balm_streampublisher-alternative-systems-for-telemetry"> Alternative Systems for Telemetry </a>
28/// * <a href="#balm_streampublisher-usage"> Usage </a>
29/// * <a href="#balm_streampublisher-example-1-basic-usage"> Example 1: Basic Usage </a>
30///
31/// # Purpose {#balm_streampublisher-purpose}
32/// Provide a `balm::Publisher` implementation that writes to a stream.
33///
34/// # Classes {#balm_streampublisher-classes}
35///
36/// - balm::StreamPublisher: publishes collected metric samples to a stream
37///
38/// @see balm_publisher, balm_metricrecord, balm_metricsmanager
39///
40/// # Description {#balm_streampublisher-description}
41/// This component defines a concrete class
42/// `balm::StreamPublisher` that implements the `balm::Publisher` protocol for
43/// publishing metric records:
44/// @code
45/// ( balm::StreamPublisher )
46/// | ctor
47/// |
48/// V
49/// ( balm::Publisher )
50/// dtor
51/// publish
52/// @endcode
53/// This implementation of the publisher protocol publishes records to an output
54/// stream that is supplied at construction.
55///
56/// ## Alternative Systems for Telemetry {#balm_streampublisher-alternative-systems-for-telemetry}
57///
58///
59/// Bloomberg software may alternatively use the GUTS telemetry API, which is
60/// integrated into Bloomberg infrastructure.
61///
62/// ## Usage {#balm_streampublisher-usage}
63///
64///
65/// This section illustrates intended use of this component.
66///
67/// ### Example 1: Basic Usage {#balm_streampublisher-example-1-basic-usage}
68///
69///
70/// In the following example we illustrate how to create and publish records
71/// with a `balm::StreamPublisher`. First we define a couple of metric ids.
72/// Note that we create the `balm::MetricId` objects by hand, but in practice an
73/// id should be obtained from a `balm::MetricRegistry` object (such as the one
74/// owned by a `balm::MetricsManager`).
75/// @code
76/// balm::Category myCategory("MyCategory");
77/// balm::MetricDescription descA(&myCategory, "MetricA");
78/// balm::MetricDescription descB(&myCategory, "MetricB");
79///
80/// balm::MetricId metricA(&descA);
81/// balm::MetricId metricB(&descB);
82/// @endcode
83/// Now we create a `balm::StreamPublisher` object, supplying it the `stdout`
84/// stream:
85/// @code
86/// balm::StreamPublisher myPublisher(bsl::cout);
87/// @endcode
88/// Next we create a metric sample containing some records and pass it to the
89/// `balm::StreamPublisher` we created. Note that because we are not actually
90/// collecting the metrics we set the elapsed time of the sample to an
91/// arbitrary 5s interval.
92/// @code
93/// bslma::Allocator *allocator = bslma::Default::allocator(0);
94/// bsl::vector<balm::MetricRecord> records(allocator);
95///
96/// records.push_back(balm::MetricRecord(metricA, 5, 25.0, 6.0, 25.0));
97/// records.push_back(balm::MetricRecord(metricB, 2, 7.0, 3.0, 11.0));
98///
99/// balm::MetricSample sample(allocator);
100///
101/// sample.setTimeStamp(bdlt::DatetimeTz(bdlt::CurrentTime::utc(), 0));
102/// sample.appendGroup(records.data(),
103/// static_cast<int>(records.size()),
104/// bsls::TimeInterval(5, 0));
105///
106/// myPublisher.publish(sample);
107/// @endcode
108/// The output of this example would look similar to:
109/// @code
110/// 05FEB2009_19:52:11.723+0000 2 Records
111/// Elapsed Time: 5s
112/// MyCategory.MetricA [ count = 5, total = 25, min = 6, max = 25 ]
113/// MyCategory.MetricB [ count = 2, total = 7, min = 3, max = 11 ]
114/// @endcode
115/// @}
116/** @} */
117/** @} */
118
119/** @addtogroup bal
120 * @{
121 */
122/** @addtogroup balm
123 * @{
124 */
125/** @addtogroup balm_streampublisher
126 * @{
127 */
128
129#include <balscm_version.h>
130
131#include <balm_publisher.h>
132
133#include <bsl_iosfwd.h>
134
135
136
137
138namespace balm {
139
140class MetricSample;
141
142 // =====================
143 // class StreamPublisher
144 // =====================
145
146/// This class provides an implementation of the `Publisher` protocol.
147/// This stream publisher publishes recorded metric values to an output
148/// stream specified at construction.
149///
150/// See @ref balm_streampublisher
152
153 // DATA
154 bsl::ostream& d_stream; // stream to which to write data
155
156 // NOT IMPLEMENTED
158 StreamPublisher& operator=(const StreamPublisher& );
159
160 public:
161 // CREATORS
162
163 /// Create a streampublisher and initialize it to publish metrics to
164 /// the specified `stream`.
165 StreamPublisher(bsl::ostream& stream);
166
167 /// Destroy this stream publisher.
169
170 // MANIPULATORS
171
172 /// Publish the specified `metricValues` to the output stream specified
173 /// at construction.
174 virtual void publish(const MetricSample& metricValues);
175};
176
177// ============================================================================
178// INLINE DEFINITIONS
179// ============================================================================
180
181 // ---------------------
182 // class StreamPublisher
183 // ---------------------
184
185// CREATORS
186inline
187StreamPublisher::StreamPublisher(bsl::ostream& stream)
188: d_stream(stream)
189{
190}
191
192} // close package namespace
193
194
195#endif
196
197// ----------------------------------------------------------------------------
198// Copyright 2015 Bloomberg Finance L.P.
199//
200// Licensed under the Apache License, Version 2.0 (the "License");
201// you may not use this file except in compliance with the License.
202// You may obtain a copy of the License at
203//
204// http://www.apache.org/licenses/LICENSE-2.0
205//
206// Unless required by applicable law or agreed to in writing, software
207// distributed under the License is distributed on an "AS IS" BASIS,
208// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
209// See the License for the specific language governing permissions and
210// limitations under the License.
211// ----------------------------- END-OF-FILE ----------------------------------
212
213/** @} */
214/** @} */
215/** @} */
Definition balm_metricsample.h:342
Definition balm_publisher.h:276
Definition balm_streampublisher.h:151
virtual ~StreamPublisher()
Destroy this stream publisher.
virtual void publish(const MetricSample &metricValues)
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balm_bdlmmetricsadapter.h:141