Skip to content

Commit 601d4f0

Browse files
committed
Merge pull request #1546 from DataDog/yann/win-jmx-status-files
[jmx] fix bad status path and encoding issues on Windows 🐛
2 parents d8a8637 + f1cf257 commit 601d4f0

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Diff for: checks/check_status.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# project
2020
import config
21-
from config import _windows_commondata_path, get_config
21+
from config import get_config, get_jmx_status_path, _windows_commondata_path
2222
from util import get_os, plural, Platform
2323

2424
# 3rd party
@@ -675,6 +675,7 @@ def to_dict(self):
675675
})
676676
return status_info
677677

678+
678679
def get_jmx_instance_status(instance_name, status, message, metric_count):
679680
if status == STATUS_ERROR:
680681
instance_status = InstanceStatus(instance_name, STATUS_ERROR, error=message, metric_count=metric_count)
@@ -719,8 +720,8 @@ def get_jmx_status():
719720
###
720721
"""
721722
check_statuses = []
722-
java_status_path = os.path.join(tempfile.gettempdir(), "jmx_status.yaml")
723-
python_status_path = os.path.join(tempfile.gettempdir(), "jmx_status_python.yaml")
723+
java_status_path = os.path.join(get_jmx_status_path(), "jmx_status.yaml")
724+
python_status_path = os.path.join(get_jmx_status_path(), "jmx_status_python.yaml")
724725
if not os.path.exists(java_status_path) and not os.path.exists(python_status_path):
725726
log.debug("There is no jmx_status file at: %s or at: %s" % (java_status_path, python_status_path))
726727
return []

Diff for: config.py

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
import glob
1212
import inspect
13+
import tempfile
1314
import traceback
1415
import re
1516
import imp
@@ -922,6 +923,7 @@ def load_check_directory(agentConfig, hostname):
922923
def get_log_date_format():
923924
return "%Y-%m-%d %H:%M:%S %Z"
924925

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

934936

937+
def get_jmx_status_path():
938+
if Platform.is_win32():
939+
path = os.path.join(_windows_commondata_path(), 'Datadog')
940+
else:
941+
path = tempfile.gettempdir()
942+
return path
943+
944+
935945
def get_logging_config(cfg_path=None):
936946
system_os = get_os()
937947
if system_os != 'windows':

Diff for: jmxfetch.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
import logging
44
import glob
55
import subprocess
6-
import tempfile
76
import time
87
import sys
98
import signal
109

1110
# datadog
1211
from util import get_os, yLoader, yDumper
13-
from config import get_config, get_confd_path, get_logging_config, \
12+
from config import get_config, get_confd_path, get_jmx_status_path, get_logging_config, \
1413
PathNotFound, DEFAULT_CHECK_FREQUENCY
1514

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

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

185186
if tools_jar_path is None:
186187
classpath = path_to_jmxfetch
@@ -234,7 +235,7 @@ def _write_status_file(self, invalid_checks):
234235
'timestamp': time.time(),
235236
'invalid_checks': invalid_checks
236237
}
237-
stream = file(os.path.join(tempfile.gettempdir(), PYTHON_JMX_STATUS_FILE), 'w')
238+
stream = file(os.path.join(get_jmx_status_path(), PYTHON_JMX_STATUS_FILE), 'w')
238239
yaml.dump(data, stream, Dumper=yDumper)
239240
stream.close()
240241

0 commit comments

Comments
 (0)