Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d0cf20f
syntax highlight last example in README
shamrin Oct 28, 2015
54062b7
Merge pull request #67 from shamrin/patch-1
juliusv Oct 28, 2015
d771b38
Add `MetricsResource` for twisted.
tomprince Oct 13, 2015
ad9b902
Merge pull request #59 from ClusterHQ/twisted-resource
brian-brazil Nov 2, 2015
abef969
Make tests pass on python3
brian-brazil Nov 3, 2015
a08b4bd
Make core test code filename match.
brian-brazil Nov 5, 2015
b3dc602
Follow naming conventions for graphite bridge tests
alexandrul Jan 22, 2016
5519118
Fix test_exposition.py on Windows
alexandrul Jan 22, 2016
a7c6cc1
Merge pull request #72 from alexandrul/pr1
brian-brazil Jan 22, 2016
83d40c1
Merge pull request #73 from alexandrul/pr2
brian-brazil Jan 23, 2016
54260fa
Add WSGI helper methods
rmohr Apr 26, 2016
9a188ac
Merge pull request #78 from rmohr/master
brian-brazil Apr 26, 2016
2c2aa24
Unnest several classes in the core module.
alex Jun 1, 2016
f005a78
Merge pull request #81 from alex/patch-1
brian-brazil Jun 1, 2016
5c5d997
Adds support for the WSGI server to read from a different registry
Jun 9, 2016
42671e2
Merge pull request #83 from thomaso-mirodin/master
brian-brazil Jun 10, 2016
0e5696b
Allow passing label values as keyword arguments
alex Jul 3, 2016
d70c6d8
Add CI, make tests pass on non-linux
hynek Jun 17, 2016
ab5b401
Merge pull request #86 from hynek/master
brian-brazil Jul 8, 2016
225a95a
Make tests pass on Python 2.6
hynek Jul 8, 2016
bc2f2bc
Merge pull request #89 from hynek/master
brian-brazil Jul 14, 2016
700ac29
Release 0.0.14
brian-brazil Jul 15, 2016
6d5d72b
Bundle decorator.py and fix decorators
hynek Jul 20, 2016
cba7100
Merge pull request #91 from hynek/decorators
brian-brazil Jul 20, 2016
882d576
Remove the by-dict support for labels
alex Jul 22, 2016
bda36bf
Merge pull request #87 from alex/labels-as-kwargs
brian-brazil Jul 23, 2016
1ce94d7
Clean up the ProcessCollector.
vad Aug 3, 2016
9cf6f4e
Merge pull request #93 from vad/clean_process_collector
brian-brazil Aug 19, 2016
4197142
Add optional scheme support for push gateway urls (#103)
thekuffs Oct 1, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[run]
branch = True
source = prometheus_client
omit =
prometheus_client/decorator.py

[paths]
source =
prometheus_client
.tox/*/lib/python*/site-packages/prometheus_client
.tox/pypy/site-packages/prometheus_client

[report]
show_missing = True
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ dist
*.egg-info
*.pyc
*.swp
.coverage.*
.coverage
.tox
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
sudo: false
cache:
directories:
- $HOME/.cache/pip

language: python

matrix:
include:
- python: "2.6"
env: TOXENV=py26
- python: "2.7"
env: TOXENV=py27
- python: "2.7"
env: TOXENV=py27-nooptionals
- python: "3.4"
env: TOXENV=py34
- python: "3.5"
env: TOXENV=py35
- python: "3.5"
env: TOXENV=py35-nooptionals
- python: "pypy"
env: TOXENV=pypy

install:
- pip install tox

script:
- tox

notifications:
email: false
3 changes: 3 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Prometheus instrumentation library for Python applications
Copyright 2015 The Prometheus Authors

This product bundles decorator 4.0.10 which is available under a "2-clause BSD"
license. For details, see prometheus_client/decorator.py.
55 changes: 49 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ c.labels('get', '/').inc()
c.labels('post', '/submit').inc()
```

Labels can also be provided as a dict:
Labels can also be passed as keyword-arguments:

```python
from prometheus_client import Counter
c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])
c.labels({'method': 'get', 'endpoint': '/'}).inc()
c.labels({'method': 'post', 'endpoint': '/submit'}).inc()
c.labels(method='get', endpoint='/').inc()
c.labels(method='post', endpoint='/submit').inc()
```

### Process Collector
Expand Down Expand Up @@ -229,6 +229,50 @@ To add Prometheus exposition to an existing HTTP server, see the `MetricsHandler
which provides a `BaseHTTPRequestHandler`. It also serves as a simple example of how
to write a custom endpoint.

#### Twisted

To use prometheus with [twisted](https://twistedmatrix.com/), there is `MetricsResource` which exposes metrics as a twisted resource.

```python
from prometheus_client.twisted import MetricsResource
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.internet import reactor

root = Resource()
root.putChild(b'metrics', MetricsResource())

factory = Site(root)
reactor.listenTCP(8000, factory)
reactor.run()
```

#### WSGI

To use Prometheus with [WSGI](http://wsgi.readthedocs.org/en/latest/), there is
`make_wsgi_app` which creates a WSGI application.

```python
from prometheus_client import make_wsgi_app
from wsgiref.simple_server import make_server

app = make_wsgi_app()
httpd = make_server('', 8000, app)
httpd.serve_forever()
```

Such an application can be useful when integrating Prometheus metrics with WSGI
apps.

The method `start_wsgi_server` can be used to serve the metrics through the
WSGI reference implementation in a new thread.

```python
from prometheus_client import start_wsgi_server

start_wsgi_server(8000)
```

### Node exporter textfile collector

The [textfile collector](https://github.com/prometheus/node_exporter#textfile-collector)
Expand Down Expand Up @@ -325,14 +369,13 @@ REGISTRY.register(CustomCollector())
## Parser

The Python client supports parsing the Promeheus text format.
This is intended for advanced use cases where you have servers
This is intended for advanced use cases where you have servers
exposing Prometheus metrics and need to get them into some other
system.

```
```python
from prometheus_client.parser import text_string_to_metric_families
for family in text_string_to_metric_families("my_gauge 1.0\n"):
for sample in family.samples:
print("Name: {0} Labels: {1} Value: {2}".format(*sample))
```

2 changes: 2 additions & 0 deletions prometheus_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
CONTENT_TYPE_LATEST = exposition.CONTENT_TYPE_LATEST
generate_latest = exposition.generate_latest
MetricsHandler = exposition.MetricsHandler
make_wsgi_app = exposition.make_wsgi_app
start_http_server = exposition.start_http_server
start_wsgi_server = exposition.start_wsgi_server
write_to_textfile = exposition.write_to_textfile
push_to_gateway = exposition.push_to_gateway
pushadd_to_gateway = exposition.pushadd_to_gateway
Expand Down
Loading