summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBinh Le <lebinh.it@gmail.com>2014-03-24 23:22:42 +0700
committerBinh Le <lebinh.it@gmail.com>2014-03-24 23:22:42 +0700
commitc0ca54525004de3308cc27077ff907d5f5c1cd09 (patch)
tree8fa4db430c9f758745a2e9124211bd3a9a58bc3b
parent7ea09b9ad11209d95dc50c2e3fd162c53a99169c (diff)
Restructured and prepared for packaging
-rw-r--r--.gitignore4
-rw-r--r--LICENSE.txt2
-rw-r--r--README.md92
-rw-r--r--README.rst101
-rw-r--r--ngxtop/__init__.py1
-rwxr-xr-xngxtop/ngxtop.py (renamed from ngxtop.py)10
-rw-r--r--requirements.txt2
-rw-r--r--setup.cfg0
-rw-r--r--setup.py34
9 files changed, 148 insertions, 98 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..57075a8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.py[cod]
+.idea
+.vagrant
+Vagrantfile
diff --git a/LICENSE.txt b/LICENSE.txt
index 85a8a8a..15a483d 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) [year] [fullname]
+Copyright (c) 2014 Binh Le.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
deleted file mode 100644
index 237c414..0000000
--- a/README.md
+++ /dev/null
@@ -1,92 +0,0 @@
-#`ngxtop` - know what is happening to your nginx server in real-time.
-
-**ngxtop** parses your nginx access log and outputs useful, `top`-like, metrics of your nginx server.
-
-
-## Usage
-```
-Usage:
- ngxtop [options]
- ngxtop [options] (print|top|avg|sum) <var>
- ngxtop info
-
-Options:
- -l <file>, --access-log <file> access log file to parse.
- -f <format>, --log-format <format> log format as specify in log_format directive.
- --no-follow ngxtop default behavior is to ignore current lines in log
- and only watch for new lines as they are written to the access log.
- Use this flag to tell ngxtop to process the current content of the access log instead.
- -t <seconds>, --interval <seconds> report interval when running in follow mode [default: 2.0]
-
- -g <var>, --group-by <var> group by variable [default: request_path]
- -w <var>, --having <expr> having clause [default: 1]
- -o <var>, --order-by <var> order of output for default query [default: count]
- -n <number>, --limit <number> limit the number of records included in report for top command [default: 10]
- -a <exp> ..., --a <exp> ... add exp (must be aggregation exp: sum, avg, min, max, etc.) into output
-
- -v, --verbose more verbose output
- -d, --debug print every line and parsed record
- -h, --help print this help message.
- --version print version information.
-```
-
-## Sample output
-
-###Default output
-
-```
-$ ./ngxtop.py
-running for 411 seconds, 64332 records processed: 156.60 req/sec
-
-Summary:
-| count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |
-|---------+------------------+-------+-------+-------+-------|
-| 64332 | 2775.251 | 61262 | 2994 | 71 | 5 |
-
-Detailed:
-| request_path | count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |
-|------------------------------------------+---------+------------------+-------+-------+-------+-------|
-| /abc/xyz/xxxx | 20946 | 434.693 | 20935 | 0 | 11 | 0 |
-| /xxxxx.json | 5633 | 1483.723 | 5633 | 0 | 0 | 0 |
-| /xxxxx/xxx/xxxxxxxxxxxxx | 3629 | 6835.499 | 3626 | 0 | 3 | 0 |
-| /xxxxx/xxx/xxxxxxxx | 3627 | 15971.885 | 3623 | 0 | 4 | 0 |
-| /xxxxx/xxx/xxxxxxx | 3624 | 7830.236 | 3621 | 0 | 3 | 0 |
-| /static/js/minified/utils.min.js | 3031 | 1781.155 | 2104 | 927 | 0 | 0 |
-| /static/js/minified/xxxxxxx.min.v1.js | 2889 | 2210.235 | 2068 | 821 | 0 | 0 |
-| /static/tracking/js/xxxxxxxx.js | 2594 | 1325.681 | 1927 | 667 | 0 | 0 |
-| /xxxxx/xxx.html | 2521 | 573.597 | 2520 | 0 | 1 | 0 |
-| /xxxxx/xxxx.json | 1840 | 800.542 | 1839 | 0 | 1 | 0 |
-```
-
-###View top source IPs of clients
-
-```
-$ ./ngxtop.py top remote_addr
-running for 20 seconds, 3215 records processed: 159.62 req/sec
-
-top remote_addr
-| remote_addr | count |
-|-----------------+---------|
-| 118.173.177.161 | 20 |
-| 110.78.145.3 | 16 |
-| 171.7.153.7 | 16 |
-| 180.183.67.155 | 16 |
-| 183.89.65.9 | 16 |
-| 202.28.182.5 | 16 |
-| 1.47.170.12 | 15 |
-| 119.46.184.2 | 15 |
-| 125.26.135.219 | 15 |
-| 125.26.213.203 | 15 |
-```
-
-###List 4xx or 5xx responses together with HTTP referer
-
-```
-$ ./ngxtop.py -i 'status >= 400' print request status http_referer
-running for 2 seconds, 28 records processed: 13.95 req/sec
-
-request, status, http_referer:
-| request | status | http_referer |
-|-----------+----------+----------------|
-| - | 400 | - |
-```
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..97c3568
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,101 @@
+===================================================
+``ngxtop`` - **real-time** metrics for nginx server
+===================================================
+
+**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.
+
+
+Usage
+-----
+
+::
+
+ Usage:
+ ngxtop [options]
+ ngxtop [options] (print|top|avg|sum) <var>
+ ngxtop info
+
+ Options:
+ -l <file>, --access-log <file> access log file to parse.
+ -f <format>, --log-format <format> log format as specify in log_format directive.
+ --no-follow ngxtop default behavior is to ignore current lines in log
+ and only watch for new lines as they are written to the access log.
+ Use this flag to tell ngxtop to process the current content of the access log instead.
+ -t <seconds>, --interval <seconds> report interval when running in follow mode [default: 2.0]
+
+ -g <var>, --group-by <var> group by variable [default: request_path]
+ -w <var>, --having <expr> having clause [default: 1]
+ -o <var>, --order-by <var> order of output for default query [default: count]
+ -n <number>, --limit <number> limit the number of records included in report for top command [default: 10]
+ -a <exp> ..., --a <exp> ... add exp (must be aggregation exp: sum, avg, min, max, etc.) into output
+
+ -v, --verbose more verbose output
+ -d, --debug print every line and parsed record
+ -h, --help print this help message.
+ --version print version information.
+
+Samples
+-------
+
+Default output
+~~~~~~~~~~~~~~
+
+::
+
+ $ ./ngxtop.py
+ running for 411 seconds, 64332 records processed: 156.60 req/sec
+
+ Summary:
+ | count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |
+ |---------+------------------+-------+-------+-------+-------|
+ | 64332 | 2775.251 | 61262 | 2994 | 71 | 5 |
+
+ Detailed:
+ | request_path | count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx |
+ |------------------------------------------+---------+------------------+-------+-------+-------+-------|
+ | /abc/xyz/xxxx | 20946 | 434.693 | 20935 | 0 | 11 | 0 |
+ | /xxxxx.json | 5633 | 1483.723 | 5633 | 0 | 0 | 0 |
+ | /xxxxx/xxx/xxxxxxxxxxxxx | 3629 | 6835.499 | 3626 | 0 | 3 | 0 |
+ | /xxxxx/xxx/xxxxxxxx | 3627 | 15971.885 | 3623 | 0 | 4 | 0 |
+ | /xxxxx/xxx/xxxxxxx | 3624 | 7830.236 | 3621 | 0 | 3 | 0 |
+ | /static/js/minified/utils.min.js | 3031 | 1781.155 | 2104 | 927 | 0 | 0 |
+ | /static/js/minified/xxxxxxx.min.v1.js | 2889 | 2210.235 | 2068 | 821 | 0 | 0 |
+ | /static/tracking/js/xxxxxxxx.js | 2594 | 1325.681 | 1927 | 667 | 0 | 0 |
+ | /xxxxx/xxx.html | 2521 | 573.597 | 2520 | 0 | 1 | 0 |
+ | /xxxxx/xxxx.json | 1840 | 800.542 | 1839 | 0 | 1 | 0 |
+
+View top source IPs of clients
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ $ ./ngxtop.py top remote_addr
+ running for 20 seconds, 3215 records processed: 159.62 req/sec
+
+ top remote_addr
+ | remote_addr | count |
+ |-----------------+---------|
+ | 118.173.177.161 | 20 |
+ | 110.78.145.3 | 16 |
+ | 171.7.153.7 | 16 |
+ | 180.183.67.155 | 16 |
+ | 183.89.65.9 | 16 |
+ | 202.28.182.5 | 16 |
+ | 1.47.170.12 | 15 |
+ | 119.46.184.2 | 15 |
+ | 125.26.135.219 | 15 |
+ | 125.26.213.203 | 15 |
+
+List 4xx or 5xx responses together with HTTP referer
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
+
+ $ ./ngxtop.py -i 'status >= 400' print request status http_referer
+ running for 2 seconds, 28 records processed: 13.95 req/sec
+
+ request, status, http_referer:
+ | request | status | http_referer |
+ |-----------+----------+----------------|
+ | - | 400 | - |
diff --git a/ngxtop/__init__.py b/ngxtop/__init__.py
new file mode 100644
index 0000000..7ec1fc3
--- /dev/null
+++ b/ngxtop/__init__.py
@@ -0,0 +1 @@
+from ngxtop import main \ No newline at end of file
diff --git a/ngxtop.py b/ngxtop/ngxtop.py
index 6e1cf48..b4fd0d5 100755
--- a/ngxtop.py
+++ b/ngxtop/ngxtop.py
@@ -393,7 +393,7 @@ def build_reporter(processor, arguments):
return thread
-def main(arguments):
+def process(arguments):
access_log = arguments['--access-log']
log_format = arguments['--log-format']
if access_log is None or log_format is None:
@@ -425,7 +425,7 @@ def main(arguments):
logging.info('Processed %d lines in %.3f seconds, %.2f lines/sec.', total, duration, total / duration)
-if __name__ == '__main__':
+def main():
args = docopt(__doc__, version='xstat 0.1')
log_level = logging.WARNING
@@ -437,6 +437,10 @@ if __name__ == '__main__':
logging.debug('arguments:\n%s', args)
try:
- main(args)
+ process(args)
except KeyboardInterrupt:
sys.exit(0)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index d68ced8..0000000
--- a/requirements.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-docopt
-tabulate
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/setup.cfg
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..db45f95
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,34 @@
+from setuptools import setup
+
+setup(
+ name='ngxtop',
+ version='0.0.1',
+ description='Real-time metrics for nginx server',
+ long_description=open('README.rst').read(),
+ license='MIT',
+
+ url='https://github.com/lebinh/ngxtop',
+ author='Binh Le',
+ author_email='lebinh.it@gmail.com',
+
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'License :: OSI Approved :: MIT License',
+ 'Environment :: Console',
+ 'Intended Audience :: Developers',
+ 'Intended Audience :: System Administrators',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ ],
+ keywords='cli monitoring nginx system',
+
+ packages=['ngxtop'],
+ install_requires=['docopt', 'tabulate'],
+
+ entry_points={
+ 'console_scripts': [
+ 'ngxtop = ngxtop.ngxtop:main',
+ ],
+ },
+)