Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[AMBARI-23787] Log rotation for ambari metrics monitor log (#1204)
* AMBARI-23787 Log rotation for ambari metrics monitor log

* AMBARI-23787 log and out file config improvement
  • Loading branch information
majorendre authored and swagle committed May 11, 2018
1 parent 5c303d0 commit 0c1e918c4798654e107f9f1f844dd54e95529e67
Showing 3 changed files with 25 additions and 16 deletions.
@@ -26,10 +26,10 @@
from ambari_commons.exceptions import FatalException, NonFatalException
from ambari_commons.logging_utils import print_warning_msg, print_error_msg
from ambari_commons.os_windows import SvcStatusCallback
from core.config_reader import SERVER_OUT_FILE, SERVICE_USERNAME_KEY, SERVICE_PASSWORD_KEY, \
from core.config_reader import SERVICE_USERNAME_KEY, SERVICE_PASSWORD_KEY, \
SETUP_ACTION, START_ACTION, STOP_ACTION, RESTART_ACTION, STATUS_ACTION
from core.stop_handler import bind_signal_handlers, StopHandler
from main import server_process_main
from main import server_process_main, main_config


#
@@ -64,7 +64,7 @@ def _InitOptionsParser(self):
return init_options_parser()

def redirect_output_streams(self):
self._RedirectOutputStreamsToFile(SERVER_OUT_FILE)
self._RedirectOutputStreamsToFile(main_config.ams_monitor_out_file())
pass


@@ -83,10 +83,6 @@ def get_ca_certs_file_path(self):
METRIC_FILE_PATH = configDefaults.get_metric_file_path()
CA_CERTS_FILE_PATH = configDefaults.get_ca_certs_file_path()

OUT_DIR = os.path.join(os.sep, "var", "log", "ambari-metrics-host-monitoring")
SERVER_OUT_FILE = OUT_DIR + os.sep + "ambari-metrics-host-monitoring.out"
SERVER_LOG_FILE = OUT_DIR + os.sep + "ambari-metrics-host-monitoring.log"

PID_DIR = os.path.join(os.sep, "var", "run", "ambari-metrics-host-monitoring")
PID_OUT_FILE = PID_DIR + os.sep + "ambari-metrics-host-monitoring.pid"
EXITCODE_OUT_FILE = PID_DIR + os.sep + "ambari-metrics-host-monitoring.exitcode"
@@ -281,6 +277,18 @@ def ams_monitor_log_dir(self):
hosts = self.get("aggregation", "ams_monitor_log_dir", "/var/log/ambari-metrics-monitor")
return hosts

def ams_monitor_log_file(self):
"""
:returns the log file
"""
return self.ams_monitor_log_dir() + os.sep + "ambari-metrics-monitor.log"

def ams_monitor_out_file(self):
"""
:returns the out file
"""
return self.ams_monitor_log_dir() + os.sep + "ambari-metrics-monitor.out"

def is_set_instanceid(self):
return "true" == str(self.get("default", "set.instanceId", 'false')).lower()

@@ -19,18 +19,20 @@
'''

import logging
import logging.handlers
import os
import sys
import signal
from ambari_commons.os_utils import remove_file

from core.controller import Controller
from core.config_reader import Configuration, PID_OUT_FILE, SERVER_LOG_FILE, SERVER_OUT_FILE
from core.config_reader import Configuration, PID_OUT_FILE
from core.stop_handler import bind_signal_handlers


logger = logging.getLogger()

main_config = Configuration()

def save_pid(pid, pidfile):
"""
@@ -58,15 +60,14 @@ def server_process_main(stop_handler, scmStatus=None):
if scmStatus is not None:
scmStatus.reportStartPending()

config = Configuration()
_init_logging(config)
controller = Controller(config, stop_handler)
_init_logging(main_config)
controller = Controller(main_config, stop_handler)

logger.info('Starting Server RPC Thread: %s' % ' '.join(sys.argv))
controller.start()

print "Server out at: " + SERVER_OUT_FILE
print "Server log at: " + SERVER_LOG_FILE
print "Server out at: " + main_config.ams_monitor_out_file()
print "Server log at: " + main_config.ams_monitor_log_file()

save_pid(os.getpid(), PID_OUT_FILE)

@@ -97,9 +98,9 @@ def _init_logging(config):
level = _levels.get(config.get_log_level())
logger.setLevel(level)
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(filename)s:%(lineno)d - %(message)s")
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
rotateLog = logging.handlers.RotatingFileHandler(config.ams_monitor_log_file(), "a", 10000000, 25)
rotateLog.setFormatter(formatter)
logger.addHandler(rotateLog)


if __name__ == '__main__':

0 comments on commit 0c1e918

Please sign in to comment.