diff options
author | Miguel A. Cortizo <macortizo@gmail.com> | 2014-03-28 15:05:17 +0100 |
---|---|---|
committer | Miguel A. Cortizo <macortizo@gmail.com> | 2014-03-28 15:05:17 +0100 |
commit | 4137c7da57e74e624a865e357479e7ec0f699b23 (patch) | |
tree | c626116531c86728b08381361511319e8c5f3e2e | |
parent | d780518a518d3e1342073af53bb2e3fe9cbf491b (diff) |
Enable input from stdin, such as pipe output
-rw-r--r-- | README.rst | 16 | ||||
-rwxr-xr-x | ngxtop/ngxtop.py | 14 |
2 files changed, 23 insertions, 7 deletions
@@ -1,10 +1,13 @@ -=================================================== -``ngxtop`` - **real-time** metrics for nginx server -=================================================== +================================================================ +``ngxtop`` - **real-time** metrics for nginx server (and others) +================================================================ **ngxtop** parses your nginx access log and outputs useful, ``top``-like, metrics of your nginx server. So you can tell what is happening with your server in real-time. +Can be used also with Apache log files (experimental). In this case, if not log format is specified, 'combined' will be +used. If the script doesn't detect redirections properly you can force it by using the '-s' option. + Installation ------------ @@ -24,6 +27,7 @@ Usage ngxtop [options] ngxtop [options] (print|top|avg|sum) <var> ngxtop info + tail -f /var/log/apache2/access.log | ngxtop [-s] Options: -l <file>, --access-log <file> access log file to parse. @@ -44,6 +48,12 @@ Usage -h, --help print this help message. --version print version information. + Advanced / experimental options: + -c <file>, --config <file> allow ngxtop to parse nginx config file for log format and location. + -i <filter-expression>, --filter <filter-expression> filter in, records satisfied given expression are processed. + -p <filter-expression>, --pre-filter <filter-expression> in-filter expression to check in pre-parsing phase. + -s, --from-stdin read lines from stdin. + Samples ------- diff --git a/ngxtop/ngxtop.py b/ngxtop/ngxtop.py index 17af878..12a84c3 100755 --- a/ngxtop/ngxtop.py +++ b/ngxtop/ngxtop.py @@ -29,6 +29,7 @@ Options: -c <file>, --config <file> allow ngxtop to parse nginx config file for log format and location. -i <filter-expression>, --filter <filter-expression> filter in, records satisfied given expression are processed. -p <filter-expression>, --pre-filter <filter-expression> in-filter expression to check in pre-parsing phase. + -s, --from-stdin read lines from stdin. Examples: All examples read nginx config file for access log location and format. @@ -377,6 +378,8 @@ def build_source(access_log, arguments): # constructing log source if arguments['--no-follow']: lines = open(access_log) + elif (arguments['--from-stdin'] or not sys.stdin.isatty()): + lines = sys.stdin else: lines = follow(access_log) return lines @@ -403,10 +406,13 @@ def process(arguments): access_log = arguments['--access-log'] log_format = arguments['--log-format'] if access_log is None or log_format is None: - config = arguments['--config'] - if config is None: - config = get_nginx_conf_path() - access_log, log_format = extract_nginx_conf(config, access_log) + if not (arguments['--from-stdin'] or sys.stdin.isatty()): + config = arguments['--config'] + if config is None: + config = get_nginx_conf_path() + access_log, log_format = extract_nginx_conf(config, access_log) + else: + log_format = 'combined' else: config = None logging.info('access_log: %s', access_log) |