Prechádzať zdrojové kódy

[desktop] Metric description improvements

This removes a couple expensive and duplicate metrics
Erick Tryzelaar 10 rokov pred
rodič
commit
f45fb424ea

+ 3 - 3
apps/useradmin/src/useradmin/metrics.py

@@ -25,7 +25,7 @@ def active_users():
 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',
+    label='Number of Active Users',
+    description='Number of users that were active in the last hour',
+    numerator='users',
 )

+ 98 - 31
desktop/core/src/desktop/lib/metrics/registry.py

@@ -98,17 +98,29 @@ class MetricDefinition(object):
     raise NotImplementedError
 
 
-  def _make_json(self, key, **kwargs):
+  def _make_json(self, key,
+      suffix=None,
+      **kwargs):
     names = ['hue', self.name.replace('.', '_').replace('-', '_')]
 
+    label = self.label
+    description = self.description
+
+    if suffix:
+      label += suffix
+      description += suffix
+
     if self._add_key_to_name:
       names.append(key)
 
+    if 'counter' in kwargs and not kwargs['counter']:
+      kwargs.pop('counter')
+
     mdl = dict(
       context='%s::%s' % (self.name, key),
       name='_'.join(names),
-      label=self.label,
-      description=self.description,
+      label=label,
+      description=description,
       numeratorUnit=self.numerator,
     )
     mdl.update(**kwargs)
@@ -144,15 +156,28 @@ class HistogramDefinition(MetricDefinition):
 
   def to_json(self):
     return [
-        self._make_json('max'),
-        self._make_json('min'),
-        self._make_json('avg'),
-        self._make_json('count', counter=True, numeratorUnit=self.counter_numerator),
-        self._make_json('std_dev'),
-        self._make_json('75_percentile'),
-        self._make_json('95_percentile'),
-        self._make_json('99_percentile'),
-        self._make_json('999_percentile'),
+        self._make_json('max',
+          suffix=': Max'),
+        self._make_json('min',
+          suffix=': Min'),
+        self._make_json('avg',
+          suffix=': Average'),
+        self._make_json('count',
+          suffix=': Samples',
+          counter=True,
+          numeratorUnit=self.counter_numerator),
+        self._make_json('std_dev',
+          suffix=': Standard Deviation'),
+        self._make_json('median',
+          suffix=': 50th Percentile'),
+        self._make_json('75_percentile',
+          suffix=': 75th Percentile'),
+        self._make_json('95_percentile',
+          suffix=': 95th Percentile'),
+        self._make_json('99_percentile',
+          suffix=': 99th Percentile'),
+        self._make_json('999_percentile',
+          suffix=': 999th Percentile'),
     ]
 
 
@@ -186,11 +211,25 @@ class MeterDefinition(MetricDefinition):
 
   def to_json(self):
     return [
-        self._make_json('count', counter=True, numeratorUnit=self.counter_numerator),
-        self._make_json('15m_rate', numeratorUnit=self.counter_numerator, denominatorUnit=self.rate_denominator),
-        self._make_json('5m_rate', numeratorUnit=self.counter_numerator, denominatorUnit=self.rate_denominator),
-        self._make_json('1m_rate', numeratorUnit=self.counter_numerator, denominatorUnit=self.rate_denominator),
-        self._make_json('mean_rate', numeratorUnit=self.counter_numerator, denominatorUnit=self.rate_denominator),
+        self._make_json('count',
+          counter=True,
+          numeratorUnit=self.counter_numerator),
+        self._make_json('15m_rate',
+          suffix=': 15 Minute Rate',
+          numeratorUnit=self.counter_numerator,
+          denominatorUnit=self.rate_denominator),
+        self._make_json('5m_rate',
+          suffix=': 5 Minute Rate',
+          numeratorUnit=self.counter_numerator,
+          denominatorUnit=self.rate_denominator),
+        self._make_json('1m_rate',
+          suffix=': 1 Minute Rate',
+          numeratorUnit=self.counter_numerator,
+          denominatorUnit=self.rate_denominator),
+        self._make_json('mean_rate',
+          suffix=': Mean Rate',
+          numeratorUnit=self.counter_numerator,
+          denominatorUnit=self.rate_denominator),
     ]
 
 
