Replaces tab to 4 whitespaces
This commit also aligns an indent and fixes some syntax. Change-Id: I6aeb7bd4f27a7853f4152e07999776731a7a1a3b
This commit is contained in:
parent
c8a299e9c8
commit
51edaa7a86
@ -141,37 +141,52 @@ The [monasca-statsd](https://github.com/openstack/monasca-statsd library provide
|
|||||||
of a statsd client but also adds the ability to add dimensions to the statsd metrics for the client.
|
of a statsd client but also adds the ability to add dimensions to the statsd metrics for the client.
|
||||||
|
|
||||||
Here are some examples of how code can be instrumented using calls to monasca-statsd.
|
Here are some examples of how code can be instrumented using calls to monasca-statsd.
|
||||||
```
|
|
||||||
|
|
||||||
* Import the module once it's installed.
|
* Import the module once it's installed.
|
||||||
|
|
||||||
|
```python
|
||||||
from monascastatsd import monasca_statsd
|
from monascastatsd import monasca_statsd
|
||||||
statsd = monasca_statsd.MonascaStatsd()
|
statsd = monasca_statsd.MonascaStatsd()
|
||||||
|
```
|
||||||
|
|
||||||
* Optionally, configure the host and port if you're running Statsd on a non-standard port.
|
* Optionally, configure the host and port if you're running Statsd on a non-standard port.
|
||||||
|
|
||||||
|
```python
|
||||||
statsd.connect('localhost', 8125)
|
statsd.connect('localhost', 8125)
|
||||||
|
```
|
||||||
|
|
||||||
* Increment a counter.
|
* Increment a counter.
|
||||||
|
|
||||||
|
```python
|
||||||
statsd.increment('page_views')
|
statsd.increment('page_views')
|
||||||
|
|
||||||
With dimensions:
|
With dimensions:
|
||||||
statsd.increment('page_views', 5, dimensions={'Hostname': 'prod.mysql.abccorp.com'})
|
statsd.increment('page_views', 5, dimensions={'Hostname': 'prod.mysql.abccorp.com'})
|
||||||
|
```
|
||||||
|
|
||||||
* Record a gauge 50% of the time.
|
* Record a gauge 50% of the time.
|
||||||
|
|
||||||
|
```python
|
||||||
statsd.gauge('users_online', 91, sample_rate=0.5)
|
statsd.gauge('users_online', 91, sample_rate=0.5)
|
||||||
|
|
||||||
With dimensions:
|
With dimensions:
|
||||||
statsd.gauge('users_online', 91, dimensions={'Origin': 'Dev', 'Environment': 'Test'})
|
statsd.gauge('users_online', 91, dimensions={'Origin': 'Dev', 'Environment': 'Test'})
|
||||||
|
```
|
||||||
|
|
||||||
* Time a function call.
|
* Time a function call.
|
||||||
|
|
||||||
|
```python
|
||||||
@statsd.timed('page.render')
|
@statsd.timed('page.render')
|
||||||
def render_page():
|
def render_page():
|
||||||
# Render things...
|
# Render things...
|
||||||
|
```
|
||||||
|
|
||||||
* Time a block of code.
|
* Time a block of code.
|
||||||
|
|
||||||
|
```python
|
||||||
with statsd.time('database_read_time',
|
with statsd.time('database_read_time',
|
||||||
dimensions={'db_host': 'mysql1.mycompany.net'}):
|
dimensions={'db_host': 'mysql1.mycompany.net'}):
|
||||||
# Do something...
|
# Do something...
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
Loading…
Reference in New Issue
Block a user