Skip to content

Commit

Permalink
Properly cache http profiler (DataDog#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored Dec 19, 2018
1 parent fef38af commit 9b8f8ed
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions filebeat/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import simplejson

# project
from checks import AgentCheck
from datadog_checks.checks import AgentCheck
from datadog_checks.utils.containers import hash_mutable


EVENT_TYPE = SOURCE_TYPE_NAME = 'filebeat'
Expand Down Expand Up @@ -205,11 +206,19 @@ class FilebeatCheck(AgentCheck):

def __init__(self, *args, **kwargs):
AgentCheck.__init__(self, *args, **kwargs)
self.instance_cache = {}

def check(self, instance):
config = FilebeatCheckInstanceConfig(instance)
instance_key = hash_mutable(instance)
if instance_key in self.instance_cache:
config = self.instance_cache['config']
profiler = self.instance_cache['profiler']
else:
self.instance_cache['config'] = config = FilebeatCheckInstanceConfig(instance)
self.instance_cache['profiler'] = profiler = FilebeatCheckHttpProfiler(config)

self._process_registry(config)
self._gather_http_profiler_metrics(config)
self._gather_http_profiler_metrics(config, profiler)

def _process_registry(self, config):
registry_contents = self._parse_registry_file(config.registry_file_path)
Expand Down Expand Up @@ -253,8 +262,7 @@ def _process_registry_item(self, item):
def _is_same_file(self, stats, file_state_os):
return stats.st_dev == file_state_os['device'] and stats.st_ino == file_state_os['inode']

def _gather_http_profiler_metrics(self, config):
profiler = FilebeatCheckHttpProfiler(config)
def _gather_http_profiler_metrics(self, config, profiler):
try:
all_metrics = profiler.gather_metrics()
except StandardError as ex:
Expand Down

0 comments on commit 9b8f8ed

Please sign in to comment.