Skip to content

Commit

Permalink
[jmx] fix bad status path and encoding issues on Windows 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
yannmh committed Apr 15, 2015
1 parent d8a8637 commit f1cf257
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
7 changes: 4 additions & 3 deletions checks/check_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# project
import config
from config import _windows_commondata_path, get_config
from config import get_config, get_jmx_status_path, _windows_commondata_path
from util import get_os, plural, Platform

# 3rd party
Expand Down Expand Up @@ -675,6 +675,7 @@ def to_dict(self):
})
return status_info


def get_jmx_instance_status(instance_name, status, message, metric_count):
if status == STATUS_ERROR:
instance_status = InstanceStatus(instance_name, STATUS_ERROR, error=message, metric_count=metric_count)
Expand Down Expand Up @@ -719,8 +720,8 @@ def get_jmx_status():
###
"""
check_statuses = []
java_status_path = os.path.join(tempfile.gettempdir(), "jmx_status.yaml")
python_status_path = os.path.join(tempfile.gettempdir(), "jmx_status_python.yaml")
java_status_path = os.path.join(get_jmx_status_path(), "jmx_status.yaml")
python_status_path = os.path.join(get_jmx_status_path(), "jmx_status_python.yaml")
if not os.path.exists(java_status_path) and not os.path.exists(python_status_path):
log.debug("There is no jmx_status file at: %s or at: %s" % (java_status_path, python_status_path))
return []
Expand Down
10 changes: 10 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import glob
import inspect
import tempfile
import traceback
import re
import imp
Expand Down Expand Up @@ -922,6 +923,7 @@ def load_check_directory(agentConfig, hostname):
def get_log_date_format():
return "%Y-%m-%d %H:%M:%S %Z"


def get_log_format(logger_name):
if get_os() != 'windows':
return '%%(asctime)s | %%(levelname)s | dd.%s | %%(name)s(%%(filename)s:%%(lineno)s) | %%(message)s' % logger_name
Expand All @@ -932,6 +934,14 @@ def get_syslog_format(logger_name):
return 'dd.%s[%%(process)d]: %%(levelname)s (%%(filename)s:%%(lineno)s): %%(message)s' % logger_name


def get_jmx_status_path():
if Platform.is_win32():
path = os.path.join(_windows_commondata_path(), 'Datadog')
else:
path = tempfile.gettempdir()
return path


def get_logging_config(cfg_path=None):
system_os = get_os()
if system_os != 'windows':
Expand Down
9 changes: 5 additions & 4 deletions jmxfetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import logging
import glob
import subprocess
import tempfile
import time
import sys
import signal

# datadog
from util import get_os, yLoader, yDumper
from config import get_config, get_confd_path, get_logging_config, \
from config import get_config, get_confd_path, get_jmx_status_path, get_logging_config, \
PathNotFound, DEFAULT_CHECK_FREQUENCY

# 3rd party
Expand Down Expand Up @@ -165,6 +164,8 @@ def _should_run(self, checks_list):
tools_jar_path = check_tools_jar_path
except InvalidJMXConfiguration, e:
log.error("%s check does not have a valid JMX configuration: %s" % (check_name, e))
# Make sure check_name is a string - Fix issues with Windows
check_name = check_name.encode('ascii', 'ignore')
invalid_checks[check_name] = str(e)

return (jmx_checks, invalid_checks, java_bin_path, java_options, tools_jar_path)
Expand All @@ -180,7 +181,7 @@ def _start(self, path_to_java, java_run_opts, jmx_checks, command, reporter, too
path_to_java = path_to_java or "java"
java_run_opts = java_run_opts or ""
path_to_jmxfetch = self._get_path_to_jmxfetch()
path_to_status_file = os.path.join(tempfile.gettempdir(), "jmx_status.yaml")
path_to_status_file = os.path.join(get_jmx_status_path(), "jmx_status.yaml")

if tools_jar_path is None:
classpath = path_to_jmxfetch
Expand Down Expand Up @@ -234,7 +235,7 @@ def _write_status_file(self, invalid_checks):
'timestamp': time.time(),
'invalid_checks': invalid_checks
}
stream = file(os.path.join(tempfile.gettempdir(), PYTHON_JMX_STATUS_FILE), 'w')
stream = file(os.path.join(get_jmx_status_path(), PYTHON_JMX_STATUS_FILE), 'w')
yaml.dump(data, stream, Dumper=yDumper)
stream.close()

Expand Down

0 comments on commit f1cf257

Please sign in to comment.