summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/NodeI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceGrid/NodeI.cpp')
-rw-r--r--cpp/src/IceGrid/NodeI.cpp167
1 files changed, 5 insertions, 162 deletions
diff --git a/cpp/src/IceGrid/NodeI.cpp b/cpp/src/IceGrid/NodeI.cpp
index 4793ed6b22c..07e3824a16e 100644
--- a/cpp/src/IceGrid/NodeI.cpp
+++ b/cpp/src/IceGrid/NodeI.cpp
@@ -21,15 +21,6 @@
#if defined(_WIN32)
# include <direct.h> // For _getcwd
-#elif defined(__APPLE__)
-# include <sys/sysctl.h>
-#elif defined(__sun)
-# include <sys/loadavg.h>
-#elif defined(__hpux)
-# include <sys/pstat.h>
-#elif defined(_AIX)
-# include <nlist.h>
-# include <fcntl.h>
#endif
using namespace std;
@@ -221,78 +212,10 @@ NodeI::NodeI(const Ice::ObjectAdapterPtr& adapter,
_serversDir = dataDir + (dataDir[dataDir.length() - 1] == '/' ? "" : "/") + "servers";
_tmpDir = dataDir + (dataDir[dataDir.length() - 1] == '/' ? "" : "/") + "tmp";
-
-#if defined(_WIN32)
- PDH_STATUS err = PdhOpenQuery(0, 0, &_query);
- if(err != ERROR_SUCCESS)
- {
- Ice::SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- Ice::Warning out(_traceLevels->logger);
- out << "can't open performance data query:\n" << ex;
- }
- err = PdhAddCounter(_query, "\\Processor(_Total)\\% Processor Time", 0, &_counter);
- if(err != ERROR_SUCCESS)
- {
- Ice::SyscallException ex(__FILE__, __LINE__);
- ex.error = err;
- Ice::Warning out(_traceLevels->logger);
- out << "can't add performance counter:\n" << ex;
- }
- _usages1.insert(_usages1.end(), 1 * 60 / 5, 0); // 1 sample every 5 seconds during 1 minutes.
- _usages5.insert(_usages5.end(), 5 * 60 / 5, 0); // 1 sample every 5 seconds during 5 minutes.
- _usages15.insert(_usages15.end(), 15 * 60 / 5, 0); // 1 sample every 5 seconds during 15 minutes.
- _last1Total = 0;
- _last5Total = 0;
- _last15Total = 0;
-#else
-#if defined(__linux) || defined(__sun)
- _nproc = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
-#elif defined(__APPLE__)
- static int ncpu[2] = { CTL_HW, HW_NCPU };
- size_t sz = sizeof(_nproc);
- if(sysctl(ncpu, 2, &_nproc, &sz, 0, 0) == -1)
- {
- Ice::SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
- }
-#elif defined(_AIX)
- _nproc = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
- struct nlist nl;
- nl.n_name = "avenrun";
- nl.n_value = 0;
- if(knlist(&nl, 1, sizeof(nl)) == 0)
- {
- _kmem = open("/dev/kmem", O_RDONLY);
-
- //
- // Give up root permissions, it's only needed to access the file.
- //
- setuid(getuid());
- setgid(getgid());
- }
- else
- {
- _kmem = -1;
- }
-#else
- _nproc = 1;
-#endif
- assert(_nproc > 0);
-#endif
}
NodeI::~NodeI()
{
-#ifdef _WIN32
- PdhCloseQuery(_query);
-#elif defined(_AIX)
- if(_kmem > 0)
- {
- close(_kmem);
- }
-#endif
}
ServerPrx
@@ -587,89 +510,7 @@ NodeI::keepAlive()
{
try
{
- LoadInfo info;
- info.load1 = 1.0f;
- info.load5 = 1.0f;
- info.load15 = 1.0f;
- info.nProcessors = 1;
-
-#if defined(_WIN32)
- //
- // TODO: Use CPU utilization
- //
- int usage = 100;
- if(PdhCollectQueryData(_query) == ERROR_SUCCESS)
- {
- DWORD type;
- PDH_FMT_COUNTERVALUE value;
- PdhGetFormattedCounterValue(_counter, PDH_FMT_LONG, &type, &value);
- usage = static_cast<int>(value.longValue);
- }
-
- _last1Total += usage - _usages1.back();
- _last5Total += usage - _usages5.back();
- _last15Total += usage - _usages15.back();
-
- _usages1.pop_back();
- _usages5.pop_back();
- _usages15.pop_back();
- _usages1.push_front(usage);
- _usages5.push_front(usage);
- _usages15.push_front(usage);
-
- info.load1 = static_cast<float>(_last1Total) / _usages1.size() / 100.0f;
- info.load5 = static_cast<float>(_last5Total) / _usages5.size() / 100.0f;
- info.load15 = static_cast<float>(_last15Total) / _usages15.size() / 100.0f;
- info.nProcessors = 1;
-#elif defined(__sun) || defined(__linux) || defined(__APPLE__)
- //
- // We use the load average divided by the number of
- // processors to figure out if the machine is busy or
- // not. The result is capped at 1.0f.
- //
- double loadAvg[3];
- if(getloadavg(loadAvg, 3) != -1)
- {
- info.load1 = static_cast<float>(loadAvg[0]);
- info.load5 = static_cast<float>(loadAvg[1]);
- info.load15 = static_cast<float>(loadAvg[2]);
- }
- info.nProcessors = _nproc;
-#elif defined(__hpux)
- struct pst_dynamic dynInfo;
- if(pstat_getdynamic(&dynInfo, sizeof(dynInfo), 1, 0) >= 0)
- {
- info.load1 = dynInfo.psd_avg_1_min;
- info.load5 = dynInfo.psd_avg_5_min;
- info.load15 = dynInfo.psd_avg_15_min;
- info.nProcessors = dynInfo.psd_proc_cnt;
- }
-#elif defined(_AIX)
- if(_kmem > 1)
- {
- long long avenrun[3];
- struct nlist nl;
- nl.n_name = "avenrun";
- nl.n_value = 0;
- if(knlist(&nl, 1, sizeof(nl)) == 0)
- {
- if(pread(_kmem, avenrun, sizeof(avenrun), nl.n_value) >= sizeof(avenrun))
- {
- info.load1 = avenrun[0] / 65536.0f;
- info.load5 = avenrun[1] / 65536.0f;
- info.load15 = avenrun[2] / 65536.0f;
- }
- }
- }
- else
- {
- info.load1 = -1.f;
- info.load5 = -1.f;
- info.load15 = -1.f;
- }
- info.nProcessors = _nproc;
-#endif
- session->keepAlive(info);
+ session->keepAlive(_platform.getLoadInfo());
}
catch(const Ice::LocalException&)
{
@@ -680,9 +521,10 @@ NodeI::keepAlive()
{
try
{
- Ice::ObjectPrx registry = getCommunicator()->stringToProxy("IceGrid/Registry@IceGrid.Registry.Internal");
+ Ice::ObjectPrx object = getCommunicator()->stringToProxy("IceGrid/Registry@IceGrid.Registry.Internal");
+ RegistryPrx registry = RegistryPrx::uncheckedCast(object);
NodeObserverPrx observer;
- setSession(RegistryPrx::uncheckedCast(registry)->registerNode(_name, _proxy, observer), observer);
+ setSession(registry->registerNode(_name, _proxy, _platform.getNodeInfo(), observer), observer);
checkConsistency();
}
catch(const NodeActiveException&)
@@ -947,6 +789,7 @@ NodeI::initObserver(const Ice::StringSeq& servers)
{
NodeDynamicInfo info;
info.name = _name;
+ info.info = _platform.getNodeInfo();
info.servers = serverInfos;
info.adapters = adapterInfos;
_observer->nodeUp(info);