@@ -209,20 +248,48 @@ class TimerDefinition(MetricDefinition):
 
   def to_json(self):
     return [
-        self._make_json('avg'),
-        self._make_json('sum'),
-        self._make_json('count', counter=True, numeratorUnit=self.counter_numerator),
-        self._make_json('max'),
-        self._make_json('min'),
-        self._make_json('std_dev'),
-        self._make_json('15m_rate', numeratorUnit=self.counter_numerator, denominatorUnit=self.rate_denominator),
-        self._make_json('5m_rate', numeratorUnit=self.counter_numerator, denominatorUnit=self.rate_denominator),
-        self._make_json('1m_rate', numeratorUnit=self.counter_numerator, denominatorUnit=self.rate_denominator),
-        self._make_json('mean_rate', numeratorUnit=self.counter_numerator, denominatorUnit=self.rate_denominator),
-        self._make_json('75_percentile'),
-        self._make_json('95_percentile'),
-        self._make_json('99_percentile'),
-        self._make_json('999_percentile'),
+        self._make_json('max',
+          suffix=': Max'),
+        self._make_json('min',
+          suffix=': Min'),
+        self._make_json('avg',
+          suffix=': Average'),
+        self._make_json('sum',
+          suffix=': Samples',
+          counter=True,
+          numeratorUnit=self.counter_numerator),
+        #self._make_json('count',
+        #  suffix=': Samples',
+        #  counter=True,
+        #  numeratorUnit=self.counter_numerator),
+        self._make_json('std_dev',
+          suffix=': Standard Deviation'),
+        self._make_json('1m_rate',
+          suffix=': 1 Minute Rate',
+          numeratorUnit=self.counter_numerator,
+          denominatorUnit=self.rate_denominator),
+        self._make_json('5m_rate',
+          suffix=': 5 Minute Rate',
+          numeratorUnit=self.counter_numerator,
+          denominatorUnit=self.rate_denominator),
+        self._make_json('15m_rate',
+          suffix=': 15 Minue Rate',
+          numeratorUnit=self.counter_numerator,
+          denominatorUnit=self.rate_denominator),
+        #self._make_json('mean_rate',
+        #  suffix=': Mean Rate',
+        #  numeratorUnit=self.counter_numerator,
+        #  denominatorUnit=self.rate_denominator),
+        self._make_json('median',
+          suffix=': 50th Percentile'),
+        self._make_json('75_percentile',
+          suffix=': 75th Percentile'),
+        self._make_json('95_percentile',
+          suffix=': 95th Percentile'),
+        self._make_json('99_percentile',
+          suffix=': 99th Percentile'),
+        self._make_json('999_percentile',
+          suffix=': 999th Percentile'),
     ]
 
 

+ 36 - 75
desktop/core/src/desktop/metrics.py

@@ -21,31 +21,21 @@ 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.total',
     callback=lambda: len(threading.enumerate()),
-    label='Thread count',
+    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() if thread.isDaemon()),
-    label='Daemon thread count',
+    label='Daemon Thread Count',
     description='Number of daemon threads',
     numerator='threads',
 )
