Skip to content

Commit 4c7ecc9

Browse files
committed
Add support for envvar
1 parent cc4a188 commit 4c7ecc9

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from setuptools import setup
66

7-
VERSION = '0.4.0'
7+
VERSION = '0.5.0'
88

99
setup(
1010
maintainer='John Hu',

uwsgimon

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import argparse
55
import errno
6+
import os
67
try:
78
import simplejson as json
89
except ImportError:
@@ -33,7 +34,7 @@ def abstract_unix_addr(arg):
3334
return sfamily, addr, socket.gethostname()
3435

3536

36-
def run(stats, freq, node, role, f):
37+
def run(stats, node, role, freq, f):
3738
if ':' in stats:
3839
sfamily, addr, host = inet_addr(stats)
3940
elif stats.startswith('@'):
@@ -117,13 +118,16 @@ def run(stats, freq, node, role, f):
117118

118119

119120
def main():
120-
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'
121+
DEFAULT_NODE = socket.gethostname()
122+
DEFAULT_ROLE = 'uwsgi'
123+
DEFAULT_FREQ = 5
124+
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'
121125

122126
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
123-
parser.add_argument('--node', '-n', dest='node', default=socket.gethostname(), help='uWSGI node name, default: "{}"'.format(socket.gethostname()))
124-
parser.add_argument('--role', '-r', dest='role', default='uwsgi', help='uWSGI role name, default: "uwsgi"')
125-
parser.add_argument('--frequency', '-q', dest='freq', default=1, type=float, help='uWSGI stats refresh frequency, in seconds')
126-
parser.add_argument('--format', '-f', dest='format', default=default_format,
127+
parser.add_argument('--node', '-n', dest='node', default=None, help='uWSGI node name, default: "{}"'.format(DEFAULT_NODE))
128+
parser.add_argument('--role', '-r', dest='role', default=None, help='uWSGI role name, default: "{}"'.format(DEFAULT_ROLE))
129+
parser.add_argument('--frequency', '-q', dest='freq', default=None, type=float, help='uWSGI stats refresh frequency in seconds, default: {}'.format(DEFAULT_FREQ))
130+
parser.add_argument('--format', '-f', dest='format', default=None,
127131
help='''output format, available variables:
128132
ver - uWSGI version
129133
node - uWSGI node name
@@ -136,15 +140,18 @@ def main():
136140
idle - idle workers count
137141
rss - average RSS (Resident Set Size)
138142
vsz - average VSZ (Virtual Memory Size)
139-
140-
e.g. "{}"'''.format(default_format))
141-
143+
e.g. "{}"'''.format(DEFAULT_FORMAT))
142144
parser.add_argument('stats', help='uWSGI stats address')
143145

144146
args = parser.parse_args()
145147

148+
node = args.node or os.getenv('UWSGIMON_NODE') or DEFAULT_NODE
149+
role = args.role or os.getenv('UWSGIMON_ROLE') or DEFAULT_ROLE
150+
freq = args.freq or os.getenv('UWSGIMON_FREQ') or DEFAULT_FREQ
151+
format_ = args.format or os.getenv('UWSGIMON_FORMAT') or DEFAULT_FORMAT
152+
146153
try:
147-
run(stats=args.stats, freq=args.freq, node=args.node, role=args.role, f=args.format)
154+
run(stats=args.stats, node=node, role=role, freq=float(freq), f=format_)
148155
except IOError as e:
149156
if e.errno == errno.EPIPE:
150157
sys.exit(0)

0 commit comments

Comments
 (0)