def process_request(self, request): # import threading # LOG.debug("===> MetricsMiddleware pid: %d thread: %d" % (os.getpid(), threading.get_ident())) self._response_timer = metrics.response_time.time() metrics.active_requests.inc() if is_gunicorn_report_enabled(): global_registry().update_metrics_shared_data()
def handle_noargs(self, **options): """Generates a Monitor Descriptor file.""" registry = global_registry() definitions = [] for schema in registry.schemas: definitions.extend(schema.to_json()) definitions.sort(lambda a, b: cmp(a['context'], b['context'])) d = { 'name': 'HUE', 'nameForCrossEntityAggregateMetrics': 'hues', 'version': 1, 'metricDefinitions': [], 'roles': [ { 'name': 'HUE_SERVER', 'nameForCrossEntityAggregateMetrics': 'hue_servers', 'metricDefinitions': definitions, }, ], } print json.dumps(d)
def report_now(self, registry=None, timestamp=None): dirname = os.path.dirname(self.location) if not os.path.exists(dirname): try: os.makedirs(dirname) except OSError as e: LOG.error('failed to make the directory %s: %s' % (dirname, e)) return # Write the metrics to a temporary file, then atomically # rename the file to the real location. f = tempfile.NamedTemporaryFile( mode='w' if sys.version_info[0] > 2 else 'w+b', dir=dirname, delete=False) try: # import threading # LOG.info("===> FileReporter pid: %d thread: %d" % (os.getpid(), threading.get_ident())) metrics_data = global_registry().get_metrics_shared_data() \ if 'rungunicornserver' in sys.argv \ else self.registry.dump_metrics() json.dump(metrics_data, f) f.close() os.rename(f.name, self.location) except Exception: LOG.exception('failed to write metrics to file') os.remove(f.name) raise
def handle_noargs(self, **options): """Generates a Monitor Descriptor file.""" registry = global_registry() definitions = [] for schema in registry.schemas: definitions.extend(schema.to_json()) d = { 'name': 'HUE', 'nameForCrossEntityAggregateMetrics': 'hues', 'version': 1, 'metricDefinitions': [], 'roles': [ { 'name': 'HUE_SERVER', 'nameForCrossEntityAggregateMetrics': 'hue_servers', 'metricDefinitions': definitions, }, ], } print json.dumps(d)
def start_file_reporter(): from desktop.conf import METRICS global _reporter if _reporter is None: location = METRICS.LOCATION.get() interval = METRICS.COLLECTION_INTERVAL.get() if location is not None and interval is not None: _reporter = FileReporter(location, reporting_interval=interval / 1000.0, registry=global_registry()) _reporter.start()
def start_file_reporter(): from desktop.conf import METRICS global _reporter if _reporter is None: location = METRICS.LOCATION.get() interval = METRICS.COLLECTION_INTERVAL.get() if location is not None and interval is not None: _reporter = FileReporter( location, reporting_interval=interval / 1000.0, registry=global_registry()) _reporter.start()
# Licensed to Cloudera, Inc. under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. Cloudera, Inc. licenses this file # to you 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. from __future__ import absolute_import from desktop.lib.metrics import global_registry saml2_authentication_time = global_registry().timer( name='auth.saml2.auth-time', label='SAML2 Authentication Time', description='The time spent waiting for SAML2 to authenticate a user', numerator='seconds', counter_numerator='authentications', rate_denominator='seconds', )
name for name in REGISTRY._names_to_collectors.keys() if name.startswith('django_') and not name.startswith(ALLOWED_DJANGO_PROMETHEUS_METRICS) ] for metric_name in django_metrics_names: collector_obj = REGISTRY._names_to_collectors[metric_name] django_collectors.add(collector_obj) for django_collector in django_collectors: REGISTRY.unregister(django_collector) global_registry().gauge_callback( name='threads.total', callback=lambda: len(threading.enumerate()), label='Threads', description='The total number of threads', numerator='threads', ) global_registry().gauge_callback( name='threads.daemon', callback=lambda: sum(1 for thread in threading.enumerate() if thread.isDaemon()), label='Daemon Threads', description='The number of daemon threads', numerator='threads', ) # ------------------------------------------------------------------------------
# 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 logging from datetime import datetime, timedelta from desktop.lib.metrics import global_registry LOG = logging.getLogger(__name__) def active_users(): from useradmin.models import UserProfile try: count = UserProfile.objects.filter(last_activity__gt=datetime.now() - timedelta(hours=1)).count() except: LOG.exception('Could not get active_users') count = 0 return count global_registry().gauge_callback( name='users.active', callback=active_users, label='Active Users', description='Number of users that were active in the last hour', numerator='users', )
# to you 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. from datetime import datetime, timedelta from desktop.lib.metrics import global_registry def active_users(): from useradmin.models import UserProfile return UserProfile.objects.filter(last_activity__gt=datetime.now() - timedelta(hours=1)).count() global_registry().gauge_callback( name='users.active', callback=active_users, label='Number of active users', description='Number of active users in the last hour', numerator='active users', )
def process_response(self, request, response): self._response_timer.stop() metrics.active_requests.dec() if is_gunicorn_report_enabled(): global_registry().update_metrics_shared_data() return response
# Licensed to Cloudera, Inc. under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. Cloudera, Inc. licenses this file # to you 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. from __future__ import absolute_import from desktop.lib.metrics import global_registry saml2_authentication_time = global_registry().timer( name='desktop.auth.saml2.authentication-time', label='SAML2 Authentication time', description='Time taken to authenticate a user with SAML2', numerator='s', counter_numerator='auths', rate_denominator='seconds', )
from __future__ import absolute_import import gc import multiprocessing import threading from django.contrib.auth.models import User from django.contrib.auth.signals import user_logged_in, user_logged_out from django.db.models.signals import post_save, post_delete from django.dispatch import receiver from desktop.lib.metrics import global_registry global_registry().gauge_callback( name='python.threads.count', callback=lambda: len(threading.enumerate()), label='Thread count', description='Number of threads', ) global_registry().gauge_callback( name='python.threads.active', callback=lambda: threading.active_count(), label='Active thread count', description='Number of active threads', ) global_registry().gauge_callback( name='python.threads.daemon', callback=lambda: sum(1 for thread in threading.enumerate() if thread.isDaemon()), label='Daemon thread count',
# Licensed to Cloudera, Inc. under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. Cloudera, Inc. licenses this file # to you 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. from __future__ import absolute_import from desktop.lib.metrics import global_registry openid_authentication_time = global_registry().timer( name='desktop.auth.openid.authentication-time', label='OpenID Authentication time', description='Time taken to authenticate a user with OpenID', numerator='s', counter_numerator='auths', rate_denominator='seconds', )
from __future__ import absolute_import import gc import multiprocessing import threading from django.contrib.auth.models import User from django.contrib.auth.signals import user_logged_in, user_logged_out from django.db.models.signals import post_save, post_delete from django.dispatch import receiver from desktop.lib.metrics import global_registry global_registry().gauge_callback( name='python.threads.count', callback=lambda: len(threading.enumerate()), label='Thread count', description='Number of threads', ) global_registry().gauge_callback( name='python.threads.active', callback=lambda: threading.active_count(), label='Active thread count', description='Number of active threads', ) global_registry().gauge_callback( name='python.threads.daemon', callback=lambda: sum(1 for thread in threading.enumerate() if thread.isDaemon()), label='Daemon thread count', description='Number of daemon threads',
def active_users(): from useradmin.models import UserProfile try: count = UserProfile.objects.filter(last_activity__gt=datetime.now() - timedelta(hours=1)).count() except: LOG.exception('Could not get active_users') count = 0 return count global_registry().gauge_callback( name='users.active', callback=active_users, label='Active Users', description='Number of users that were active in the last hour', numerator='users', ) def active_users_per_instance(): from useradmin.models import UserProfile try: count = UserProfile.objects.filter( last_activity__gt=datetime.now() - timedelta(hours=1), hostname=get_localhost_name()).count() except: LOG.exception('Could not get active_users per instance') count = 0 return count
# Licensed to Cloudera, Inc. under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. Cloudera, Inc. licenses this file # to you 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. from __future__ import absolute_import from desktop.lib.metrics import global_registry openid_authentication_time = global_registry().timer( name='auth.openid.auth-time', label='OpenID Authentication Time', description='The time spent waiting for OpenID to authenticate a user', numerator='seconds', counter_numerator='authentications', rate_denominator='seconds', )
# limitations under the License. from __future__ import absolute_import import gc import multiprocessing import threading from django.contrib.auth.models import User from desktop.lib.metrics import global_registry global_registry().gauge_callback( name='threads.total', callback=lambda: len(threading.enumerate()), label='Threads', description='The total number of threads', numerator='threads', ) global_registry().gauge_callback( name='threads.daemon', callback=lambda: sum(1 for thread in threading.enumerate() if thread.isDaemon()), label='Daemon Threads', description='The number of daemon threads', numerator='threads', ) # ------------------------------------------------------------------------------ global_registry().gauge_callback(
# Licensed to Cloudera, Inc. under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. Cloudera, Inc. licenses this file # to you 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. from __future__ import absolute_import from desktop.lib.metrics import global_registry openid_authentication_time = global_registry().timer( name='desktop.auth.openid.authentication-time', label='OpenID Authentication time', description='Time taken to authenticate a user with OpenID', )
from __future__ import absolute_import import gc import multiprocessing import threading from django.contrib.auth.models import User from django.contrib.auth.signals import user_logged_in, user_logged_out from django.dispatch import receiver from desktop.lib.metrics import global_registry global_registry().gauge_callback( name='python.threads.count', callback=lambda: len(threading.enumerate()), label='Thread count', description='Number of threads', numerator='threads', ) global_registry().gauge_callback( name='python.threads.active', callback=lambda: threading.active_count(), label='Active thread count', description='Number of active threads', numerator='threads', ) global_registry().gauge_callback( name='python.threads.daemon', callback=lambda: sum(1 for thread in threading.enumerate()
# Licensed to Cloudera, Inc. under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. Cloudera, Inc. licenses this file # to you 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. from __future__ import absolute_import from desktop.lib.metrics import global_registry saml2_authentication_time = global_registry().timer( name='desktop.auth.saml2.authentication-time', label='SAML2 Authentication time', description='Time taken to authenticate a user with SAML2', )