Files
monasca-agent/monasca_setup/detection/plugins/json_plugin.py
Donagh McCabe a72f907eef Add json_plugin: simple way to post metrics to Monasca
This patch adds a plugin that reads metrics from JSON files. This
makes it very easy to integrate with Monasca -- instead of writing
a new plugin, simply write your metrics to a file.

The advantage of this mechanism is that:
- It's simple and easy to understand
- It is asynchronous with Monasca Agent. There are two technical
  advantages to this:
    - Your check does not need to run at same frequency as
      the agent.
    - If your check blocks, this does not affect other checks
      in the agent because the agent is not blocked.
- You can create the metrics as a side effect of doing other
  stuff. For example, a server process can write the JSON
  file while it is processing requests. With the normal plugin
  architecture, you need to write code that talks to your
  server process to access the metrics.
- You can write the check code in any language.

Change-Id: I1e998fa677e16cc04d46edd46d0e6433131825e7
2016-12-09 14:04:02 +00:00

41 lines
1.2 KiB
Python

# (c) Copyright 2016 Hewlett Packard Enterprise Development LP
from monasca_setup import agent_config
import monasca_setup.detection
import os
VAR_CACHE_DIR = '/var/cache/monasca_json_plugin'
class JsonPlugin(monasca_setup.detection.ArgsPlugin):
"""Detect if /var/cache/monasca_json_plugin exists
This builds a config for the json_plugin. This detects if
/var/cache/monasca_json_plugin exists and if so,
builds a configuration for it.
Users are free to add their own configs.
"""
def __init__(self, template_dir, overwrite=True, args=None):
super(JsonPlugin, self).__init__(
template_dir, overwrite, args)
def _detect(self):
self.available = False
if os.path.isdir(VAR_CACHE_DIR):
self.available = True
def build_config(self):
"""Build the config as a Plugins object and return."""
config = agent_config.Plugins()
config['json_plugin'] = {'init_config': None,
'instances': [{'name': VAR_CACHE_DIR,
'metrics_dir': VAR_CACHE_DIR}]}
return config
def dependencies_installed(self):
"""Return True if dependencies are installed."""
return True