diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 11 | ||||
-rw-r--r-- | cpp/src/Ice/MetricsAdminI.cpp | 113 | ||||
-rw-r--r-- | cpp/src/Ice/MetricsAdminI.h | 109 | ||||
-rw-r--r-- | cpp/src/Ice/MetricsObserverI.h | 25 | ||||
-rw-r--r-- | cpp/src/Ice/ObserverI.cpp | 6 |
5 files changed, 155 insertions, 109 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 1b9fda895b0..d4c83e6f980 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -39,6 +39,7 @@ #include <Ice/Observer.h> #include <Ice/GC.h> #include <Ice/MetricsAdminI.h> +#include <Ice/ObserverI.h> #include <IceUtil/UUID.h> #include <IceUtil/Mutex.h> @@ -130,7 +131,11 @@ public: void updateThreadObservers() { _instance->clientThreadPool()->updateObservers(); - _instance->serverThreadPool(false)->updateObservers(); + ThreadPoolPtr serverThreadPool = _instance->serverThreadPool(false); + if(serverThreadPool) + { + serverThreadPool->updateObservers(); + } _instance->objectAdapterFactory()->updateObservers(&ObjectAdapterI::updateThreadObservers); _instance->endpointHostResolver()->updateObserver(); theCollector->updateObserver(_instance->initializationData().observer); @@ -1078,7 +1083,9 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi // if(!_initData.observer) { - _adminFacets.insert(FacetMap::value_type("MetricsAdmin", new IceMX::MetricsAdminI(_initData))); + IceMX::MetricsAdminIPtr admin = new IceMX::MetricsAdminI(_initData.properties); + _adminFacets.insert(FacetMap::value_type("MetricsAdmin", admin)); + _initData.observer = new IceMX::CommunicatorObserverI(admin); } __setNoDelete(false); diff --git a/cpp/src/Ice/MetricsAdminI.cpp b/cpp/src/Ice/MetricsAdminI.cpp index f5182f690c5..a4b502bebbb 100644 --- a/cpp/src/Ice/MetricsAdminI.cpp +++ b/cpp/src/Ice/MetricsAdminI.cpp @@ -153,7 +153,7 @@ MetricsMapI::getMatching(const MetricsHelper& helper) map<string, EntryPtr>::const_iterator p = _objects.find(key); if(p == _objects.end()) { - p = _objects.insert(make_pair(key, new Entry(this, helper.newMetrics(key)))).first; + p = _objects.insert(make_pair(key, newEntry(this, helper.newMetrics(key)))).first; } return p->second; } @@ -197,15 +197,14 @@ MetricsMapI::detached(Entry* entry) _detachedQueue.push_back(entry); } -MetricsViewI::MetricsViewI() +MetricsViewI::MetricsViewI(bool enabled) : _enabled(enabled) { } void -MetricsViewI::add(const string& name, const string& groupBy, int retain, const NameValueDict& accept, - const NameValueDict& reject) +MetricsViewI::add(const string& name, const MetricsMapIPtr& map) { - _maps.insert(make_pair(name, new MetricsMapI(groupBy, retain, accept, reject))); + _maps.insert(make_pair(name, map)); } void @@ -264,27 +263,26 @@ MetricsViewI::getMaps() const return maps; } -MetricsAdminI::MetricsAdminI(InitializationData& initData) +MetricsAdminI::MetricsAdminI(const Ice::PropertiesPtr& properties) : _properties(properties) { - const string viewsPrefix = "IceMX.MetricsView."; - - vector<string> defaultMaps; - defaultMaps.push_back("Connection"); - defaultMaps.push_back("Thread"); - defaultMaps.push_back("Request"); - defaultMaps.push_back("Dispatch"); - defaultMaps.push_back("Invocation"); - defaultMaps.push_back("Connect"); - defaultMaps.push_back("EndpointLookups"); - - PropertiesPtr properties = initData.properties; +} - __setNoDelete(true); +void +MetricsAdminI::addUpdater(const string& mapName, const UpdaterPtr& updater) +{ + _updaters.insert(make_pair(mapName, updater)); +} - assert(!initData.observer); - initData.observer = new CommunicatorObserverI(this); +void +MetricsAdminI::addFactory(const string& mapName, const MetricsMapFactoryPtr& factory) +{ + _factories[mapName] = factory; - PropertyDict views = properties->getPropertiesForPrefix(viewsPrefix); + // + // Add maps to views configured with the given map name. + // + const string viewsPrefix = "IceMX.MetricsView."; + PropertyDict views = _properties->getPropertiesForPrefix(viewsPrefix); for(PropertyDict::const_iterator p = views.begin(); p != views.end(); ++p) { string viewName = p->first.substr(viewsPrefix.size()); @@ -294,60 +292,33 @@ MetricsAdminI::MetricsAdminI(InitializationData& initData) viewName = viewName.substr(0, dotPos); } - MetricsViewIPtr view = new MetricsViewI(); - _views.insert(make_pair(viewName, view)); - - view->setEnabled(properties->getPropertyAsIntWithDefault(viewsPrefix + viewName, 1) > 0); + map<string, MetricsViewIPtr>::const_iterator q = _views.find(viewName); + if(q == _views.end()) + { + bool enabled = _properties->getPropertyAsIntWithDefault(viewsPrefix + viewName, 1) > 0; + q = _views.insert(make_pair(viewName, new MetricsViewI(enabled))).first; + } + MetricsViewIPtr view = q->second; - int mapsCount = 0; - const string mapsPrefix = viewsPrefix + viewName + '.'; - PropertyDict maps = properties->getPropertiesForPrefix(mapsPrefix); - for(PropertyDict::const_iterator q = maps.begin(); q != maps.end(); ++q) + const string mapsPrefix = viewsPrefix + viewName + ".Map."; + string mapPrefix = mapsPrefix + mapName; + if(_properties->getPropertiesForPrefix(mapPrefix).empty() && + _properties->getPropertiesForPrefix(mapsPrefix).empty()) { - string mapName = q->first.substr(mapsPrefix.size()); - dotPos = mapName.find('.'); - if(dotPos != string::npos) - { - mapName = mapName.substr(0, dotPos); - } - - if(mapName == "GroupBy" || mapName == "Accept" || mapName == "Reject" || mapName == "RetainDetached") - { - continue; // Those aren't maps. - } - - ++mapsCount; - - string groupBy = properties->getProperty(mapsPrefix + mapName + ".GroupBy"); - int retain = properties->getPropertyAsIntWithDefault(mapsPrefix + mapName + ".RetainDetached", 10); - NameValueDict accept = parseRule(properties, mapsPrefix + mapName + ".Accept"); - NameValueDict reject = parseRule(properties, mapsPrefix + mapName + ".Reject"); - addMapToView(viewName, mapName, groupBy, retain, accept, reject); + mapPrefix = viewsPrefix + viewName; } - - // - // If no maps were defined explicitly, add default maps. - // - if(mapsCount == 0) + else { - string groupBy = properties->getProperty(viewsPrefix + viewName + ".GroupBy"); - int retain = properties->getPropertyAsIntWithDefault(viewsPrefix + viewName + ".RetainDetached", 10); - NameValueDict accept = parseRule(properties, viewsPrefix + viewName + ".Accept"); - NameValueDict reject = parseRule(properties, viewsPrefix + viewName + ".Reject"); - for(vector<string>::const_iterator p = defaultMaps.begin(); p != defaultMaps.end(); ++p) - { - addMapToView(viewName, *p, groupBy, retain, accept, reject); - } + continue; // This map isn't configured for this view. } - } - __setNoDelete(false); -} + string groupBy = _properties->getProperty(mapPrefix + ".GroupBy"); + int retain = _properties->getPropertyAsIntWithDefault(mapPrefix + ".RetainDetached", 10); + NameValueDict accept = parseRule(_properties, mapPrefix + ".Accept"); + NameValueDict reject = parseRule(_properties, mapPrefix + ".Reject"); -void -MetricsAdminI::addUpdater(const string& mapName, const UpdaterPtr& updater) -{ - _updaters.insert(make_pair(mapName, updater)); + view->add(mapName, factory->create(groupBy, retain, accept, reject)); + } } vector<MetricsMapI::EntryPtr> @@ -419,9 +390,9 @@ MetricsAdminI::addMapToView(const string& view, map<string, MetricsViewIPtr>::const_iterator p = _views.find(view); if(p == _views.end()) { - p = _views.insert(make_pair(view, new MetricsViewI())).first; + p = _views.insert(make_pair(view, new MetricsViewI(true))).first; } - p->second->add(mapName, groupBy, retain, accept, reject); + p->second->add(mapName, _factories[mapName]->create(groupBy, retain, accept, reject)); map<string, UpdaterPtr>::const_iterator q = _updaters.find(mapName); if(q != _updaters.end()) diff --git a/cpp/src/Ice/MetricsAdminI.h b/cpp/src/Ice/MetricsAdminI.h index 8159057aa67..c8875054e4f 100644 --- a/cpp/src/Ice/MetricsAdminI.h +++ b/cpp/src/Ice/MetricsAdminI.h @@ -37,33 +37,17 @@ public: { } - template<typename MetricsType> IceInternal::Handle<MetricsType> - attach(const MetricsHelperT<MetricsType>& helper) + template<typename T> IceInternal::Handle<T> + attach(const MetricsHelperT<T>& helper) { IceUtil::Mutex::Lock sync(*this); ++_object->total; ++_object->current; - - IceInternal::Handle<MetricsType> obj = IceInternal::Handle<MetricsType>::dynamicCast(_object); + IceInternal::Handle<T> obj = IceInternal::Handle<T>::dynamicCast(_object); assert(obj); helper.initMetrics(obj); return obj; } - - void detach(long lifetime) - { - bool detached = false; - { - IceUtil::Mutex::Lock sync(*this); - detached = --_object->current == 0; - - _object->totalLifetime += lifetime; - } - if(detached) - { - _map->detached(this); - } - } void failed(const std::string& exceptionName) { @@ -71,14 +55,6 @@ public: ++_failures[exceptionName]; } - MetricsPtr - clone() const - { - IceUtil::Mutex::Lock sync(*this); - // TODO: Fix ice_clone to use a co-variant type. - return dynamic_cast<Metrics*>(_object->ice_clone().get()); - } - MetricsFailures getFailures() const { @@ -97,6 +73,28 @@ public: IceUtil::Mutex::Lock sync(*this); func(obj); } + + void detach(long lifetime) + { + bool detached = false; + { + IceUtil::Mutex::Lock sync(*this); + detached = --_object->current == 0; + _object->totalLifetime += lifetime; + } + if(detached) + { + _map->detached(this); + } + } + + MetricsPtr + clone() const + { + IceUtil::Mutex::Lock sync(*this); + // TODO: Fix ice_clone to use a co-variant type. + return dynamic_cast<Metrics*>(_object->ice_clone().get()); + } const std::string& id() const { @@ -119,11 +117,14 @@ public: MetricsMapI(const std::string&, int, const NameValueDict&, const NameValueDict&); - MetricsMap getMetrics(); MetricsFailuresSeq getFailures(); - + MetricsMap getMetrics(); EntryPtr getMatching(const MetricsHelper&); +protected: + + virtual EntryPtr newEntry(MetricsMapI*, const MetricsPtr& object) = 0; + private: friend class Entry; @@ -140,11 +141,50 @@ private: }; typedef IceUtil::Handle<MetricsMapI> MetricsMapIPtr; +class MetricsMapFactory : public IceUtil::Shared +{ +public: + + virtual MetricsMapIPtr create(const std::string&, int, const NameValueDict&, const NameValueDict&) = 0; +}; +typedef IceUtil::Handle<MetricsMapFactory> MetricsMapFactoryPtr; + +template<class MetricsType> class MetricsMapT : public MetricsMapI +{ +public: + + typedef MetricsType T; + typedef IceInternal::Handle<MetricsType> TPtr; + + class EntryT : public MetricsMapI::Entry + { + public: + + EntryT(MetricsMapI* map, const TPtr& object) : Entry(map, object) + { + } + + }; + typedef IceUtil::Handle<EntryT> EntryTPtr; + + MetricsMapT(const std::string& groupBy, int retain, const NameValueDict& accept, const NameValueDict& reject) : + MetricsMapI(groupBy, retain, accept, reject) + { + } + +protected: + + virtual EntryPtr newEntry(MetricsMapI* map, const MetricsPtr& object) + { + return new EntryT(map, TPtr::dynamicCast(object)); + } +}; + class MetricsViewI : public IceUtil::Shared { public: - MetricsViewI(); + MetricsViewI(bool); void setEnabled(bool enabled) { @@ -156,7 +196,7 @@ public: return _enabled; } - void add(const std::string&, const std::string&, int, const NameValueDict&, const NameValueDict&); + void add(const std::string&, const MetricsMapIPtr&); void remove(const std::string&); MetricsView getMetrics(); @@ -177,10 +217,12 @@ class MetricsAdminI : public MetricsAdmin, public IceUtil::Mutex { public: - MetricsAdminI(::Ice::InitializationData&); + MetricsAdminI(const ::Ice::PropertiesPtr&); std::vector<MetricsMapI::EntryPtr> getMatching(const MetricsHelper&) const; + void addUpdater(const std::string&, const UpdaterPtr&); + void addFactory(const std::string&, const MetricsMapFactoryPtr&); virtual Ice::StringSeq getMetricsViewNames(const ::Ice::Current&); virtual MetricsView getMetricsView(const std::string&, const ::Ice::Current&); @@ -197,6 +239,9 @@ private: std::map<std::string, MetricsViewIPtr> _views; std::map<std::string, UpdaterPtr> _updaters; + std::map<std::string, MetricsMapFactoryPtr> _factories; + + Ice::PropertiesPtr _properties; }; typedef IceUtil::Handle<MetricsAdminI> MetricsAdminIPtr; diff --git a/cpp/src/Ice/MetricsObserverI.h b/cpp/src/Ice/MetricsObserverI.h index 217bb353c59..0dfb46ec22a 100644 --- a/cpp/src/Ice/MetricsObserverI.h +++ b/cpp/src/Ice/MetricsObserverI.h @@ -375,13 +375,14 @@ class ObserverFactoryT public: typedef IceUtil::Handle<ObserverImplType> ObserverImplPtrType; + typedef typename ObserverImplType::Type MetricsType; ObserverFactoryT(const MetricsAdminIPtr& metrics) : _metrics(metrics) { } - template<typename MetricsHelper> ObserverImplPtrType - getObserver(const MetricsHelper& helper) + ObserverImplPtrType + getObserver(const MetricsHelperT<MetricsType>& helper) { std::vector<MetricsMapI::EntryPtr> metricsObjects = _metrics->getMatching(helper); if(metricsObjects.empty()) @@ -394,8 +395,8 @@ public: return obsv; } - template<typename MetricsHelper, typename ObserverPtrType> ObserverImplPtrType - getObserver(const MetricsHelper& helper, const ObserverPtrType& observer) + template<typename ObserverPtrType> ObserverImplPtrType + getObserver(const MetricsHelperT<MetricsType>& helper, const ObserverPtrType& observer) { std::vector<MetricsMapI::EntryPtr> metricsObjects = _metrics->getMatching(helper); if(metricsObjects.empty()) @@ -412,6 +413,22 @@ public: return obsv; } + virtual MetricsMapFactoryPtr + newFactory() + { + class Factory : public MetricsMapFactory + { + public: + + virtual MetricsMapIPtr + create(const std::string& groupBy, int retain, const NameValueDict& accept, const NameValueDict& reject) + { + return new MetricsMapT<MetricsType>(groupBy, retain, accept, reject); + } + }; + return new Factory(); + } + private: const std::string _name; diff --git a/cpp/src/Ice/ObserverI.cpp b/cpp/src/Ice/ObserverI.cpp index 5c3a461af7b..139645acebf 100644 --- a/cpp/src/Ice/ObserverI.cpp +++ b/cpp/src/Ice/ObserverI.cpp @@ -573,6 +573,12 @@ CommunicatorObserverI::CommunicatorObserverI(const MetricsAdminIPtr& metrics) : _connects(metrics), _endpointLookups(metrics) { + metrics->addFactory("Connection", _connections.newFactory()); + metrics->addFactory("Thread", _threads.newFactory()); + metrics->addFactory("Dispatch", _dispatch.newFactory()); + metrics->addFactory("Invocation", _invocations.newFactory()); + metrics->addFactory("Connect", _connects.newFactory()); + metrics->addFactory("EndpointLookups", _endpointLookups.newFactory()); } void |