(self, data, base_prefix)
Publish values of type: counter or percent
Publish values of type: counter or percent
Publish values of type : counter or percent
def _publish_transformed(self, data, base_prefix):
        """ Publish values of type: counter or percent """
        self._publish_dict_with_prefix(data.get('opcounters', {}),
                                       base_prefix + ['opcounters_per_sec'],
                                       self.publish_counter)
        self._publish_dict_with_prefix(data.get('opcountersRepl', {}),
                                       base_prefix +
                                       ['opcountersRepl_per_sec'],
                                       self.publish_counter)
        self._publish_dict_with_prefix(data.get('network', {}),
                                       base_prefix + ['network_per_sec'],
                                       self.publish_counter)
        self._publish_metrics(base_prefix + ['extra_info_per_sec'],
                              'page_faults',
                              data.get('extra_info', {}),
                              self.publish_counter)

        def get_dotted_value(data, key_name):
            key_name = key_name.split('.')
            for i in key_name:
                data = data.get(i, {})
                if not data:
                    return 0
            return data

        def compute_interval(data, total_name):
            current_total = get_dotted_value(data, total_name)
            total_key = '.'.join(base_prefix + [total_name])
            last_total = self.__totals.get(total_key, current_total)
            interval = current_total - last_total
            self.__totals[total_key] = current_total
            return interval

        def publish_percent(value_name, total_name, data):
            value = float(get_dotted_value(data, value_name) * 100)
            interval = compute_interval(data, total_name)
            key = '.'.join(base_prefix + ['percent', value_name])
            self.publish_counter(key, value, time_delta=bool(interval),
                                 interval=interval)

        publish_percent('globalLock.lockTime', 'globalLock.totalTime', data)

        locks = data.get('locks')
        if locks:
            if '.' in locks:
                locks['_global_'] = locks['.']
                del (locks['.'])
            key_prefix = '.'.join(base_prefix + ['percent'])
            db_name_filter = re.compile(self.config['databases'])
            interval = compute_interval(data, 'uptimeMillis')
            for db_name in locks:
                if not db_name_filter.search(db_name):
                    continue
                r = get_dotted_value(
                    locks,
                    '%s.timeLockedMicros.r' % db_name)
                R = get_dotted_value(
                    locks,
                    '.%s.timeLockedMicros.R' % db_name)
                value = float(r + R) / 10
                if value:
                    self.publish_counter(
                        key_prefix + '.locks.%s.read' % db_name,
                        value, time_delta=bool(interval),
                        interval=interval)
                w = get_dotted_value(
                    locks,
                    '%s.timeLockedMicros.w' % db_name)
                W = get_dotted_value(
                    locks,
                    '%s.timeLockedMicros.W' % db_name)
                value = float(w + W) / 10
                if value:
                    self.publish_counter(
                        key_prefix + '.locks.%s.write' % db_name,
                        value, time_delta=bool(interval), interval=interval)
def _publish_transformed ( self , data , base_prefix ) : self . _publish_dict_with_prefix ( data . get ( 'opcounters' , { } ) , base_prefix + [ 'opcounters_per_sec' ] , self . publish_counter ) self . _publish_dict_with_prefix ( data . get ( 'opcountersRepl' , { } ) , base_prefix + [ 'opcountersRepl_per_sec' ] , self . publish_counter ) self . _publish_dict_with_prefix ( data . get ( 'network' , { } ) , base_prefix + [ 'network_per_sec' ] , self . publish_counter ) self . _publish_metrics ( base_prefix + [ 'extra_info_per_sec' ] , 'page_faults' , data . get ( 'extra_info' , { } ) , self . publish_counter ) def get_dotted_value ( data , key_name ) : key_name = key_name . split ( '.' ) for i in key_name : data = data . get ( i , { } ) if not data : return 0 return data def compute_interval ( data , total_name ) : current_total = get_dotted_value ( data , total_name ) total_key = '.' . join ( base_prefix + [ total_name ] ) last_total = self . __totals . get ( total_key , current_total ) interval = current_total - last_total self . __totals [ total_key ] = current_total return interval def publish_percent ( value_name , total_name , data ) : value = float ( get_dotted_value ( data , value_name ) * 100 ) interval = compute_interval ( data , total_name ) key = '.' . join ( base_prefix + [ 'percent' , value_name ] ) self . publish_counter ( key , value , time_delta = bool ( interval ) , interval = interval ) publish_percent ( 'globalLock.lockTime' , 'globalLock.totalTime' , data ) locks = data . get ( 'locks' ) if locks : if '.' in locks : locks [ '_global_' ] = locks [ '.' ] del ( locks [ '.' ] ) key_prefix = '.' . join ( base_prefix + [ 'percent' ] ) db_name_filter = re . compile ( self . config [ 'databases' ] ) interval = compute_interval ( data , 'uptimeMillis' ) for db_name in locks : if not db_name_filter . search ( db_name ) : continue r = get_dotted_value ( locks , '%s.timeLockedMicros.r' % db_name ) R = get_dotted_value ( locks , '.%s.timeLockedMicros.R' % db_name ) value = float ( r + R ) / 10 if value : self . publish_counter ( key_prefix + '.locks.%s.read' % db_name , value , time_delta = bool ( interval ) , interval = interval ) w = get_dotted_value ( locks , '%s.timeLockedMicros.w' % db_name ) W = get_dotted_value ( locks , '%s.timeLockedMicros.W' % db_name ) value = float ( w + W ) / 10 if value : self . publish_counter ( key_prefix + '.locks.%s.write' % db_name , value , time_delta = bool ( interval ) , interval = interval )