diff options
author | Alexander Ignatyev <aignatyev@mirantis.com> | 2016-07-15 03:21:45 +0300 |
---|---|---|
committer | Alexander Ignatyev <aignatyev@mirantis.com> | 2016-07-18 15:10:04 +0300 |
commit | aca7aeb13384bae39172fe1186ea62e58f52e493 (patch) | |
tree | 377717610f59ca721e606932fb221a9b603b2317 | |
parent | 10f48b9cc86e44e4e22ec9ffdf3094f207e39120 (diff) | |
download | osprofiler-aca7aeb13384bae39172fe1186ea62e58f52e493.tar.gz |
OSprofiler initialization method
Added init_from_conf method, that takes service configuration
and initializes notifier. This allows initialization to be
handled in osprofiler instead of projects/services. Added
oslo.messaging dependency.
Change-Id: I77d0d3b5e9e725507916724dcd28d5fbc6f7f5c7
-rw-r--r-- | osprofiler/initializer.py | 42 | ||||
-rw-r--r-- | requirements.txt | 1 |
2 files changed, 43 insertions, 0 deletions
diff --git a/osprofiler/initializer.py b/osprofiler/initializer.py new file mode 100644 index 0000000..b518c03 --- /dev/null +++ b/osprofiler/initializer.py @@ -0,0 +1,42 @@ +# Copyright 2016 Mirantis Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import oslo_messaging + +from osprofiler import notifier +from osprofiler import web + + +def init_from_conf(conf, context, project, service, host): + """Initialize notifier from service configuration + + :param conf: service configuration + :param context: request context + :param project: project name (keystone, cinder etc.) + :param service: service name that will be profiled + :param host: hostname or host IP address that the service will be + running on. + """ + connection_str = conf.profiler.connection_string + _notifier = notifier.create( + connection_str, + messaging=oslo_messaging, + context=context, + transport=oslo_messaging.get_transport(conf), + project=project, + service=service, + host=host) + notifier.set(_notifier) + web.enable(conf.profiler.hmac_keys) diff --git a/requirements.txt b/requirements.txt index d59f2f3..04ea584 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ six>=1.9.0 # MIT +oslo.messaging>=5.2.0 # Apache-2.0 oslo.utils>=3.4.0 # Apache-2.0 WebOb>=1.2.3 # MIT |