Add metrics to the framework

This change adds support for a metrics class which provides
the API allowing an xAPP to easily create and send a set of
measurements to a central collector for forwarding.

Issue-ID: RIC381

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: I0926b26d4862df308ab0863260805fe057785bdc
diff --git a/examples/Makefile b/examples/Makefile
index a56760a..2c4ded5 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -22,9 +22,10 @@
 # variables are set to reference the needed files.
 
 %.o:: %.cpp %.hpp
-	g++ -g ${prereq%% *} -c 
+	g++ -g ${prereq%% *} -c
 
 % :: %.cpp
+	#C_INCLUDE_PATH=/tmp/usr/include:/usr/local/include g++ $< -g -o $@  -lricxfcpp -lrmr_si -lpthread -lm
 	g++ $< -g -o $@  -lricxfcpp -lrmr_si -lpthread -lm
 
 all:: xapp_t1 xapp_t2 rmr_dump
diff --git a/examples/xapp_t1.cpp b/examples/xapp_t1.cpp
index 5ec8536..0de4e11 100644
--- a/examples/xapp_t1.cpp
+++ b/examples/xapp_t1.cpp
@@ -45,6 +45,7 @@
 
 #include "ricxfcpp/message.hpp"
 #include "ricxfcpp/msg_component.hpp"
+#include <ricxfcpp/metrics.hpp>
 #include "ricxfcpp/xapp.hpp"
 
 // counts; not thread safe
@@ -55,7 +56,10 @@
 long cb1_lastts = 0;
 long cb1_lastc = 0;
 
-// respond with 2 messages for each type 1 received
+/*
+	Respond with 2 messages for each type 1 received
+	Send metrics every 1000 messages.
+*/
 void cb1( xapp::Message& mbuf, int mtype, int subid, int len,
 			xapp::Msg_component payload,  void* data ) {
 	long now;
@@ -66,6 +70,16 @@
 	mbuf.Send_response( 101, -1, 5, (unsigned char *) "OK2\n" );
 
 	cb1_count++;
+
+    if( cb1_count % 1000 == 0 && data != NULL ) {   // send metrics every 1000 messages
+        auto x = (Xapp *) data;
+        auto msgm = std::shared_ptr<xapp::Message>( x->Alloc_msg( 4096 ) );
+
+        auto m = std::unique_ptr<xapp::Metrics>( new xapp::Metrics( msgm ) );
+        m->Push_data( "tst_cb1", (double) cb1_count );
+        m->Push_data( "tst_cb2", (double) cb2_count );
+        m->Send();
+    }
 }
 
 // just count messages
@@ -111,7 +125,7 @@
 	fprintf( stderr, "<XAPP> starting %d threads\n", nthreads );
 
 	x = new Xapp( port, true );
-	x->Add_msg_cb( 1, cb1, NULL );				// register callbacks
+	x->Add_msg_cb( 1, cb1, x );		// register callbacks
 	x->Add_msg_cb( 2, cb2, NULL );
 	x->Add_msg_cb( x->DEFAULT_CALLBACK, cbd, NULL );