NdmcClientService.cpp
Go to the documentation of this file.
1 /**
2  * NdmcClientService implementation file
3  * $Id: NdmcClientService.cpp,v 1.10 2017/08/08 20:21:09 dingpf Exp $
4  */
6 #include "NovaDAQMonitorClient/NdmcClientService.h"
7 
8 using namespace NDMC_NAMESPACE;
9 
10 std::string NdmcClientService::_CONFIGFILE = "/etc/ganglia/gmond_nova.conf";
11 
12 /**
13  * Constructor
14  */
16 
17  LOG_DEBUG("NdmcClientService") << "NdmcClientService::ctor @" << this << std::endl;
18 
19  if ( _initGanglia() ) _enabled = true; // initialize Ganglia
20 
21 }
22 
23 /**
24  * Destructor
25  */
27 
28  LOG_DEBUG("NdmcClientService") << "NdmcClientService::dtor @" << this << std::endl;
29 
30  Ganglia_pool_destroy(_globalContext);
31 
32 }
33 
34 /**
35  * Access the singleton instance
36  */
38 
39  static NdmcClientService ndmc;
40  return ndmc;
41 
42 }
43 
44 /**
45  * Initialize Ganglia. Return true if success, else false.
46  */
48 
49  // Create the Ganglia global context
50  _globalContext = Ganglia_pool_create(NULL);
51  if ( !_globalContext ) {
52  ::mf::LogError("NdmcClientService")
53  << "NdmcClientService::_initGanglia - Unable to create global context." << std::endl;
54  return false;
55  }
56  else {
57  LOG_DEBUG("NdmcClientService")
58  << "NdmcClientService::_initGanglia - Successfully created global context." << std::endl;
59  }
60 
61  // Parse the configuration file.
62  const char* configFile = getCONFIGFILE().c_str();
63  ::mf::LogInfo("NdmcClientService") << "NdmcClientService::_initGanglia - Using gmond config "
64  << configFile << "." << std::endl;
65  int fall_back_to_default = 0; // use default location for configuration, not.
66  _gmondConfig = Ganglia_gmond_config_create((char*)configFile,fall_back_to_default);
67  if ( !_gmondConfig ) {
68  ::mf::LogError("NdmcClientService") << "NdmcClientService::_initGanglia - Unable to open "
69  << configFile << "." << std::endl;;
70  return false;
71  }
72  else {
73  LOG_DEBUG("NdmcClientService")
74  << "NdmcClientService::_initGanglia - Successfully opened "
75  << configFile << "." << std::endl;
76  }
77 
78  // Build the udp send channels
79  _sendChannels = Ganglia_udp_send_channels_create(_globalContext, _gmondConfig);
80  if ( !_sendChannels ) {
81  ::mf::LogError("NdmcClientService")
82  << "NdmcClientService::_initGanglia - Unable to create ganglia send channels." << std::endl;
83  return false;
84  }
85  else {
86  LOG_DEBUG("NdmcClientService")
87  << "NdmcClientService::_initGanglia - Successfully created ganglia send channels."
88  << std::endl;;
89  }
90 
91  return true;
92 
93 }
94 
95 
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
Ganglia_udp_send_channels_t _sendChannels
static std::string getCONFIGFILE()
static std::string _CONFIGFILE
static NdmcClientService & instance()
Ganglia_gmond_config_t _gmondConfig
Ganglia_pool_t _globalContext
enum BeamMode string