Uploaded Test files
This commit is contained in:
parent
f584ad9d97
commit
2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions
|
@ -0,0 +1 @@
|
|||
pip
|
201
venv/Lib/site-packages/prometheus_client-0.8.0.dist-info/LICENSE
Normal file
201
venv/Lib/site-packages/prometheus_client-0.8.0.dist-info/LICENSE
Normal file
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,600 @@
|
|||
Metadata-Version: 2.1
|
||||
Name: prometheus-client
|
||||
Version: 0.8.0
|
||||
Summary: Python client for the Prometheus monitoring system.
|
||||
Home-page: https://github.com/prometheus/client_python
|
||||
Author: Brian Brazil
|
||||
Author-email: brian.brazil@robustperception.io
|
||||
License: Apache Software License 2.0
|
||||
Keywords: prometheus monitoring instrumentation client
|
||||
Platform: UNKNOWN
|
||||
Classifier: Development Status :: 4 - Beta
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: Intended Audience :: Information Technology
|
||||
Classifier: Intended Audience :: System Administrators
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 2
|
||||
Classifier: Programming Language :: Python :: 2.6
|
||||
Classifier: Programming Language :: Python :: 2.7
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3.4
|
||||
Classifier: Programming Language :: Python :: 3.5
|
||||
Classifier: Programming Language :: Python :: 3.6
|
||||
Classifier: Programming Language :: Python :: 3.7
|
||||
Classifier: Programming Language :: Python :: 3.8
|
||||
Classifier: Programming Language :: Python :: Implementation :: CPython
|
||||
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
||||
Classifier: Topic :: System :: Monitoring
|
||||
Classifier: License :: OSI Approved :: Apache Software License
|
||||
Description-Content-Type: text/markdown
|
||||
Provides-Extra: twisted
|
||||
Requires-Dist: twisted ; extra == 'twisted'
|
||||
|
||||
# Prometheus Python Client
|
||||
|
||||
The official Python 2 and 3 client for [Prometheus](http://prometheus.io).
|
||||
|
||||
## Three Step Demo
|
||||
|
||||
**One**: Install the client:
|
||||
```
|
||||
pip install prometheus_client
|
||||
```
|
||||
|
||||
**Two**: Paste the following into a Python interpreter:
|
||||
```python
|
||||
from prometheus_client import start_http_server, Summary
|
||||
import random
|
||||
import time
|
||||
|
||||
# Create a metric to track time spent and requests made.
|
||||
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')
|
||||
|
||||
# Decorate function with metric.
|
||||
@REQUEST_TIME.time()
|
||||
def process_request(t):
|
||||
"""A dummy function that takes some time."""
|
||||
time.sleep(t)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Start up the server to expose the metrics.
|
||||
start_http_server(8000)
|
||||
# Generate some requests.
|
||||
while True:
|
||||
process_request(random.random())
|
||||
```
|
||||
|
||||
**Three**: Visit [http://localhost:8000/](http://localhost:8000/) to view the metrics.
|
||||
|
||||
From one easy to use decorator you get:
|
||||
* `request_processing_seconds_count`: Number of times this function was called.
|
||||
* `request_processing_seconds_sum`: Total amount of time spent in this function.
|
||||
|
||||
Prometheus's `rate` function allows calculation of both requests per second,
|
||||
and latency over time from this data.
|
||||
|
||||
In addition if you're on Linux the `process` metrics expose CPU, memory and
|
||||
other information about the process for free!
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
pip install prometheus_client
|
||||
```
|
||||
|
||||
This package can be found on
|
||||
[PyPI](https://pypi.python.org/pypi/prometheus_client).
|
||||
|
||||
## Instrumenting
|
||||
|
||||
Four types of metric are offered: Counter, Gauge, Summary and Histogram.
|
||||
See the documentation on [metric types](http://prometheus.io/docs/concepts/metric_types/)
|
||||
and [instrumentation best practices](https://prometheus.io/docs/practices/instrumentation/#counter-vs-gauge-summary-vs-histogram)
|
||||
on how to use them.
|
||||
|
||||
### Counter
|
||||
|
||||
Counters go up, and reset when the process restarts.
|
||||
|
||||
|
||||
```python
|
||||
from prometheus_client import Counter
|
||||
c = Counter('my_failures', 'Description of counter')
|
||||
c.inc() # Increment by 1
|
||||
c.inc(1.6) # Increment by given value
|
||||
```
|
||||
|
||||
If there is a suffix of `_total` on the metric name, it will be removed. When
|
||||
exposing the time series for counter, a `_total` suffix will be added. This is
|
||||
for compatibility between OpenMetrics and the Prometheus text format, as OpenMetrics
|
||||
requires the `_total` suffix.
|
||||
|
||||
There are utilities to count exceptions raised:
|
||||
|
||||
```python
|
||||
@c.count_exceptions()
|
||||
def f():
|
||||
pass
|
||||
|
||||
with c.count_exceptions():
|
||||
pass
|
||||
|
||||
# Count only one type of exception
|
||||
with c.count_exceptions(ValueError):
|
||||
pass
|
||||
```
|
||||
|
||||
### Gauge
|
||||
|
||||
Gauges can go up and down.
|
||||
|
||||
```python
|
||||
from prometheus_client import Gauge
|
||||
g = Gauge('my_inprogress_requests', 'Description of gauge')
|
||||
g.inc() # Increment by 1
|
||||
g.dec(10) # Decrement by given value
|
||||
g.set(4.2) # Set to a given value
|
||||
```
|
||||
|
||||
There are utilities for common use cases:
|
||||
|
||||
```python
|
||||
g.set_to_current_time() # Set to current unixtime
|
||||
|
||||
# Increment when entered, decrement when exited.
|
||||
@g.track_inprogress()
|
||||
def f():
|
||||
pass
|
||||
|
||||
with g.track_inprogress():
|
||||
pass
|
||||
```
|
||||
|
||||
A Gauge can also take its value from a callback:
|
||||
|
||||
```python
|
||||
d = Gauge('data_objects', 'Number of objects')
|
||||
my_dict = {}
|
||||
d.set_function(lambda: len(my_dict))
|
||||
```
|
||||
|
||||
### Summary
|
||||
|
||||
Summaries track the size and number of events.
|
||||
|
||||
```python
|
||||
from prometheus_client import Summary
|
||||
s = Summary('request_latency_seconds', 'Description of summary')
|
||||
s.observe(4.7) # Observe 4.7 (seconds in this case)
|
||||
```
|
||||
|
||||
There are utilities for timing code:
|
||||
|
||||
```python
|
||||
@s.time()
|
||||
def f():
|
||||
pass
|
||||
|
||||
with s.time():
|
||||
pass
|
||||
```
|
||||
|
||||
The Python client doesn't store or expose quantile information at this time.
|
||||
|
||||
### Histogram
|
||||
|
||||
Histograms track the size and number of events in buckets.
|
||||
This allows for aggregatable calculation of quantiles.
|
||||
|
||||
```python
|
||||
from prometheus_client import Histogram
|
||||
h = Histogram('request_latency_seconds', 'Description of histogram')
|
||||
h.observe(4.7) # Observe 4.7 (seconds in this case)
|
||||
```
|
||||
|
||||
The default buckets are intended to cover a typical web/rpc request from milliseconds to seconds.
|
||||
They can be overridden by passing `buckets` keyword argument to `Histogram`.
|
||||
|
||||
There are utilities for timing code:
|
||||
|
||||
```python
|
||||
@h.time()
|
||||
def f():
|
||||
pass
|
||||
|
||||
with h.time():
|
||||
pass
|
||||
```
|
||||
|
||||
### Info
|
||||
|
||||
Info tracks key-value information, usually about a whole target.
|
||||
|
||||
```python
|
||||
from prometheus_client import Info
|
||||
i = Info('my_build_version', 'Description of info')
|
||||
i.info({'version': '1.2.3', 'buildhost': 'foo@bar'})
|
||||
```
|
||||
|
||||
### Enum
|
||||
|
||||
Enum tracks which of a set of states something is currently in.
|
||||
|
||||
```python
|
||||
from prometheus_client import Enum
|
||||
e = Enum('my_task_state', 'Description of enum',
|
||||
states=['starting', 'running', 'stopped'])
|
||||
e.state('running')
|
||||
```
|
||||
|
||||
### Labels
|
||||
|
||||
All metrics can have labels, allowing grouping of related time series.
|
||||
|
||||
See the best practices on [naming](http://prometheus.io/docs/practices/naming/)
|
||||
and [labels](http://prometheus.io/docs/practices/instrumentation/#use-labels).
|
||||
|
||||
Taking a counter as an example:
|
||||
|
||||
```python
|
||||
from prometheus_client import Counter
|
||||
c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])
|
||||
c.labels('get', '/').inc()
|
||||
c.labels('post', '/submit').inc()
|
||||
```
|
||||
|
||||
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()
|
||||
```
|
||||
|
||||
### Process Collector
|
||||
|
||||
The Python client automatically exports metrics about process CPU usage, RAM,
|
||||
file descriptors and start time. These all have the prefix `process`, and
|
||||
are only currently available on Linux.
|
||||
|
||||
The namespace and pid constructor arguments allows for exporting metrics about
|
||||
other processes, for example:
|
||||
```
|
||||
ProcessCollector(namespace='mydaemon', pid=lambda: open('/var/run/daemon.pid').read())
|
||||
```
|
||||
|
||||
### Platform Collector
|
||||
|
||||
The client also automatically exports some metadata about Python. If using Jython,
|
||||
metadata about the JVM in use is also included. This information is available as
|
||||
labels on the `python_info` metric. The value of the metric is 1, since it is the
|
||||
labels that carry information.
|
||||
|
||||
## Exporting
|
||||
|
||||
There are several options for exporting metrics.
|
||||
|
||||
### HTTP
|
||||
|
||||
Metrics are usually exposed over HTTP, to be read by the Prometheus server.
|
||||
|
||||
The easiest way to do this is via `start_http_server`, which will start a HTTP
|
||||
server in a daemon thread on the given port:
|
||||
|
||||
```python
|
||||
from prometheus_client import start_http_server
|
||||
|
||||
start_http_server(8000)
|
||||
```
|
||||
|
||||
Visit [http://localhost:8000/](http://localhost:8000/) to view the metrics.
|
||||
|
||||
To add Prometheus exposition to an existing HTTP server, see the `MetricsHandler` class
|
||||
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)
|
||||
```
|
||||
|
||||
#### ASGI
|
||||
|
||||
To use Prometheus with [ASGI](http://asgi.readthedocs.org/en/latest/), there is
|
||||
`make_asgi_app` which creates an ASGI application.
|
||||
|
||||
```python
|
||||
from prometheus_client import make_asgi_app
|
||||
|
||||
app = make_asgi_app()
|
||||
```
|
||||
Such an application can be useful when integrating Prometheus metrics with ASGI
|
||||
apps.
|
||||
|
||||
#### Flask
|
||||
|
||||
To use Prometheus with [Flask](http://flask.pocoo.org/) we need to serve metrics through a Prometheus WSGI application. This can be achieved using [Flask's application dispatching](http://flask.pocoo.org/docs/latest/patterns/appdispatch/). Below is a working example.
|
||||
|
||||
Save the snippet below in a `myapp.py` file
|
||||
|
||||
```python
|
||||
from flask import Flask
|
||||
from werkzeug.middleware.dispatcher import DispatcherMiddleware
|
||||
from prometheus_client import make_wsgi_app
|
||||
|
||||
# Create my app
|
||||
app = Flask(__name__)
|
||||
|
||||
# Add prometheus wsgi middleware to route /metrics requests
|
||||
app_dispatch = DispatcherMiddleware(app, {
|
||||
'/metrics': make_wsgi_app()
|
||||
})
|
||||
```
|
||||
|
||||
Run the example web application like this
|
||||
|
||||
```bash
|
||||
# Install uwsgi if you do not have it
|
||||
pip install uwsgi
|
||||
uwsgi --http 127.0.0.1:8000 --wsgi-file myapp.py --callable app_dispatch
|
||||
```
|
||||
|
||||
Visit http://localhost:8000/metrics to see the metrics
|
||||
|
||||
### Node exporter textfile collector
|
||||
|
||||
The [textfile collector](https://github.com/prometheus/node_exporter#textfile-collector)
|
||||
allows machine-level statistics to be exported out via the Node exporter.
|
||||
|
||||
This is useful for monitoring cronjobs, or for writing cronjobs to expose metrics
|
||||
about a machine system that the Node exporter does not support or would not make sense
|
||||
to perform at every scrape (for example, anything involving subprocesses).
|
||||
|
||||
```python
|
||||
from prometheus_client import CollectorRegistry, Gauge, write_to_textfile
|
||||
|
||||
registry = CollectorRegistry()
|
||||
g = Gauge('raid_status', '1 if raid array is okay', registry=registry)
|
||||
g.set(1)
|
||||
write_to_textfile('/configured/textfile/path/raid.prom', registry)
|
||||
```
|
||||
|
||||
A separate registry is used, as the default registry may contain other metrics
|
||||
such as those from the Process Collector.
|
||||
|
||||
## Exporting to a Pushgateway
|
||||
|
||||
The [Pushgateway](https://github.com/prometheus/pushgateway)
|
||||
allows ephemeral and batch jobs to expose their metrics to Prometheus.
|
||||
|
||||
```python
|
||||
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
|
||||
|
||||
registry = CollectorRegistry()
|
||||
g = Gauge('job_last_success_unixtime', 'Last time a batch job successfully finished', registry=registry)
|
||||
g.set_to_current_time()
|
||||
push_to_gateway('localhost:9091', job='batchA', registry=registry)
|
||||
```
|
||||
|
||||
A separate registry is used, as the default registry may contain other metrics
|
||||
such as those from the Process Collector.
|
||||
|
||||
Pushgateway functions take a grouping key. `push_to_gateway` replaces metrics
|
||||
with the same grouping key, `pushadd_to_gateway` only replaces metrics with the
|
||||
same name and grouping key and `delete_from_gateway` deletes metrics with the
|
||||
given job and grouping key. See the
|
||||
[Pushgateway documentation](https://github.com/prometheus/pushgateway/blob/master/README.md)
|
||||
for more information.
|
||||
|
||||
`instance_ip_grouping_key` returns a grouping key with the instance label set
|
||||
to the host's IP address.
|
||||
|
||||
### Handlers for authentication
|
||||
|
||||
If the push gateway you are connecting to is protected with HTTP Basic Auth,
|
||||
you can use a special handler to set the Authorization header.
|
||||
|
||||
```python
|
||||
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
|
||||
from prometheus_client.exposition import basic_auth_handler
|
||||
|
||||
def my_auth_handler(url, method, timeout, headers, data):
|
||||
username = 'foobar'
|
||||
password = 'secret123'
|
||||
return basic_auth_handler(url, method, timeout, headers, data, username, password)
|
||||
registry = CollectorRegistry()
|
||||
g = Gauge('job_last_success_unixtime', 'Last time a batch job successfully finished', registry=registry)
|
||||
g.set_to_current_time()
|
||||
push_to_gateway('localhost:9091', job='batchA', registry=registry, handler=my_auth_handler)
|
||||
```
|
||||
|
||||
## Bridges
|
||||
|
||||
It is also possible to expose metrics to systems other than Prometheus.
|
||||
This allows you to take advantage of Prometheus instrumentation even
|
||||
if you are not quite ready to fully transition to Prometheus yet.
|
||||
|
||||
### Graphite
|
||||
|
||||
Metrics are pushed over TCP in the Graphite plaintext format.
|
||||
|
||||
```python
|
||||
from prometheus_client.bridge.graphite import GraphiteBridge
|
||||
|
||||
gb = GraphiteBridge(('graphite.your.org', 2003))
|
||||
# Push once.
|
||||
gb.push()
|
||||
# Push every 10 seconds in a daemon thread.
|
||||
gb.start(10.0)
|
||||
```
|
||||
|
||||
## Custom Collectors
|
||||
|
||||
Sometimes it is not possible to directly instrument code, as it is not
|
||||
in your control. This requires you to proxy metrics from other systems.
|
||||
|
||||
To do so you need to create a custom collector, for example:
|
||||
|
||||
```python
|
||||
from prometheus_client.core import GaugeMetricFamily, CounterMetricFamily, REGISTRY
|
||||
|
||||
class CustomCollector(object):
|
||||
def collect(self):
|
||||
yield GaugeMetricFamily('my_gauge', 'Help text', value=7)
|
||||
c = CounterMetricFamily('my_counter_total', 'Help text', labels=['foo'])
|
||||
c.add_metric(['bar'], 1.7)
|
||||
c.add_metric(['baz'], 3.8)
|
||||
yield c
|
||||
|
||||
REGISTRY.register(CustomCollector())
|
||||
```
|
||||
|
||||
`SummaryMetricFamily` and `HistogramMetricFamily` work similarly.
|
||||
|
||||
A collector may implement a `describe` method which returns metrics in the same
|
||||
format as `collect` (though you don't have to include the samples). This is
|
||||
used to predetermine the names of time series a `CollectorRegistry` exposes and
|
||||
thus to detect collisions and duplicate registrations.
|
||||
|
||||
Usually custom collectors do not have to implement `describe`. If `describe` is
|
||||
not implemented and the CollectorRegistry was created with `auto_describe=True`
|
||||
(which is the case for the default registry) then `collect` will be called at
|
||||
registration time instead of `describe`. If this could cause problems, either
|
||||
implement a proper `describe`, or if that's not practical have `describe`
|
||||
return an empty list.
|
||||
|
||||
|
||||
## Multiprocess Mode (Gunicorn)
|
||||
|
||||
Prometheus client libraries presume a threaded model, where metrics are shared
|
||||
across workers. This doesn't work so well for languages such as Python where
|
||||
it's common to have processes rather than threads to handle large workloads.
|
||||
|
||||
To handle this the client library can be put in multiprocess mode.
|
||||
This comes with a number of limitations:
|
||||
|
||||
- Registries can not be used as normal, all instantiated metrics are exported
|
||||
- Custom collectors do not work (e.g. cpu and memory metrics)
|
||||
- Info and Enum metrics do not work
|
||||
- The pushgateway cannot be used
|
||||
- Gauges cannot use the `pid` label
|
||||
|
||||
There's several steps to getting this working:
|
||||
|
||||
**1. Gunicorn deployment**:
|
||||
|
||||
The `prometheus_multiproc_dir` environment variable must be set to a directory
|
||||
that the client library can use for metrics. This directory must be wiped
|
||||
between Gunicorn runs (before startup is recommended).
|
||||
|
||||
This environment variable should be set from a start-up shell script,
|
||||
and not directly from Python (otherwise it may not propagate to child processes).
|
||||
|
||||
**2. Metrics collector**:
|
||||
|
||||
The application must initialize a new `CollectorRegistry`,
|
||||
and store the multi-process collector inside.
|
||||
|
||||
```python
|
||||
from prometheus_client import multiprocess
|
||||
from prometheus_client import generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST
|
||||
|
||||
# Expose metrics.
|
||||
def app(environ, start_response):
|
||||
registry = CollectorRegistry()
|
||||
multiprocess.MultiProcessCollector(registry)
|
||||
data = generate_latest(registry)
|
||||
status = '200 OK'
|
||||
response_headers = [
|
||||
('Content-type', CONTENT_TYPE_LATEST),
|
||||
('Content-Length', str(len(data)))
|
||||
]
|
||||
start_response(status, response_headers)
|
||||
return iter([data])
|
||||
```
|
||||
|
||||
**3. Gunicorn configuration**:
|
||||
|
||||
The `gunicorn` configuration file needs to include the following function:
|
||||
|
||||
```python
|
||||
from prometheus_client import multiprocess
|
||||
|
||||
def child_exit(server, worker):
|
||||
multiprocess.mark_process_dead(worker.pid)
|
||||
```
|
||||
|
||||
**4. Metrics tuning (Gauge)**:
|
||||
|
||||
When `Gauge` metrics are used, additional tuning needs to be performed.
|
||||
Gauges have several modes they can run in, which can be selected with the `multiprocess_mode` parameter.
|
||||
|
||||
- 'all': Default. Return a timeseries per process alive or dead.
|
||||
- 'liveall': Return a timeseries per process that is still alive.
|
||||
- 'livesum': Return a single timeseries that is the sum of the values of alive processes.
|
||||
- 'max': Return a single timeseries that is the maximum of the values of all processes, alive or dead.
|
||||
- 'min': Return a single timeseries that is the minimum of the values of all processes, alive or dead.
|
||||
|
||||
```python
|
||||
from prometheus_client import Gauge
|
||||
|
||||
# Example gauge
|
||||
IN_PROGRESS = Gauge("inprogress_requests", "help", multiprocess_mode='livesum')
|
||||
```
|
||||
|
||||
|
||||
## Parser
|
||||
|
||||
The Python client supports parsing the Prometheus text format.
|
||||
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(u"my_gauge 1.0\n"):
|
||||
for sample in family.samples:
|
||||
print("Name: {0} Labels: {1} Value: {2}".format(*sample))
|
||||
```
|
||||
|
||||
|
|
@ -0,0 +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.
|
|
@ -0,0 +1,57 @@
|
|||
prometheus_client-0.8.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
prometheus_client-0.8.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
||||
prometheus_client-0.8.0.dist-info/METADATA,sha256=cY1r0eK80RUWZ8_OgIil8SRJOF5cf5XedwA-hYvXfg4,18330
|
||||
prometheus_client-0.8.0.dist-info/NOTICE,sha256=TvoYdK6qYPNl9Xl-YX8f-TPhXlCOr3UemEjtRBPXp64,236
|
||||
prometheus_client-0.8.0.dist-info/RECORD,,
|
||||
prometheus_client-0.8.0.dist-info/WHEEL,sha256=kGT74LWyRUZrL4VgLh6_g12IeVl_9u9ZVhadrgXZUEY,110
|
||||
prometheus_client-0.8.0.dist-info/top_level.txt,sha256=AxLEvHEMhTW-Kvb9Ly1DPI3aapigQ2aeg8TXMt9WMRo,18
|
||||
prometheus_client/__init__.py,sha256=BoUpgs-xd4g96ig5Ry6LbrPMIkUPXsO56qnw4WcDK1k,1817
|
||||
prometheus_client/__pycache__/__init__.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/asgi.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/context_managers.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/core.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/decorator.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/exposition.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/gc_collector.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/metrics.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/metrics_core.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/mmap_dict.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/multiprocess.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/parser.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/platform_collector.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/process_collector.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/registry.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/samples.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/utils.cpython-36.pyc,,
|
||||
prometheus_client/__pycache__/values.cpython-36.pyc,,
|
||||
prometheus_client/asgi.py,sha256=toC_R7t7GfNRu8_H5yctDMaxnBnhj8F1oVV4LIRWXWs,1185
|
||||
prometheus_client/bridge/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
prometheus_client/bridge/__pycache__/__init__.cpython-36.pyc,,
|
||||
prometheus_client/bridge/__pycache__/graphite.cpython-36.pyc,,
|
||||
prometheus_client/bridge/graphite.py,sha256=85g38FSc6FeJFvD594B54W89Uf1wtuBllf5GcZawaT0,2485
|
||||
prometheus_client/context_managers.py,sha256=PWnrQJAyznpEiw84enD508p5e_aweu6Fifk4qTpuDtM,1691
|
||||
prometheus_client/core.py,sha256=Etgn7_XLFIXZVHaBHAxvK0tQFGOO07_G4AQ55njllgM,895
|
||||
prometheus_client/decorator.py,sha256=7MdUokWmzQ17foet2R5QcMubdZ1WDPGYo0_HqLxAw2k,15802
|
||||
prometheus_client/exposition.py,sha256=7vqZZg69ADg6LpnWwj2PJ6ILkbmj16163pBeMDzjARA,15283
|
||||
prometheus_client/gc_collector.py,sha256=A0CkohCJ8AhjLuYsbzjgD8k6nQG41FZJXy1r4XunBxs,1458
|
||||
prometheus_client/metrics.py,sha256=ZCzHeKz0SPgxhwJbq4XYrJZbC2Cr_nxx4-bIJ7Let7U,22184
|
||||
prometheus_client/metrics_core.py,sha256=hOdnDqCVPuX9Y8tnR0nxdEsA5DqdMf0rfFmM2actkxM,11881
|
||||
prometheus_client/mmap_dict.py,sha256=AWFK2nSz-Wve4bOzUdrkTPfs4nkPzyyUwo4ksqYkOic,5264
|
||||
prometheus_client/multiprocess.py,sha256=H24BnqdzihrqQP01RU5nMMGbgdXTki7-CnV4s3zztho,6474
|
||||
prometheus_client/openmetrics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
prometheus_client/openmetrics/__pycache__/__init__.cpython-36.pyc,,
|
||||
prometheus_client/openmetrics/__pycache__/exposition.cpython-36.pyc,,
|
||||
prometheus_client/openmetrics/__pycache__/parser.cpython-36.pyc,,
|
||||
prometheus_client/openmetrics/exposition.py,sha256=o1ndi0m380AB7-4Q8qHO9zc21qWBOOnIMHRHiKbk1EY,2860
|
||||
prometheus_client/openmetrics/parser.py,sha256=nixK-y-WpO6PFw-a08eOnzZo_pjbpFBntTOCbKWYckw,21527
|
||||
prometheus_client/parser.py,sha256=5N0l_aV9BKknmYwQEGBXJ1p24s-p_XaicZAaCqRIPZQ,7256
|
||||
prometheus_client/platform_collector.py,sha256=FVKOCAgD_qiOHazNViZ9QxnoN_YDOlJJuuFvlTJo8ZE,1735
|
||||
prometheus_client/process_collector.py,sha256=mwFMfWuKPi5kkBQ8pXYnJfcKSg_hIPXaxb3zs_tf0AY,3654
|
||||
prometheus_client/registry.py,sha256=boNhxDToERzBjBieFPOUqzAB6IMfHdNmrcUlJVMhLjc,5357
|
||||
prometheus_client/samples.py,sha256=kFAvGfhebelkZ-Gpoqy-b3Uz4dpkOn3KN2ZXGOeqXP8,1358
|
||||
prometheus_client/twisted/__init__.py,sha256=0RxJjYSOC5p6o2cu6JbfUzc8ReHYQGNv9pKP-U4u7OE,72
|
||||
prometheus_client/twisted/__pycache__/__init__.cpython-36.pyc,,
|
||||
prometheus_client/twisted/__pycache__/_exposition.cpython-36.pyc,,
|
||||
prometheus_client/twisted/_exposition.py,sha256=PyBlOhIHXFCLjxD6IxfZkwnZaj1_eLFpzUnYHbVLp9c,308
|
||||
prometheus_client/utils.py,sha256=aTZtRyjbY_2lmHMzAHghchy4nSx5rofSibf0Ltzk6Jw,621
|
||||
prometheus_client/values.py,sha256=5i6XZYIzYvuj2TeKnK01dMYVTa9plW7lBgMAgIUrwfI,3836
|
|
@ -0,0 +1,6 @@
|
|||
Wheel-Version: 1.0
|
||||
Generator: bdist_wheel (0.34.2)
|
||||
Root-Is-Purelib: true
|
||||
Tag: py2-none-any
|
||||
Tag: py3-none-any
|
||||
|
|
@ -0,0 +1 @@
|
|||
prometheus_client
|
Loading…
Add table
Add a link
Reference in a new issue