Skip to content
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

Asomensari doc patch 1 #109

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion docs/outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ you'd like to use.


## Available Third-party outputs
-
- * [New Relic Insights][insights] (`insights`): An Analytics platform that allows for querying, dashboard
and alerting on the data collected byt logster. Setup details can be found here: [New Relic Insights Output](https://github.com/asomensari/logster/blob/master/logster/outputs/insights.md)


If you have an output you'd like to be included here, please open a pull
request with a link to its source/GitHub repo and a brief description of its
Expand Down
10 changes: 6 additions & 4 deletions logster/outputs/builtin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from logster.outputs.stdout import StdoutOutput
from logster.outputs.graphite import GraphiteOutput
from logster.outputs.ganglia import GangliaOutput
from logster.outputs.statsd import StatsdOutput
from logster.outputs.cloudwatch import CloudwatchOutput
from logster.outputs.ganglia import GangliaOutput
from logster.outputs.graphite import GraphiteOutput
from logster.outputs.insights import InsightsOutput
from logster.outputs.nsca import NSCAOutput
from logster.outputs.statsd import StatsdOutput
from logster.outputs.stdout import StdoutOutput

builtin_output_classes = (
StdoutOutput,
Expand All @@ -12,6 +13,7 @@
StatsdOutput,
CloudwatchOutput,
NSCAOutput,
InsightsOutput
)

builtin_outputs = dict([(a.shortname, a) for a in builtin_output_classes])
9 changes: 9 additions & 0 deletions logster/outputs/insights.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# New Relic Insights Output

This output class reports data to New Relic Insights Platform [https://newrelic.com/insights]

These are the configuration options:

- '--event_type_name': Defines the eventType name that will used to report the data (default: 'Logster')
- '--insights_api_key': New Relic Insights API Insert key. Can be configured via enviroment variable 'INSIGHTS_API_KEY_ID'
- '--newrelic_account_number': New Relic Account Number. Can be configured via environment variable 'NEW_RELIC_ACCOUNT'
88 changes: 88 additions & 0 deletions logster/outputs/insights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from logster.logster_helper import LogsterOutput
from httplib import *

import json
import os
import jsonpickle
import platform


class InsightsOutput(LogsterOutput):
shortname = 'insights'

@classmethod
def add_options(cls, parser):
parser.add_option('--stdout-separator', action='store', default="_", dest="stdout_separator",
help='Separator between prefix/suffix and name for stdout. Default is \"%default\".')
parser.add_option('--event_type_name', action='store', default="Logster", dest="event_type_name",
help='Event Type as it will be used by Insights. Default is \"%default\".')
parser.add_option('--insights_api_key', action='store',
default=os.getenv('INSIGHTS_API_KEY_ID'), help='New Relic Insights API Insert key')
parser.add_option('--newrelic_account_number', action='store',
default=os.getenv('NEW_RELIC_ACCOUNT'), help='New Relic Account Number')
parser.add_option('--integration_type', action='store',
default='standalone', help='Define New Relic Integration Type (ohi or standalone)')

def __init__(self, parser, options, logger):
super(InsightsOutput, self).__init__(parser, options, logger)
self.separator = options.stdout_separator
self.insights_url = 'insights-collector.newrelic.com'

self.integration_type = options.integration_type

if not options.newrelic_account_number or not options.insights_api_key:
parser.print_help()
parser.error(
"You must supply --insights_api_key and --newrelic_account_number or Set environment variables. INSIGHTS_API_KEY_ID for --insights_api_key, NEW_RELIC_ACCOUNT for --newrelic_account_number")

self.eventType = options.event_type_name
self.newrelic_account_number = options.newrelic_account_number
self.insights_api_key = options.insights_api_key
self.full_url = '/v1/accounts/' + self.newrelic_account_number + '/events'

def submit(self, metrics):

eventData = []

if self.integration_type == "standalone":

for metric in metrics:
metric.eventType = self.eventType
metric.osName = os.name
metric.platformSystem = platform.system()
metric.platformRelease = platform.release()
platform.python_version()
eventData.append(metric)

try:
conn = HTTPSConnection(self.insights_url)
headers = {
"Content-Type": "application/json",
"X-Insert-Key": self.insights_api_key
}

conn.request("POST", self.full_url, json.dumps([ob.__dict__ for ob in eventData.__iter__()]), headers)

response = conn.getresponse()

print response.status, response.reason

except Exception as ex:
raise Exception("Can't connect ", ex)
else:
for metric in metrics:
metric.event_type = self.eventType
eventData.append(metric)

print jsonpickle.encode(self.getohistructure(eventData))

def getohistructure(self, metrics):
OHIDataEvent = {}
OHIDataEvent["name"] = "com.newrelic.ohi"
OHIDataEvent["protocol_version"] = "1"
OHIDataEvent["integration_version"] = "1.0.0"
OHIDataEvent["metrics"] = {}
OHIDataEvent["metrics"] = metrics

return OHIDataEvent

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
'logster/outputs'
],
install_requires = [
'pygtail>=0.5.1'
'pygtail>=0.5.1',
'jsonpickle>=0.9.5'
],
zip_safe=False,
scripts=[
Expand Down