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

Added plugin for Carbon Black monitoring #562

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
build
dist
etc/test.yml
venv
1 change: 1 addition & 0 deletions newrelic_plugin_agent/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
available = {
'apache_httpd': 'newrelic_plugin_agent.plugins.apache_httpd.ApacheHTTPD',
'carbonblack': 'newrelic_plugin_agent.plugins.carbonblack.CarbonBlack',
'couchdb': 'newrelic_plugin_agent.plugins.couchdb.CouchDB',
'edgecast': 'newrelic_plugin_agent.plugins.edgecast.Edgecast',
'elasticsearch':
Expand Down
109 changes: 109 additions & 0 deletions newrelic_plugin_agent/plugins/carbonblack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""
carbonblack

"""
import json
import logging
import requests
import time
from attrdict import AttrDict

from newrelic_plugin_agent.plugins import base

LOGGER = logging.getLogger(__name__)


class CarbonBlack(base.Plugin):

GUID = 'com.meetme.newrelic_carbonblack_agent'

DEFAULT_HOST = 'localhost'
DEFAULT_PORT = 80
DEFAULT_PATH = '/debug/vars'

def add_instance_datapoints(self, instance, data):
"""Send metrics to New Relic for the specified instance
"""
instance_name = instance['name']
upload_bucket = instance['upload_bucket']
LOGGER.info('added %s %s' % (instance_name, data.error_count))
print('added %s ' % instance_name)

self.add_gauge_value('%s/ErrorCount' % instance_name, 'errors', data.error_count)
self.add_derive_value('%s/ErrorRate' % instance_name, 'errors', data.error_count)

self.add_gauge_value(
'%s/Upload/FilesCount' % instance_name,
'files',
data.output_status[upload_bucket]['files_uploaded'])
self.add_derive_value(
'%s/Upload/FilesRate' % instance_name,
'files',
data.output_status[upload_bucket]['files_uploaded'])

self.add_gauge_value(
'%s/Upload/ErrorsCount' % instance_name,
'errors',
data.output_status[upload_bucket]['upload_errors'])
self.add_derive_value(
'%s/Upload/ErrorsRate' % instance_name,
'errors',
data.output_status[upload_bucket]['upload_errors'])

self.add_gauge_value(
'%s/Events/InputCount' % instance_name,
'events',
data.input_event_count)
self.add_derive_value(
'%s/Events/InputRate' % instance_name,
'events',
data.input_event_count)

self.add_gauge_value(
'%s/Events/OutputCount' % instance_name,
'events',
data.output_event_count)
self.add_derive_value(
'%s/Events/OutputRate' % instance_name,
'events',
data.output_event_count)

def poll(self):
"""Poll each of the defined CarbonBlack instances"""
for instance in self.carbonblack_instances:
LOGGER.info('Polling CarbonBlack %s' % instance['name'])
start_time = time.time()

response = requests.get(instance['url'])

self.add_instance_datapoints(
instance=instance,
data=AttrDict(json.loads(response.text)))

LOGGER.info('Polling complete in %.2f seconds',
time.time() - start_time)

@property
def carbonblack_instances(self):
"""Return a list of monitored CB instance dicts
"""
instances = []
default_upload_bucket = self.config.get('upload_bucket')
for instance in self.config.get('instances', []):
secure = instance.get('secure', False)
scheme = 'https' if secure else 'http'
instance_upload_bucket = instance.get('upload_bucket', default_upload_bucket)
url = '{scheme}://{host}:{port}{path}'.format(
scheme=scheme,
host=instance['host'],
port=instance.get('port', self.DEFAULT_PORT),
path=instance.get('path', self.DEFAULT_PATH)
)

instances.append(dict(
name=instance['name'],
url=url,
upload_bucket=instance_upload_bucket
))

return instances
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'apc-nrp.php']

console_scripts = ['newrelic-plugin-agent=newrelic_plugin_agent.agent:main']
install_requires = ['helper>=2.2.2', 'requests>=2.0.0']
install_requires = ['helper>=2.2.2', 'requests>=2.0.0', 'attrdict>=2.0.1']
tests_require = []
extras_require = {'mongodb': ['pymongo'],
'pgbouncer': ['psycopg2'],
Expand Down