Skip to content

Commit

Permalink
Add support for envvar
Browse files Browse the repository at this point in the history
  • Loading branch information
ushuz committed May 15, 2018
1 parent cc4a188 commit 4c7ecc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import setup

VERSION = '0.4.0'
VERSION = '0.5.0'

setup(
maintainer='John Hu',
Expand Down
27 changes: 17 additions & 10 deletions uwsgimon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse
import errno
import os
try:
import simplejson as json
except ImportError:
Expand Down Expand Up @@ -33,7 +34,7 @@ def abstract_unix_addr(arg):
return sfamily, addr, socket.gethostname()


def run(stats, freq, node, role, f):
def run(stats, node, role, freq, f):
if ':' in stats:
sfamily, addr, host = inet_addr(stats)
elif stats.startswith('@'):
Expand Down Expand Up @@ -117,13 +118,16 @@ def run(stats, freq, node, role, f):


def main():
default_format = 'uwsgi,node={node},role={role} req={req}i,rps={rps}i,avg={avg},lq={lq}i,busy={busy}i,idle={idle}i,rss={rss}i'
DEFAULT_NODE = socket.gethostname()
DEFAULT_ROLE = 'uwsgi'
DEFAULT_FREQ = 5
DEFAULT_FORMAT = 'uwsgi,node={node},role={role} req={req}i,rps={rps}i,avg={avg},lq={lq}i,busy={busy}i,idle={idle}i,rss={rss}i'

parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--node', '-n', dest='node', default=socket.gethostname(), help='uWSGI node name, default: "{}"'.format(socket.gethostname()))
parser.add_argument('--role', '-r', dest='role', default='uwsgi', help='uWSGI role name, default: "uwsgi"')
parser.add_argument('--frequency', '-q', dest='freq', default=1, type=float, help='uWSGI stats refresh frequency, in seconds')
parser.add_argument('--format', '-f', dest='format', default=default_format,
parser.add_argument('--node', '-n', dest='node', default=None, help='uWSGI node name, default: "{}"'.format(DEFAULT_NODE))
parser.add_argument('--role', '-r', dest='role', default=None, help='uWSGI role name, default: "{}"'.format(DEFAULT_ROLE))
parser.add_argument('--frequency', '-q', dest='freq', default=None, type=float, help='uWSGI stats refresh frequency in seconds, default: {}'.format(DEFAULT_FREQ))
parser.add_argument('--format', '-f', dest='format', default=None,
help='''output format, available variables:
ver - uWSGI version
node - uWSGI node name
Expand All @@ -136,15 +140,18 @@ def main():
idle - idle workers count
rss - average RSS (Resident Set Size)
vsz - average VSZ (Virtual Memory Size)
e.g. "{}"'''.format(default_format))

e.g. "{}"'''.format(DEFAULT_FORMAT))
parser.add_argument('stats', help='uWSGI stats address')

args = parser.parse_args()

node = args.node or os.getenv('UWSGIMON_NODE') or DEFAULT_NODE
role = args.role or os.getenv('UWSGIMON_ROLE') or DEFAULT_ROLE
freq = args.freq or os.getenv('UWSGIMON_FREQ') or DEFAULT_FREQ
format_ = args.format or os.getenv('UWSGIMON_FORMAT') or DEFAULT_FORMAT

try:
run(stats=args.stats, freq=args.freq, node=args.node, role=args.role, f=args.format)
run(stats=args.stats, node=node, role=role, freq=float(freq), f=format_)
except IOError as e:
if e.errno == errno.EPIPE:
sys.exit(0)
Expand Down

0 comments on commit 4c7ecc9

Please sign in to comment.