Преглед изворни кода

[desktop] Progress on script to generate mdl config

Erick Tryzelaar пре 10 година
родитељ
комит
5872262203

+ 10 - 4
desktop/core/src/desktop/lib/metrics/registry.py

@@ -32,8 +32,12 @@ class MetricsRegistry(object):
   def _register_schema(self, schema):
   def _register_schema(self, schema):
     self._schemas.append(schema)
     self._schemas.append(schema)
 
 
+  @property
+  def schemas(self):
+    return list(self._schemas)
+
   def counter(self, name, **kwargs):
   def counter(self, name, **kwargs):
-    self._schemas.append(MetricDefinition('counter', name, **kwargs))
+    self._schemas.append(MetricDefinition('counter', name, is_counter=True, **kwargs))
     return self._registry.counter(name)
     return self._registry.counter(name)
 
 
   def histogram(self, name, **kwargs):
   def histogram(self, name, **kwargs):
@@ -61,10 +65,10 @@ class MetricsRegistry(object):
 
 
 
 
 class MetricDefinition(object):
 class MetricDefinition(object):
-  def __init__(self, metric_type, name, label,
-      description=None,
-      numerator=None,
+  def __init__(self, metric_type, name, label, description, numerator,
       denominator=None,
       denominator=None,
+      is_counter=False,
+      weighting_metric_name=None,
       context=None):
       context=None):
     self.metric_type = metric_type
     self.metric_type = metric_type
     self.name = name
     self.name = name
@@ -72,6 +76,8 @@ class MetricDefinition(object):
     self.description = description
     self.description = description
     self.numerator = numerator
     self.numerator = numerator
     self.denominator = denominator
     self.denominator = denominator
+    self.is_counter = is_counter
+    self.weighting_metric_name = weighting_metric_name
     self.context = context
     self.context = context
 
 
 
 

+ 76 - 0
desktop/core/src/desktop/management/commands/generate_mdl.py

@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+# 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.
+"""
+Dumps a Cloudera Manager Monitor Descriptor file.
+"""
+
+import json
+
+from django.core.management.base import NoArgsCommand
+
+# Force loading the metrics
+import desktop.urls
+from desktop.lib.metrics import global_registry
+
+
+class Command(NoArgsCommand):
+  def handle_noargs(self, **options):
+    """Generates a Monitor Descriptor file."""
+    registry = global_registry()
+    metrics = registry.dump_metrics()
+    definitions = []
+
+    for schema in registry.schemas:
+      metric = metrics[schema.name]
+      for key in metric.iterkeys():
+        definition = {
+          'context': '%s::%s::%s' % (schema.metric_type, schema.name, key),
+          'name': '%s_%s' % (schema.name.replace('.', '_').replace('-', '_'), key),
+          'label': schema.label,
+          'description': schema.description,
+          'numeratorUnit': schema.numerator,
+          'counter': schema.is_counter,
+        }
+
+        if schema.denominator is not None:
+          definition['denominatorUnit'] = schema.denominator
+
+        if schema.weighting_metric_name is not None:
+          definition['weightingMetricName'] = schema.weighting_metric_name
+
+        definitions.append(definition)
+
+    d = {
+        'name': 'HUE',
+        'nameForCrossEntityAggregateMetrics': 'hues',
+        'version': 1,
+        'metricDefinitions': [],
+        'compability': {
+          'cdhVersion': {
+            'min': '5.5',
+          },
+        },
+        'roles': [
+          {
+            'name': 'HUE_SERVER',
+            'nameForCrossEntityAggregateMetrics': 'hue_servers',
+            'metricDefinitions': definitions,
+          },
+        ],
+    }
+
+    print json.dumps(d)

+ 20 - 1
desktop/core/src/desktop/metrics.py

