-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from sandipb/master
Some visibility and perf improvements
- Loading branch information
Showing
13 changed files
with
425 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ MANIFEST | |
*.egg-info | ||
.coverage | ||
.tox | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ Content: | |
|
||
intro | ||
quickstart | ||
|
||
speakeasy | ||
|
||
Indices and tables | ||
================== | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Module documentation | ||
==================== | ||
|
||
.. automodule:: speakeasy.speakeasy | ||
:members: | ||
:undoc-members: | ||
|
||
.. automethod:: __init__ | ||
|
||
Included emitters | ||
================= | ||
|
||
Simple | ||
------ | ||
|
||
.. automodule:: speakeasy.emitter.simple | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
max-line-length=120 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
"""The simple emitter writes metrics every interval to a file. | ||
To use this emitter provide the emitter arg `filename` to write to. If an arg is not provided, | ||
this emitter will attempt to write to `metrics.out` barring any permissions issue. | ||
.. code-block:: bash | ||
speakeasy ... --emitter simple --emitter-args filename=/var/tmp/metrics.out | ||
The special names `stdout` or `stderr` will send outputs to the appropriate stream | ||
""" | ||
import logging | ||
import os | ||
import sys | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
DEFAULT_FILENAME = "metrics.out" | ||
DEFAULT_SEPARATOR = "|" | ||
|
||
|
||
class Emitter(object): | ||
|
||
def __init__(self, **kwargs): | ||
self.filename = kwargs['filename'] | ||
self.filename = kwargs.get('filename', DEFAULT_FILENAME) | ||
self.separator = kwargs.get('separator', DEFAULT_SEPARATOR) | ||
|
||
def emit(self, metrics): | ||
fh = None | ||
if self.filename == "stderr": | ||
fh = sys.stderr | ||
elif self.filename == "stdout": | ||
fh = sys.stdout | ||
|
||
if fh: | ||
self._emit(fh, metrics) | ||
else: | ||
with open(self.filename, 'a') as fh: | ||
self._emit(fh, metrics) | ||
|
||
def _emit(self, fh, metrics): | ||
""" Ship the metrics off """ | ||
with open(self.filename, 'a') as fh: | ||
for metric in metrics: | ||
mline = '|'.join([str(m) for m in metric]) | ||
logger.debug('Writing metric out to file - {0}'.format(mline)) | ||
fh.write(mline+'\n') | ||
for metric in metrics: | ||
mline = self.separator.join([str(m) for m in metric]) | ||
fh.write(mline + '\n') |
Oops, something went wrong.