Binding promethues port to single interface 53/6753/5
authorwahidw <abdulwahid.w@nokia.com>
Fri, 24 Sep 2021 17:35:28 +0000 (17:35 +0000)
committerwahidw <abdulwahid.w@nokia.com>
Sun, 10 Oct 2021 18:23:37 +0000 (18:23 +0000)
Change-Id: Iea7d78d32301e57b5f15479ce8795f90e450c59f
Signed-off-by: wahidw <abdulwahid.w@nokia.com>
RIC-E2-TERMINATION/sctpThread.cpp
RIC-E2-TERMINATION/sctpThread.h

index 3d00a62..1306c11 100644 (file)
@@ -60,6 +60,22 @@ boost::shared_ptr<sinks::synchronous_sink<sinks::text_file_backend>> boostLogger
 double cpuClock = 0.0;
 bool jsonTrace = false;
 
+char* getinterfaceip()
+{
+   char hostname[256];
+   char *IP;
+   struct hostent *host_entry;
+   int retVal;
+   retVal = gethostname(hostname, sizeof(hostname));
+   if ( retVal == -1 )
+       return NULL;
+   host_entry = gethostbyname(hostname);
+   if ( host_entry == NULL )
+       return NULL;
+   IP = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0]));
+   return IP;
+}
+
 
 static int enable_log_change_notify(const char* fileName)
 {
@@ -129,7 +145,7 @@ static void * monitor_loglevel_change_handler(void* arg)
 #if !(defined(UNIT_TEST) || defined(MODULE_TEST))                        
                         if( errno == EAGAIN ) {
                         } else {
-                            fprintf( stderr, "### CRIT ### config listener read err: %s\n", strerror( errno ) );
+                            printf(  "### CRIT ### config listener read err: %s\n", strerror( errno ) );
                         }
                         continue;
 #endif                        
@@ -495,6 +511,9 @@ void startPrometheus(sctp_params_t &sctpParams) {
     if (strstr(podName, "alpha") != NULL) {
         metric = "E2TAlpha";
     }
+    //Get eth0 interface IP
+    char* host = getinterfaceip();
+    string hostip = host;
 
     sctpParams.prometheusFamily = &BuildCounter()
             .Name(metric.c_str())
@@ -505,7 +524,12 @@ void startPrometheus(sctp_params_t &sctpParams) {
     // Build E2T instance level metrics
     buildE2TPrometheusCounters(sctpParams);
 
-    string prometheusPath = sctpParams.prometheusPort + "," + "[::]:" + sctpParams.prometheusPort;
+    string prometheusPath;
+    if (hostip.empty())
+        prometheusPath = sctpParams.prometheusPort + "," + "[::]:" + sctpParams.prometheusPort;
+    else
+        prometheusPath = hostip + ":" + sctpParams.prometheusPort;
+
     if (mdclog_level_get() >= MDCLOG_DEBUG) {
         mdclog_write(MDCLOG_DEBUG, "Start Prometheus Pull mode on %s", prometheusPath.c_str());
     }
index 0bcff53..51527c0 100644 (file)
@@ -41,6 +41,8 @@
 #include <atomic>
 #include <sys/param.h>
 #include <sys/file.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
 #include <ctime>
 #include <netdb.h>
 #include <sys/epoll.h>
@@ -418,6 +420,7 @@ static int enable_log_change_notify(const char* fileName);
 static int register_log_change_notify(const char *fileName);
 static void * monitor_loglevel_change_handler(void* arg);
 void  update_mdc_log_level_severity(char* log_level);
+char* getinterfaceip();
 static char* parse_file(char* filename);