Skip to content

Commit

Permalink
Merge pull request #89 from gummiboll/log_max_size-in-mb
Browse files Browse the repository at this point in the history
Set max size of logfiles in megabytes instead of bytes
  • Loading branch information
Shawn Sterling committed Oct 3, 2015
2 parents 2d6c078 + c49b078 commit ade0fca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions graphios.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ spool_directory = /var/spool/nagios/graphios
# graphios log info
log_file = /usr/local/nagios/var/graphios.log

# max log size (it will rotate the files) default: 24 MB
log_max_size = 25165824
# max log size in megabytes (it will rotate the files)
log_max_size = 24

# DEBUG is quite verbose
#log_level = logging.DEBUG
Expand Down Expand Up @@ -122,10 +122,10 @@ enable_influxdb = False

#------------------------------------------------------------------------------
# InfluxDB Details (if you are using InfluxDB 0.9)
# This will work a bit differently because of the addition of tags in
# This will work a bit differently because of the addition of tags in
# InfluxDB 0.9. Now the metric will be named after the service description,
# the perfdata field will be a tag, and the host name will be a tag. The value
# of the metric is stored in the 'value' column.
# of the metric is stored in the 'value' column.
# Requires use_service_desc = True.
#------------------------------------------------------------------------------

Expand Down
13 changes: 10 additions & 3 deletions graphios.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

# graphios log info
log_file = ''
log_max_size = 25165824 # 24 MB
log_max_size = 24

# by default we will check the current path for graphios.cfg, if config_file
# is passed as a command line argument we will use that instead.
Expand Down Expand Up @@ -257,7 +257,7 @@ def verify_options(opts):
cfg["log_file"] = opts.log_file
if cfg["log_file"] == "''" or cfg["log_file"] == "":
cfg["log_file"] = "%s/graphios.log" % sys.path[0]
cfg["log_max_size"] = 25165824 # 24 MB
cfg["log_max_size"] = 24
if opts.verbose:
cfg["debug"] = True
cfg["log_level"] = "logging.DEBUG"
Expand Down Expand Up @@ -309,8 +309,15 @@ def configure():
print "log_max_size needs to be a integer"
sys.exit(1)

# Convert cfg["log_max_size"] to bytes. Assume its already in bytes
# if its > 1000000
if cfg["log_max_size"] < 1000000:
log_max_bytes = cfg["log_max_size"]*1024*1024
else:
log_max_bytes = cfg["log_max_size"]

log_handler = logging.handlers.RotatingFileHandler(
cfg["log_file"], maxBytes=cfg["log_max_size"], backupCount=4,
cfg["log_file"], maxBytes=log_max_bytes, backupCount=4,
# encoding='bz2')
)
formatter = logging.Formatter(
Expand Down

0 comments on commit ade0fca

Please sign in to comment.