-
Notifications
You must be signed in to change notification settings - Fork 179
fix #166 #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #166 #192
Changes from all commits
29c2a9a
388fce0
cab3d27
49d0194
4a7539e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,10 @@ def run(self): | |
| if self.output_counter is not None: | ||
| self.output_counter.collect(len(self.events), sum([len(e['_raw']) for e in self.events])) | ||
| self.events = None | ||
| self._output_end() | ||
|
|
||
| def _output_end(self): | ||
| pass | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the purpose of this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this callback hook is added as a exit hook point for output plugin. |
||
|
|
||
| def load(): | ||
| return OutputPlugin | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import logging | ||
| import datetime | ||
| import pprint | ||
| import sys | ||
|
|
||
| from outputplugin import OutputPlugin | ||
|
|
||
|
|
||
| class CounterOutputPlugin(OutputPlugin): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we use this good stuff?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we want to use this dummy counter plugin, we can set outputMode=counter in eventgen conf stanza.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's wrong with exposing this option to customers? |
||
| name = 'counter' | ||
| MAXQUEUELENGTH = 1000 | ||
| useOutputQueue = True | ||
|
|
||
| dataSizeHistogram = {} | ||
| eventCountHistogram = {} | ||
| flushCount = 0 | ||
| lastPrintAt = 0 | ||
|
|
||
| def __init__(self, sample, output_counter=None): | ||
| OutputPlugin.__init__(self, sample, output_counter) | ||
|
|
||
| def flush(self, q): | ||
| CounterOutputPlugin.flushCount += 1 | ||
| for e in q: | ||
| ts = datetime.datetime.fromtimestamp(int(e['_time'])) | ||
| text = e['_raw'] | ||
| day = ts.strftime('%Y-%m-%d') | ||
| CounterOutputPlugin.dataSizeHistogram[day] = CounterOutputPlugin.dataSizeHistogram.get(day, 0) + len(text) | ||
| CounterOutputPlugin.eventCountHistogram[day] = CounterOutputPlugin.eventCountHistogram.get(day, 0) + 1 | ||
|
|
||
| def _output_end(self): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is where the output_end hook is used. |
||
| if CounterOutputPlugin.flushCount - CounterOutputPlugin.lastPrintAt > 0: | ||
| self._print_info('----- print the output histogram -----') | ||
| self._print_info('--- data size histogram ---') | ||
| self._print_info(pprint.pformat(CounterOutputPlugin.dataSizeHistogram)) | ||
| self._print_info('--- event count histogram ---') | ||
| self._print_info(pprint.pformat(CounterOutputPlugin.eventCountHistogram)) | ||
| CounterOutputPlugin.lastPrintAt = CounterOutputPlugin.flushCount | ||
|
|
||
| def _print_info(self, msg): | ||
| print >> sys.stderr, '{} {}'.format(datetime.datetime.now(), msg) | ||
|
|
||
| def _setup_logging(self): | ||
| self.logger = logging.getLogger('eventgen_counter_out') | ||
|
|
||
|
|
||
| def load(): | ||
| """Returns an instance of the plugin""" | ||
| return CounterOutputPlugin | ||
Uh oh!
There was an error while loading. Please reload this page.