@@ -32,6 +32,7 @@ global_registry().gauge_callback(
     callback=lambda: len(threading.enumerate()),
     callback=lambda: len(threading.enumerate()),
     label='Thread count',
     label='Thread count',
     description='Number of threads',
     description='Number of threads',
+    numerator='threads',
 )
 )
 
 
 global_registry().gauge_callback(
 global_registry().gauge_callback(
@@ -39,6 +40,7 @@ global_registry().gauge_callback(
     callback=lambda: threading.active_count(),
     callback=lambda: threading.active_count(),
     label='Active thread count',
     label='Active thread count',
     description='Number of active threads',
     description='Number of active threads',
+    numerator='threads',
 )
 )
 
 
 global_registry().gauge_callback(
 global_registry().gauge_callback(
@@ -46,6 +48,7 @@ global_registry().gauge_callback(
     callback=lambda: sum(1 for thread in threading.enumerate() if thread.isDaemon()),
     callback=lambda: sum(1 for thread in threading.enumerate() if thread.isDaemon()),
     label='Daemon thread count',
     label='Daemon thread count',
     description='Number of daemon threads',
     description='Number of daemon threads',
+    numerator='threads',
 )
 )
 
 
 # ------------------------------------------------------------------------------
 # ------------------------------------------------------------------------------
@@ -55,6 +58,7 @@ global_registry().gauge_callback(
     callback=lambda: len(multiprocessing.active_children()),
     callback=lambda: len(multiprocessing.active_children()),
     label='Process count',
     label='Process count',
     description='Number of multiprocessing processes',
     description='Number of multiprocessing processes',
+    numerator='processes',
 )
 )
 
 
 global_registry().gauge_callback(
 global_registry().gauge_callback(
@@ -62,6 +66,7 @@ global_registry().gauge_callback(
     callback=lambda: sum(1 for proc in multiprocessing.active_children() if proc.is_alive()),
     callback=lambda: sum(1 for proc in multiprocessing.active_children() if proc.is_alive()),
     label='Active multiprocessing processes',
     label='Active multiprocessing processes',
     description='Number of active multiprocessing processes',
     description='Number of active multiprocessing processes',
+    numerator='processes',
 )
 )
 
 
 global_registry().gauge_callback(
 global_registry().gauge_callback(
@@ -69,6 +74,7 @@ global_registry().gauge_callback(
     callback=lambda: sum(1 for proc in multiprocessing.active_children() if proc.daemon),
     callback=lambda: sum(1 for proc in multiprocessing.active_children() if proc.daemon),
     label='Daemon processes count',
     label='Daemon processes count',
     description='Number of daemon multiprocessing processes',
     description='Number of daemon multiprocessing processes',
+    numerator='processes',
 )
 )
 
 
 # ------------------------------------------------------------------------------
 # ------------------------------------------------------------------------------
@@ -79,6 +85,7 @@ for i in xrange(3):
       callback=lambda: gc.get_count()[i],
       callback=lambda: gc.get_count()[i],
       label='GC collection count %s' % i,
       label='GC collection count %s' % i,
       description='Current collection counts',
       description='Current collection counts',
+      numerator='collections',
   )
   )
 
 
 global_registry().gauge_callback(
 global_registry().gauge_callback(
@@ -86,6 +93,7 @@ global_registry().gauge_callback(
     callback=lambda: len(gc.get_objects()),
     callback=lambda: len(gc.get_objects()),
     label='GC tracked object count',
     label='GC tracked object count',
     description='Number of objects being tracked by the garbage collector',
     description='Number of objects being tracked by the garbage collector',
+    numerator='objects',
 )
 )
 
 
 global_registry().gauge_callback(
 global_registry().gauge_callback(
@@ -93,6 +101,7 @@ global_registry().gauge_callback(
     callback=lambda: len(gc.get_referrers()),
     callback=lambda: len(gc.get_referrers()),
     label='GC tracked object referrers',
     label='GC tracked object referrers',
     description='Number of objects that directly refer to any objects',
     description='Number of objects that directly refer to any objects',
+    numerator='referrers',
 )
 )
 
 
 global_registry().gauge_callback(
 global_registry().gauge_callback(
@@ -100,6 +109,7 @@ global_registry().gauge_callback(
     callback=lambda: len(gc.get_referrers()),
     callback=lambda: len(gc.get_referrers()),
     label='GC tracked object referents',
     label='GC tracked object referents',
     description='Number of objects that directly referred to any objects',
     description='Number of objects that directly referred to any objects',
+    numerator='referents',
 )
 )
 
 
 # ------------------------------------------------------------------------------
 # ------------------------------------------------------------------------------
@@ -108,18 +118,21 @@ active_requests = global_registry().counter(
     name='desktop.requests.active.count',
     name='desktop.requests.active.count',
     label='Active requests',
     label='Active requests',
     description='Number of currently active requests',
     description='Number of currently active requests',
+    numerator='active requests',
 )
 )
 
 
 request_exceptions = global_registry().counter(
 request_exceptions = global_registry().counter(
     name='desktop.requests.exceptions.count',
     name='desktop.requests.exceptions.count',
     label='Request exceptions',
     label='Request exceptions',
     description='Number requests that resulted in an exception',
     description='Number requests that resulted in an exception',
+    numerator='failed requests',
 )
 )
 
 
 response_time = global_registry().timer(
 response_time = global_registry().timer(
     name='desktop.requests.aggregate-response-time',
     name='desktop.requests.aggregate-response-time',
     label='Request aggregate response time',
     label='Request aggregate response time',
-    description='Time taken to respond to requests'
+    description='Time taken to respond to requests',
+    numerator='seconds',
 )
 )
 
 
 # ------------------------------------------------------------------------------
 # ------------------------------------------------------------------------------
@@ -128,6 +141,7 @@ user_count = global_registry().gauge(
     name='desktop.users.count',
     name='desktop.users.count',
     label='User count',
     label='User count',
     description='Total number of users',
     description='Total number of users',
+    numerator='users',
 )
 )
 
 
 # Initialize with the current user count.
 # Initialize with the current user count.
@@ -146,6 +160,7 @@ logged_in_users = global_registry().counter(
     name='desktop.users.logged-in.count',
     name='desktop.users.logged-in.count',
     label='Number of logged in users',
     label='Number of logged in users',
     description='Number of logged in users',
     description='Number of logged in users',
+    numerator='logged in users',
 )
 )
 
 
 @receiver(user_logged_in)
 @receiver(user_logged_in)
@@ -162,22 +177,26 @@ ldap_authentication_time = global_registry().timer(
     name='desktop.auth.ldap.authentication-time',
     name='desktop.auth.ldap.authentication-time',
     label='LDAP Authentication time',
     label='LDAP Authentication time',
     description='Time taken to authenticate a user with LDAP',
     description='Time taken to authenticate a user with LDAP',
+    numerator='seconds',
 )
 )
 
 
 oauth_authentication_time = global_registry().timer(
 oauth_authentication_time = global_registry().timer(
     name='desktop.auth.oauth.authentication-time',
     name='desktop.auth.oauth.authentication-time',
     label='OAUTH Authentication time',
     label='OAUTH Authentication time',
     description='Time taken to authenticate a user with OAUTH',
     description='Time taken to authenticate a user with OAUTH',
+    numerator='seconds',
 )
 )
 
 
 pam_authentication_time = global_registry().timer(
 pam_authentication_time = global_registry().timer(
     name='desktop.auth.pam.authentication-time',
     name='desktop.auth.pam.authentication-time',
     label='PAM Authentication time',
     label='PAM Authentication time',
     description='Time taken to authenticate a user with PAM',
     description='Time taken to authenticate a user with PAM',
+    numerator='seconds',
 )
 )
 
 
 spnego_authentication_time = global_registry().timer(
 spnego_authentication_time = global_registry().timer(
     name='desktop.auth.spnego.authentication-time',
     name='desktop.auth.spnego.authentication-time',
     label='SPNEGO Authentication time',
     label='SPNEGO Authentication time',
     description='Time taken to authenticate a user with SPNEGO',
     description='Time taken to authenticate a user with SPNEGO',
+    numerator='seconds',
 )
 )