|
9 | 9 |
|
10 | 10 | # datadog
|
11 | 11 | from util import get_os, yLoader, yDumper
|
| 12 | +from utils.platform import Platform |
12 | 13 | from config import get_config, get_confd_path, get_jmx_status_path, get_logging_config, \
|
13 | 14 | PathNotFound, DEFAULT_CHECK_FREQUENCY
|
14 | 15 |
|
|
49 | 50 | JMX_COLLECT_COMMAND: "Start the collection of metrics based on your current configuration and display them in the console"}
|
50 | 51 |
|
51 | 52 | PYTHON_JMX_STATUS_FILE = 'jmx_status_python.yaml'
|
| 53 | +PYTHON_JMX_EXIT_FILE = 'jmxfetch_exit' |
52 | 54 |
|
53 | 55 | LINK_TO_DOC = "See http://docs.datadoghq.com/integrations/java/ for more information"
|
54 | 56 |
|
@@ -232,6 +234,13 @@ def _start(self, path_to_java, java_run_opts, jmx_checks, command, reporter, too
|
232 | 234 | command, # Name of the command
|
233 | 235 | ]
|
234 | 236 |
|
| 237 | + if Platform.is_windows(): |
| 238 | + # Signal handlers are not supported on Windows: |
| 239 | + # use a file to trigger JMXFetch exit instead |
| 240 | + path_to_exit_file = os.path.join(get_jmx_status_path(), PYTHON_JMX_EXIT_FILE) |
| 241 | + subprocess_args.insert(len(subprocess_args) - 1, '--exit_file_location') |
| 242 | + subprocess_args.insert(len(subprocess_args) - 1, path_to_exit_file) |
| 243 | + |
235 | 244 | subprocess_args.insert(4, '--check')
|
236 | 245 | for check in jmx_checks:
|
237 | 246 | subprocess_args.insert(5, check)
|
@@ -379,12 +388,31 @@ def _is_jmx_check(self, check_config, check_name, checks_list):
|
379 | 388 | return is_jmx, java_bin_path, java_options, tools_jar_path
|
380 | 389 |
|
381 | 390 | def _get_path_to_jmxfetch(self):
|
382 |
| - if get_os() != 'windows': |
| 391 | + if not Platform.is_windows(): |
383 | 392 | return os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "checks",
|
384 | 393 | "libs", JMX_FETCH_JAR_NAME))
|
385 | 394 | return os.path.realpath(os.path.join(os.path.abspath(__file__), "..", "..",
|
386 | 395 | "jmxfetch", JMX_FETCH_JAR_NAME))
|
387 | 396 |
|
| 397 | + @staticmethod |
| 398 | + def write_exit_file(): |
| 399 | + """ |
| 400 | + Create a 'special' file, which acts as a trigger to exit JMXFetch. |
| 401 | + Note: Windows only |
| 402 | + """ |
| 403 | + open(os.path.join(get_jmx_status_path(), PYTHON_JMX_EXIT_FILE), 'a').close() |
| 404 | + |
| 405 | + @staticmethod |
| 406 | + def clean_exit_file(): |
| 407 | + """ |
| 408 | + Remove exit file trigger -may not exist-. |
| 409 | + Note: Windows only |
| 410 | + """ |
| 411 | + try: |
| 412 | + os.remove(os.path.join(get_jmx_status_path(), PYTHON_JMX_EXIT_FILE)) |
| 413 | + except OSError: |
| 414 | + pass |
| 415 | + |
388 | 416 |
|
389 | 417 | def _clean_status_file():
|
390 | 418 | """
|
|
0 commit comments