1 .** vim: sw=4 ts=4 et :
3 ==================================================================================
4 Copyright (c) 2020 AT&T Intellectual Property.
5 Copyright (c) 2020 Nokia
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
22 This imbed file contains the description of the metrics API.
23 It should be included by the main user.xfm source.
28 The C++ xAPP framework provides a lightweight interface to the metrics
29 gateway allowing the xAPP to create and send metrics updates without
30 needing to understand the underlying message format.
31 From the xAPP's perspective, the metrics object is created with one or
32 more key/value measurement pairs and then is sent to the process
33 responsible for forwarding them to the various collection processes.
34 The following sections describe the Metrics object and the API associated
38 &h2(Creating The Metrics Object)
39 The &cw(xapp:Metrics) object can be created directly, or via the xapp framework.
40 When creating directly the xAPP must supply an RMR message for the object to use;
41 when the framework is used to create the object, the message is created as
42 as part of the process.
44 The framework provides three constructors for the metrics instance allowing the
45 xAPP to supply the measurement source, the source and reporter, or to default to
46 using the xAPP name as both the source and reporter (see section &ital( &snr_section )
47 for a more detailed description of these).
48 The framework constructors are illustrated in figure &frame_builders.
51 .ca start frame_builder.ca
53 std::unique_ptr<xapp::Metrics> Alloc_metrics( );
54 std::unique_ptr<xapp::Metrics> Alloc_metrics( std::string source );
55 std::unique_ptr<xapp::Metrics> Alloc_metrics( std::string reporter, std::string source );
57 &export_fig( frame_builders )
58 &fig_cen(The framework constructors for creating an instance of the metrics object.)
62 &ifroom( 2 : frame_builder.ca )
67 #include <ricxfcpp/Metrics>
69 char* port = (char *) "4560";
71 auto x = std::unique_ptr<Xapp>( new Xapp( port ) );
72 auto reading = std::shared_ptr<xapp::Metrics>( x->Alloc_metric( ) );
74 &export_fig( metric_create_1 )
75 &fig_cen(Metrics instance creation using the framework. )
79 &ifroom( 2 : create1.ca )
81 Figures &metric_create_1 illustrates how the framework constructor can be used to
82 create a metrics instance.
83 While it is unlikely that an xAPP will create a metrics instance directly, there
84 are three similar constructors available.
85 These are prototypes are shown in figure &metrics_builders and their use is illustrated
86 in figure &metrics_create_2.
88 .ca start met_builder.ca
90 Metrics( std::shared_ptr<xapp::Message> msg );
91 Metrics( std::shared_ptr<xapp::Message> msg, std::string msource );
92 Metrics( std::shared_ptr<xapp::Message> msg, std::string reporter, std::string msource );
94 &export_fig( metrics_builders )
95 &fig_cen(Metrics object constructors.)
99 &ifroom( 1 : met_builder.ca )
103 #include <ricxfcpp/Metrics>
105 char* port = (char *) "4560";
107 auto x = std::unique_ptr<Xapp>( new Xapp( port ) );
108 auto msg = std::shared_ptr<xapp::Message>( x->Alloc_msg( 4096 ) );
109 auto reading = std::shared_ptr<xapp::Metrics>( new Metrics( msg ) );
111 &export_fig( metrics_create_2 )
112 &fig_cen(Direct creation of a metrics instance.)
116 &ifroom( 2 : create2.ca )
119 Once an instance of the metrics object is created, the xAPP may push values in
120 preparation to sending the measurement(s) to the collector.
121 The &cw(Push_data()) function is used to push each key/value pair and is illustrated
126 reading->Push_data( "normal_count", (double) norm_count );
127 reading->Push_data( "high_count", (double) hi_count );
128 reading->Push_data( "excessive_count", (double) ex_count );
130 &export_fig( push_fig )
131 &fig_cen(Pushing key/value pairs into a metrics instance.)
135 &ifroom( 1 : push.ca )
137 &h2(Sending A Measurement Set)
138 After all of the measurement key/value pairs have been added to the instance, the
139 &cw(Send()) function can be invoked to create the necessary RMR message and send that
140 to the collection application.
141 Following the send, the key/value pairs are cleared from the instance and the
142 xAPP is free to start pushing values into the instance again.
143 The send function has the following prototype and returns &cw(true) on success and
144 &cw(false) if the measurements could not be sent.
146 &h2(Source and Reporter)
147 &export_var( snr_section : Source and Reporter )
148 The alarm collector has the understanding that a measurement might be &ital(sourced) from one
149 piece of equipment, or software component, but reported by another.
150 For auditing purposes it makes sense to distinguish these, and as such the metrics object
151 allows the xAPP to identify the case when the source and reporter are something other than
152 the xAPP which is generating the metrics message(s).
155 The &ital(source) is the component to which the measurement applies.
156 This could be a network interface card counting packets, a temperature sensor, or the xAPP
157 itself reporting xAPP related metrics.
158 The &ital(reporter) is the application that is reporting the measurement(s) to the collector.
161 By default, both reporter and source are assumed to be the xAPP, and the name is automatically
162 determined using the run-time supplied programme name.
163 Should the xAPP need to report measurements for more than one source it has the option to
164 create an instance for every reporter source combination, or to set the reporter and/or
165 source with the generation of each measurement set.
166 To facilitate the ability to change the source and/or the reporter without the need to create
167 a new metrics instance, two &ital(setter) functions are provided.
168 The prototypes for these are shown in figure &setter_fig.
173 void Set_source( std::string new_source );
174 void Set_reporter( std::string new_reporter );
176 &export_fig( setter_fig )
177 &fig_cen( Setter functions allowing the reporter and/or source to be set after construction. )
181 &ifroom( 1 : setter.ca )