<commit_before>import threading
from checks import Check


MAX_THREADS_COUNT = 50
MAX_COLLECTION_TIME = 30
MAX_EMIT_TIME = 5
MAX_CPU_PCT = 10
class CollectorMetrics(Check):
    def __init__(self, logger):
        Check.__init__(self, logger)
        self.logger = logger
        self.gauge('datadog.collector.collection.time')
        self.gauge('datadog.emitter.emit.time')
        self.gauge('datadog.collector.threads.count')
        self.gauge('datadog.collector.cpu.used')

    def check(self, payload, agentConfig, collection_time, emit_time, cpu_time=None):
        
        if threading.active_count() > MAX_THREADS_COUNT:
            self.save_sample('datadog.collector.threads.count', threading.active_count())
            self.logger.warning("Thread count is high: %s %s" % (threading.active_count())

        
        if collection_time > MAX_COLLECTION_TIME:
            self.save_sample('datadog.collector.collection.time', collection_time)
            self.logger.warning("Collection time is high: %s, metrics count: %s, events count: %s" 
                    % (collection_time, len(payload['metrics']), len(payload['events'])))
        
        if emit_time is not None and emit_time > MAX_EMIT_TIME:
            self.save_sample('datadog.emitter.emit.time', emit_time)
            self.logger.warning("Emit time is high: %s, metrics count: %s, events count: %s" 
                % (emit_time, len(payload['metrics']), len(payload['events'])))
        
        if cpu_time is not None:
            try:
                cpu_used_pct = 100.0 * float(cpu_time)/float(collection_time)
                if cpu_used_pct > MAX_CPU_PCT:
                    self.save_sample('datadog.collector.cpu.used', cpu_used_pct)
                    self.logger.warning("CPU consumed is high: %s, metrics count: %s, events count: %s" 
                    % (cpu_used_pct, len(payload['metrics']), len(payload['events'])))
            except Exception, e:
                self.logger.debug("Couldn't compute cpu used by collector with values %s %s %s"
                    % (cpu_time, collection_time, str(e)))
        
        return self.get_metrics()
<commit_msg>Fix a syntax error<commit_after>import threading
from checks import Check


MAX_THREADS_COUNT = 50
MAX_COLLECTION_TIME = 30
MAX_EMIT_TIME = 5
MAX_CPU_PCT = 10
class CollectorMetrics(Check):
    def __init__(self, logger):
        Check.__init__(self, logger)
        self.logger = logger
        self.gauge('datadog.collector.collection.time')
        self.gauge('datadog.emitter.emit.time')
        self.gauge('datadog.collector.threads.count')
        self.gauge('datadog.collector.cpu.used')

    def check(self, payload, agentConfig, collection_time, emit_time, cpu_time=None):
        
        if threading.active_count() > MAX_THREADS_COUNT:
            self.save_sample('datadog.collector.threads.count', threading.active_count())
            self.logger.warning("Thread count is high: %s %s" % (threading.active_count()))

        
        if collection_time > MAX_COLLECTION_TIME:
            self.save_sample('datadog.collector.collection.time', collection_time)
            self.logger.warning("Collection time is high: %s, metrics count: %s, events count: %s" 
                    % (collection_time, len(payload['metrics']), len(payload['events'])))
        
        if emit_time is not None and emit_time > MAX_EMIT_TIME:
            self.save_sample('datadog.emitter.emit.time', emit_time)
            self.logger.warning("Emit time is high: %s, metrics count: %s, events count: %s" 
                % (emit_time, len(payload['metrics']), len(payload['events'])))
        
        if cpu_time is not None:
            try:
                cpu_used_pct = 100.0 * float(cpu_time)/float(collection_time)
                if cpu_used_pct > MAX_CPU_PCT:
                    self.save_sample('datadog.collector.cpu.used', cpu_used_pct)
                    self.logger.warning("CPU consumed is high: %s, metrics count: %s, events count: %s" 
                    % (cpu_used_pct, len(payload['metrics']), len(payload['events'])))
            except Exception, e:
                self.logger.debug("Couldn't compute cpu used by collector with values %s %s %s"
                    % (cpu_time, collection_time, str(e)))
        
        return self.get_metrics()

{'fraction_non_alphanumeric': 0.11575785582255083, 'fraction_numerical': 0.005083179297597043, 'mean_word_length': 2.536764705882353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4190954', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1279, 'n_words': 275}