diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a8c5a09 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:trusty + +RUN apt-get update && apt-get install -y python python-pip +RUN pip install procfs + +ADD ./start.sh /start.sh + +EXPOSE 8000 +ENTRYPOINT ["/start.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..61b33ad --- /dev/null +++ b/README.md @@ -0,0 +1,90 @@ +# procfs + +[![Build status](https://secure.travis-ci.org/pmuller/procfs.png?branch=master)](http://travis-ci.org/pmuller/procfs) +[![Downloads](https://pypip.in/download/procfs/badge.png)](https://pypi.python.org/pypi//procfs/) +[![Latest Version](https://pypip.in/version/procfs/badge.png)](https://pypi.python.org/pypi/procfs/) +[![License](https://pypip.in/license/procfs/badge.png)](https://pypi.python.org/pypi/procfs/) + +## Python Library + +### Install + + $ pip install procfs + +### Usage + +#### Basic usage + + >>> from procfs import Proc + >>> proc = Proc() + + >>> proc.loadavg + {'average': {1: 0.0, 5: 0.0, 15: 0.0}, + 'entities': {'current': 1, 'total': 117}, + 'last_pid': 3068} + + >>> proc.net.dev.eth1.receive.bytes + 117997558 + + >>> proc.meminfo.MemFree + 57044 + + >>> proc.net.snmp.Udp + {'InDatagrams': 3394, 'OutDatagrams': 3399, 'RcvbufErrors': 0, + 'InErrors': 0, 'SndbufErrors': 0, 'NoPorts': 4} + +#### Process information + + >>> proc.self + + + >>> proc.self.parent + + + >>> proc.self.uptime + datetime.timedelta(0, 346, 380262) + + >>> proc.processes + , , , , , , , , , , ...]> + >>> len(proc.processes) + 110 + + >>> proc.processes.cmdline('(vim|ssh)') + , , , , , ]> + + >>> proc.processes.uid(1000) + , , , , , , , , , , ...]> + + >>> proc.processes.user('pmuller').cmdline('python')[0] + + +## Docker Container Appliance + +You can also use the built-in CLI and HTTP server to get JSON results from a Docker container. Both support JSON Pointer style querying into the data structures. + +### Using the CLI with Docker + + $ docker run procfs loadavg + {"entities": {"current": 1, "total": 132}, "average": {"1": 0.0, "5": 0.01, "15": 0.07}, "last_pid": 9} + $ docker run procfs loadavg/average + {"1": 0.0, "5": 0.01, "15": 0.07} + $ docker run procfs loadavg/average/1 + 0.0 + +### Using the HTTP server with Docker + + $ docker run -d -p 8000:8000 procfs + $ curl localhost:8000/loadavg + {"entities": {"current": 1, "total": 132}, "average": {"1": 0.0, "5": 0.01, "15": 0.07}, "last_pid": 9} + $ curl localhost:8000/loadavg/average + {"1": 0.0, "5": 0.01, "15": 0.07} + $ curl localhost:8000/loadavg/average/1 + 0.0 + + +## Links + + * [documentation](http://packages.python.org/procfs/) + * [github](http://github.com/pmuller/procfs) + +[![Bitdeli badge](https://d2weczhvl823v0.cloudfront.net/pmuller/procfs/trend.png)](https://bitdeli.com/free) diff --git a/procfs/http.py b/procfs/http.py index ede312c..30bff4b 100644 --- a/procfs/http.py +++ b/procfs/http.py @@ -26,6 +26,7 @@ def do_GET(self): self.send_header("Content-Type", "application/json") self.end_headers() self.wfile.write(response) + self.wfile.write("\n") except PathNotFoundError as e: self.send_error(404, "path %s does not exist" % e) diff --git a/setup.cfg b/setup.cfg index e60d8c8..48033d9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,3 +5,6 @@ all_files = 1 [upload_sphinx] upload-dir = docs/build/html + +[metadata] +description-file = README.md \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..73b3823 --- /dev/null +++ b/start.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +main() { + if [[ "$1" = "" ]]; then + procfsd -p 8000 + else + procfs $1 + fi +} + +main "$@" \ No newline at end of file