@@ -55,7 +45,7 @@ global_registry().gauge_callback(
 global_registry().gauge_callback(
     name='python.multiprocessing.total',
     callback=lambda: len(multiprocessing.active_children()),
-    label='Process count',
+    label='Process Count',
     description='Number of multiprocessing processes',
     numerator='processes',
 )
@@ -63,7 +53,7 @@ global_registry().gauge_callback(
 global_registry().gauge_callback(
     name='python.multiprocessing.active',
     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',
     numerator='processes',
 )
@@ -71,7 +61,7 @@ global_registry().gauge_callback(
 global_registry().gauge_callback(
     name='python.multiprocessing.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',
     numerator='processes',
 )
@@ -80,57 +70,43 @@ global_registry().gauge_callback(
 
 for i in xrange(3):
   global_registry().gauge_callback(
-      name='python.gc.collection.count%s' % i,
+      name='python.gc.generation.%s' % i,
       callback=lambda: gc.get_count()[i],
-      label='GC collection count %s' % i,
-      description='Current collection counts',
-      numerator='collections',
+      label='GC Object Count in Generation %s' % i,
+      description='Total number of objects in garbage collection generation %s' % i,
+      numerator='objects',
+      raw_counter=True,
   )
 
 global_registry().gauge_callback(
     name='python.gc.objects',
-    callback=lambda: len(gc.get_objects()),
-    label='GC tracked object count',
-    description='Number of objects being tracked by the garbage collector',
+    callback=lambda: sum(gc.get_count()),
+    label='GC Object Count',
+    description='Total number of objects in the Python process',
     numerator='objects',
-)
-
-global_registry().gauge_callback(
-    name='python.gc.referrers',
-    callback=lambda: len(gc.get_referrers()),
-    label='GC tracked object referrers',
-    description='Number of objects that directly refer to any objects',
-    numerator='referrers',
-)
-
-global_registry().gauge_callback(
-    name='python.gc.referents',
-    callback=lambda: len(gc.get_referrers()),
-    label='GC tracked object referents',
-    description='Number of objects that directly referred to any objects',
-    numerator='referents',
+    raw_counter=True,
 )
 
 # ------------------------------------------------------------------------------
 
 active_requests = global_registry().counter(
     name='requests.active',
-    label='Active requests',
+    label='Active Requests',
     description='Number of currently active requests',
-    numerator='active requests',
+    numerator='requests',
 )
 
 request_exceptions = global_registry().counter(
     name='requests.exceptions',
-    label='Request exceptions',
+    label='Request Exceptions',
     description='Number requests that resulted in an exception',
-    numerator='failed requests',
+    numerator='requests',
 )
 
 response_time = global_registry().timer(
-    name='requests.aggregate-response-time',
-    label='Request aggregate response time',
-    description='Time taken to respond to requests',
+    name='requests.response-time',
+    label='Request Response Time',
+    description='Time taken to respond to requests across all Hue endpoints',
     numerator='seconds',
     counter_numerator='requests',
     rate_denominator='seconds',
@@ -139,62 +115,47 @@ response_time = global_registry().timer(
 # ------------------------------------------------------------------------------
 
 user_count = global_registry().gauge_callback(
-    name='users.total',
+    name='users',
     callback=lambda: User.objects.count(),
-    label='User count',
-    description='Total number of users',
+    label='Users',
+    description='Total number of user accounts in Hue',
     numerator='users',
 )
 
-logged_in_users = global_registry().counter(
-    name='users.logged-in',
-    label='Number of logged in users',
-    description='Number of logged in users',
-    numerator='logged in users',
-)
-
-@receiver(user_logged_in)
-def user_logged_in_handler(sender, **kwargs):
-  logged_in_users.inc()
-
-@receiver(user_logged_out)
-def user_logged_out_handler(sender, **kwargs):
-  logged_in_users.dec()
-
 # ------------------------------------------------------------------------------
 
 ldap_authentication_time = global_registry().timer(
     name='ldap.authentication-time',
-    label='LDAP Authentication time',
-    description='Time taken to authenticate a user with LDAP',
+    label='LDAP Authentication Time',
+    description='The time spent waiting for LDAP to authenticate a user over the life of the process',
     numerator='seconds',
-    counter_numerator='auths',
+    counter_numerator='authentications',
     rate_denominator='seconds',
 )
 
 oauth_authentication_time = global_registry().timer(
     name='auth.oauth.authentication-time',
-    label='OAUTH Authentication time',
-    description='Time taken to authenticate a user with OAUTH',
+    label='OAUTH Authentication Time',
+    description='The time spent waiting for OAUTH to authenticate a user over the life of the process',
     numerator='seconds',
-    counter_numerator='auths',
+    counter_numerator='authentications',
     rate_denominator='seconds',
 )
 
 pam_authentication_time = global_registry().timer(
     name='auth.pam.authentication-time',
-    label='PAM Authentication time',
-    description='Time taken to authenticate a user with PAM',
+    label='PAM Authentication Time',
+    description='The time spent waiting for PAM to authenticate a user over the life of the process',
     numerator='seconds',
-    counter_numerator='auths',
+    counter_numerator='authentications',
     rate_denominator='seconds',
 )
 
 spnego_authentication_time = global_registry().timer(
     name='auth.spnego.authentication-time',
-    label='SPNEGO Authentication time',
-    description='Time taken to authenticate a user with SPNEGO',
+    label='SPNEGO Authentication Time',
+    description='The time spent waiting for SPNEGO to authenticate a user over the life of the process',
     numerator='seconds',
-    counter_numerator='auths',
+    counter_numerator='authentications',
     rate_denominator='seconds',
 )

+ 4 - 4
desktop/libs/libopenid/src/libopenid/metrics.py

@@ -20,9 +20,9 @@ from desktop.lib.metrics import global_registry
 
 openid_authentication_time = global_registry().timer(
     name='openid.authentication-time',
-    label='OpenID Authentication time',
-    description='Time taken to authenticate a user with OpenID',
-    numerator='s',
-    counter_numerator='auths',
+    label='OpenID Authentication Time',
+    description='The time spent waiting for OpenID to authenticate a user over the life of the process',
+    numerator='seconds',
+    counter_numerator='authentications',
     rate_denominator='seconds',
 )

+ 4 - 4
desktop/libs/libsaml/src/libsaml/metrics.py

@@ -20,9 +20,9 @@ from desktop.lib.metrics import global_registry
 
 saml2_authentication_time = global_registry().timer(
     name='saml2.authentication-time',
-    label='SAML2 Authentication time',
-    description='Time taken to authenticate a user with SAML2',
-    numerator='s',
-    counter_numerator='auths',
+    label='SAML2 Authentication Time',
+    description='The time spent waiting for SAML2 to authenticate a user over the life of the process',
+    numerator='seconds',
+    counter_numerator='authentications',
     rate_denominator='seconds',
 )