Converted the agent config file to yaml to match the plugin config files

Converted the config file to yaml and updated the config processing logic to match.
Cleaned up some deprecated config item processing.

Change-Id: I8c5d9ad841b22d20825608ac9f2c82d8011b04f0
This commit is contained in:
Gary Hessler 2015-02-26 09:56:38 -07:00
parent b1de7db1f5
commit f9fd9c5a30
13 changed files with 225 additions and 256 deletions

2
.gitignore vendored
View File

@ -3,7 +3,7 @@
.idea
.settings
*.pyc
agent.conf
agent.yaml
build
dist
artifacts

View File

@ -129,7 +129,7 @@ The Agent is composed of the following components:
| Agent Checks | checks.d/*.py | Python-based user-configured checks. These checks can be for other applications or services to verify functionality or gather statistics on things such as messages processed, etc. Each additional agent check must be configured using a yaml file for a specific plugin that provides the additional functionality located in the conf.d directory. |
The Agent includes the "monasca-setup" script, that can be used for automatically configuring the agent to generate metrics that are sent to the API. It creates the agent.conf file locate in /etc/monasca/agent directory. It also sets up additional checks based on what is running locally on that machine. For instance, if this is a compute node, the agent will setup checks to monitor the Nova processes and setup a http_status check on the nova-api. It can also detect other servers such as mySQL and Kafka and setup checks for them as well.
The Agent includes the "monasca-setup" script, that can be used for automatically configuring the agent to generate metrics that are sent to the API. It creates the agent.yaml file located in /etc/monasca/agent directory. It also sets up additional checks based on what is running locally on that machine. For instance, if this is a compute node, the agent will setup checks to monitor the Nova processes and setup a http_status check on the nova-api. It can also detect other servers such as mySQL and Kafka and setup checks for them as well.
A metric is identified by a name and dimensions. The fields required in a metric are name, timestamp, and value. A metric can also have 0..n dimensions. Some standard dimensions are sent with all metrics that are sent by the agent. Reference the section on [Dimensions](#dimensions) for more details.
@ -160,7 +160,7 @@ sudo pip install monasca-agent
The Agent requires configuration in order to run. There are two ways to configure the agent, either using the [monasca-setup](#monasca-setup) script or manually.
## monasca-setup (Recommended)
The Monasca agent has a script, called "monasca-setup", that should be used to automatically configure the Agent to send metrics to a Monasca API. This script will create the agent.conf configuration file as well as any plugin configuration yaml files needed to monitor the processes on the local machine. The mon-setup script will auto-detect certain applications and OpenStack processes that are running on the machine. The agent configuration files are located in /etc/monasca/agent. The plugin configuration files are located in located in /etc/monasca/agent/conf.d.
The Monasca agent has a script, called "monasca-setup", that should be used to automatically configure the Agent to send metrics to a Monasca API. This script will create the agent.yaml configuration file as well as any plugin configuration yaml files needed to monitor the processes on the local machine. The mon-setup script will auto-detect certain applications and OpenStack processes that are running on the machine. The agent configuration files are located in /etc/monasca/agent. The plugin configuration files are located in /etc/monasca/agent/conf.d.
To run monasca-setup:
@ -185,21 +185,21 @@ All parameters require a '--' before the parameter such as '--verbose'
| headless | This is an optional parameter that specifies whether monasca-setup should run in a non-interactive mode | |
| skip_enable | This is an optional parameter. By default the service is enabled, which requires the script run as root. Set this parameter to skip that step. | |
| verbose | This is an optional parameter that specifies whether the monasca-setup script will print additional information for debugging purposes | |
| overwrite | This is an optional parameter to overwrite the plugin configuration. Use this if you don't want to keep the original configuration. If this parameter is not specified, the configuration will be appended to the existing configuration, possibly creating duplicate checks. **NOTE:** The agent config file, agent.conf, will always be overwritten, even if this parameter is not specified | |
| overwrite | This is an optional parameter to overwrite the plugin configuration. Use this if you don't want to keep the original configuration. If this parameter is not specified, the configuration will be appended to the existing configuration, possibly creating duplicate checks. **NOTE:** The agent config file, agent.yaml, will always be overwritten, even if this parameter is not specified | |
| amplifier | For load testing purposes, this value will multiply the number of metrics submitted in each payload. Set to 1 for one additional set of metrics, 2 for two additional sets, etc. Additional sets of metrics are identified by the 'amplifier' dimension. Set to 0 for typical production use. | 0 |
### Manual Configuration of the Agent
This is not the recommended way to configure the agent but if you are having trouble running the monasca-setup program, you can manually configure the agent using the steps below:
Start by creating an agent.conf file. An example configuration file can be found in /usr/local/share/monasca/agent/.
Start by creating an agent.yaml file. An example configuration file can be found in /usr/local/share/monasca/agent/.
sudo mkdir -p /etc/monasca/agent
sudo cp /usr/local/share/monasca/agent/agent.conf.template /etc/monasca/agent/agent.conf
sudo cp /usr/local/share/monasca/agent/agent.yaml.template /etc/monasca/agent/agent.yaml
and then edit the file with your favorite text editor (vi, nano, emacs, etc.)
sudo nano /etc/monasca/agent/agent.conf
sudo nano /etc/monasca/agent/agent.yaml
In particular, replace any values that have curly braces.
Example:
@ -211,7 +211,7 @@ Change
username: myuser
You must replace all of the curly brace values and you can also optionally tweak any of the other configuration items as well like a port number in the case of a port conflict. The config file options are documented in the agent.conf.template file. You may also specify zero or more dimensions that would be included in every metric generated on that node, using the dimensions: value. Example: (include no extra dimensions on every metric)
You must replace all of the curly brace values and you can also optionally tweak any of the other configuration items as well like a port number in the case of a port conflict. The config file options are documented in the agent.yaml.template file. You may also specify zero or more dimensions that would be included in every metric generated on that node, using the dimensions: value. Example: (include no extra dimensions on every metric)
dimensions: (This means no dimensions)
OR
@ -1107,7 +1107,7 @@ All metrics include `resource_id` and `zone` (availability zone) dimensions. Be
| tenant_id | (N/A) | owner of VM |
### Cross-Tenant Metric Submission
If the owner of the VM is to receive his or her own metrics, the Agent needs to be able to submit metrics on their behalf. This is called cross-tenant metric submission. For this to work, a Keystone role called "monitoring-delegate" needs to be created, and the Agent's Keystone username and project (tenant) assigned to it. This username is contained as `username` in `/etc/monasca/agent/agent.conf`, and passed to `monasca-setup` as the `-u` parameter. The Agent's project name which is contained in `agent.conf` as the variable `project_name`, and passed to `monasca-setup` as the `--project-name` parameter.
If the owner of the VM is to receive his or her own metrics, the Agent needs to be able to submit metrics on their behalf. This is called cross-tenant metric submission. For this to work, a Keystone role called "monitoring-delegate" needs to be created, and the Agent's Keystone username and project (tenant) assigned to it. This username is contained as `username` in `/etc/monasca/agent/agent.yaml`, and passed to `monasca-setup` as the `-u` parameter. The Agent's project name which is contained in `agent.yaml` as the variable `project_name`, and passed to `monasca-setup` as the `--project-name` parameter.
In the below example, the Agent's Keystone username is "monasca-agent" and the Agent's Keystone project name is "mini-mon".

View File

@ -1,117 +0,0 @@
[Api]
# To configure Keystone correctly, a project-scoped token must be acquired.
# To accomplish this, the configuration must be set up with one of the
# following scenarios:
# Set username and password and you have a default project set in keystone.
# Set username, password and project id.
# Set username, password, project name and (domain id or domain name).
#
# Monitoring API URL: URL for the monitoring API, if undefined it will be pulled from the keystone service catalog
# Example: https://region-a.geo-1.monitoring.hpcloudsvc.com:8080/v2.0
url: {args.monasca_url}
# Keystone Username
username: {args.username}
# Keystone Password
password: {args.password}
# Keystone API URL: URL for the Keystone server to use
# Example: https://region-a.geo-1.identity.hpcloudsvc.com:35357/v3/
keystone_url: {args.keystone_url}
# Project name to be used by this agent
project_name: {args.project_name}
# Project domain id to be used by this agent
project_domain_id: {args.project_domain_id}
# Project domain id to be used by this agent
project_domain_name: {args.project_domain_name}
# Project id to be used by this agent
project_id: {args.project_id}
# Set whether certificates are used for Keystone
# *******************************************************************************************
# **** CAUTION ****: The insecure flag should NOT be set to True in a production environment!
# *******************************************************************************************
# If insecure is set to False, a ca_file name must be set to authenticate with Keystone
insecure: {args.insecure}
# Name of the ca certs file
ca_file: {args.ca_file}
# The following 2 options are for handling buffering and reconnection to the monasca-api
# If you want the messages to be sent as fast as possible, set these two options to
# the same number. If you have a larger system with many agents, you may want to throttle
# the number of messages sent to the API by setting the backlog_send_rate to a lower number.
# Maximum number of messages to buffer when unable to communicate with the monasca-api
max_buffer_size: 1000
# Maximum number of messages to send at one time when communication with the monasca-api is restored
backlog_send_rate: 1000
# Publish extra metrics to the API by adding this number of 'amplifier' dimensions.
# For load testing purposes only; set to 0 for production use.
amplifier: {args.amplifier}
[Main]
# Force the hostname to whatever you want.
hostname: {hostname}
# Optional dimensions to be sent with every metric from this node
# They should be in the format name:value and seperated by a comma
# Example (dimensions: service:nova, group:group_a, ...)
dimensions: {args.dimensions}
# Set the threshold for accepting points to allow anything
# with recent_point_threshold seconds
# Defaults to 30 seconds if no value is provided
#recent_point_threshold: 30
# time to wait between collection runs
check_freq: {args.check_frequency}
# Change port the Agent is listening to
# listen_port: 17123
# Additional directory to look for checks
# additional_checksd: /etc/monasca/agent/checks.d/
# Allow non-local traffic to this Agent
# This is required when using this Agent as a proxy for other Agents
# that might not have an internet connection
# For more information, please see
# https://github.com/DataDog/dd-agent/wiki/Network-Traffic-and-Proxy-Configuration
# non_local_traffic: no
[Statsd]
# ========================================================================== #
# Monasca Statsd configuration #
# ========================================================================== #
# Monasca Statsd is a small server that aggregates your custom app metrics.
# Make sure your client is sending to the same port.
monasca_statsd_port : 8125
## The monasca_statsd flush period.
# monasca_statsd_interval : 20
# If you want to forward every packet received by the monasca_statsd server
# to another statsd server, uncomment these lines.
# WARNING: Make sure that forwarded packets are regular statsd packets and not "monasca_statsd" packets,
# as your other statsd server might not be able to handle them.
# monasca_statsd_forward_host: address_of_own_statsd_server
# monasca_statsd_statsd_forward_port: 8125
[Logging]
# ========================================================================== #
# Logging
# ========================================================================== #
log_level: {args.log_level}
collector_log_file: /var/log/monasca/agent/collector.log
forwarder_log_file: /var/log/monasca/agent/forwarder.log
statsd_log_file: /var/log/monasca/agent/statsd.log
# if syslog is enabled but a host and port are not set, a local domain socket
# connection will be attempted
#
# log_to_syslog: yes
# syslog_host:
# syslog_port:

117
agent.yaml.template Normal file
View File

@ -0,0 +1,117 @@
Api:
# To configure Keystone correctly, a project-scoped token must be acquired.
# To accomplish this, the configuration must be set up with one of the
# following scenarios:
# Set username and password and you have a default project set in keystone.
# Set username, password and project id.
# Set username, password, project name and (domain id or domain name).
#
# Monitoring API URL: URL for the monitoring API, if undefined it will be pulled from the keystone service catalog
# Example: https://region-a.geo-1.monitoring.hpcloudsvc.com:8080/v2.0
url: {args.monasca_url}
# Keystone Username
username: {args.username}
# Keystone Password
password: {args.password}
# Keystone API URL: URL for the Keystone server to use
# Example: https://region-a.geo-1.identity.hpcloudsvc.com:35357/v3/
keystone_url: {args.keystone_url}
# Project name to be used by this agent
project_name: {args.project_name}
# Project domain id to be used by this agent
project_domain_id: {args.project_domain_id}
# Project domain id to be used by this agent
project_domain_name: {args.project_domain_name}
# Project id to be used by this agent
project_id: {args.project_id}
# Set whether certificates are used for Keystone
# *******************************************************************************************
# **** CAUTION ****: The insecure flag should NOT be set to True in a production environment!
# *******************************************************************************************
# If insecure is set to False, a ca_file name must be set to authenticate with Keystone
insecure: {args.insecure}
# Name of the ca certs file
ca_file: {args.ca_file}
# The following 2 options are for handling buffering and reconnection to the monasca-api
# If you want the messages to be sent as fast as possible, set these two options to
# the same number. If you have a larger system with many agents, you may want to throttle
# the number of messages sent to the API by setting the backlog_send_rate to a lower number.
# Maximum number of messages to buffer when unable to communicate with the monasca-api
max_buffer_size: 1000
# Maximum number of messages to send at one time when communication with the monasca-api is restored
backlog_send_rate: 1000
# Publish extra metrics to the API by adding this number of 'amplifier' dimensions.
# For load testing purposes only; set to 0 for production use.
amplifier: {args.amplifier}
Main:
# Force the hostname to whatever you want.
hostname: {hostname}
# Optional dimensions to be sent with every metric from this node
# They should be in the format name: value
# Example of dimensions below
# dimensions:
# service: nova
# group: group_a
# environment: production
dimensions: {args.dimensions}
# Set the threshold for accepting points to allow anything
# with recent_point_threshold seconds
# Defaults to 30 seconds if no value is provided
#recent_point_threshold: 30
# time to wait between collection runs
check_freq: {args.check_frequency}
# Change port the Agent is listening to
# listen_port: 17123
# Additional directory to look for checks
# additional_checksd: /etc/monasca/agent/checks.d/
# Allow non-local traffic to this Agent
# This is required when using this Agent as a proxy for other Agents
# that might not have an internet connection
# For more information, please see
# https://github.com/DataDog/dd-agent/wiki/Network-Traffic-and-Proxy-Configuration
# non_local_traffic: no
Statsd:
# ========================================================================== #
# Monasca Statsd configuration #
# ========================================================================== #
# Monasca Statsd is a small server that aggregates your custom app metrics.
# Make sure your client is sending to the same port.
monasca_statsd_port : 8125
## The monasca_statsd flush period.
# monasca_statsd_interval : 20
# If you want to forward every packet received by the monasca_statsd server
# to another statsd server, uncomment these lines.
# WARNING: Make sure that forwarded packets are regular statsd packets and not "monasca_statsd" packets,
# as your other statsd server might not be able to handle them.
# monasca_statsd_forward_host: address_of_own_statsd_server
# monasca_statsd_statsd_forward_port: 8125
Logging:
# ========================================================================== #
# Logging
# ========================================================================== #
log_level: {args.log_level}
collector_log_file: /var/log/monasca/agent/collector.log
forwarder_log_file: /var/log/monasca/agent/forwarder.log
statsd_log_file: /var/log/monasca/agent/statsd.log
# if syslog is enabled but a host and port are not set, a local domain socket
# connection will be attempted
#
# log_to_syslog: yes
# syslog_host:
# syslog_port:

View File

@ -1,4 +1,3 @@
import ConfigParser as parser
import logging
import os
import pkg_resources
@ -15,28 +14,71 @@ except ImportError:
import monasca_agent.common.singleton as singleton
DEFAULT_CONFIG_FILE = '/etc/monasca/agent/agent.conf'
DEFAULT_CONFIG_FILE = '/etc/monasca/agent/agent.yaml'
DEFAULT_LOG_DIR = '/var/log/monasca/agent'
LOGGING_MAX_BYTES = 5 * 1024 * 1024
log = logging.getLogger(__name__)
class Config(object):
# Make this a singleton class so we don't get the config every time
# the class is created
__metaclass__ = singleton.Singleton
def __init__(self, configFile=None):
self._config = None
if configFile is not None:
self._configFile = configFile
elif os.path.exists(DEFAULT_CONFIG_FILE):
self._configFile = DEFAULT_CONFIG_FILE
elif os.path.exists(os.getcwd() + '/agent.conf'):
self._configFile = os.getcwd() + '/agent.conf'
elif os.path.exists(os.getcwd() + '/agent.yaml'):
self._configFile = os.getcwd() + '/agent.yaml'
else:
log.error('No config file found at {0} nor in the working directory.'.format(DEFAULT_CONFIG_FILE))
error_msg = 'No config file found at {0} nor in the working directory.'.format(DEFAULT_CONFIG_FILE)
log.error(error_msg)
raise IOError(error_msg)
# Define default values for the possible config items
self._config = {'Main': {'check_freq': 15,
'forwarder_url': 'http://localhost:17123',
'hostname': None,
'dimensions': None,
'listen_port': None,
'version': self.get_version(),
'additional_checksd': os.path.join(os.path.dirname(self._configFile), '/checks_d/'),
'limit_memory_consumption': None,
'skip_ssl_validation': False,
'watchdog': True,
'autorestart': False,
'non_local_traffic': False},
'Api': {'is_enabled': False,
'url': '',
'project_name': '',
'project_id': '',
'project_domain_name': '',
'project_domain_id': '',
'ca_file': '',
'insecure': '',
'username': '',
'password': '',
'use_keystone': True,
'keystone_url': '',
'max_buffer_size': 1000,
'backlog_send_rate': 5},
'Statsd': {'recent_point_threshold': None,
'monasca_statsd_interval': 20,
'monasca_statsd_forward_host': None,
'monasca_statsd_forward_port': 8125,
'monasca_statsd_port': 8125},
'Logging': {'disable_file_logging': False,
'log_level': None,
'collector_log_file': DEFAULT_LOG_DIR + '/collector.log',
'forwarder_log_file': DEFAULT_LOG_DIR + '/forwarder.log',
'statsd_log_file': DEFAULT_LOG_DIR + '/statsd.log',
'jmxfetch_log_file': DEFAULT_LOG_DIR + '/jmxfetch.log',
'log_to_event_viewer': False,
'log_to_syslog': False,
'syslog_host': None,
'syslog_port': None}}
self._read_config()
@ -62,105 +104,14 @@ class Config(object):
def _read_config(self):
"""Read in the config file."""
file_config = parser.SafeConfigParser()
log.debug("Loading config file from {0}".format(self._configFile))
file_config.readfp(self._skip_leading_wsp(open(self._configFile)))
self._config = self._retrieve_sections(file_config)
# Process and update any special case configuration
self._parse_config()
def _retrieve_sections(self, config):
"""Get the section values from the config file."""
# Define default values for the possible config items
the_config = {'Main': {'check_freq': 15,
'forwarder_url': 'http://localhost:17123',
'hostname': None,
'dimensions': None,
'listen_port': None,
'version': self.get_version(),
'additional_checksd': os.path.join(os.path.dirname(self._configFile), '/checks_d/'),
'system_metrics': None,
'limit_memory_consumption': None,
'skip_ssl_validation': False,
'watchdog': True,
'autorestart': False,
'non_local_traffic': False},
'Api': {'is_enabled': False,
'url': '',
'project_name': '',
'project_id': '',
'project_domain_name': '',
'project_domain_id': '',
'ca_file': '',
'insecure': '',
'username': '',
'password': '',
'use_keystone': True,
'keystone_url': '',
'max_buffer_size': 1000,
'backlog_send_rate': 5},
'Statsd': {'recent_point_threshold': None,
'monasca_statsd_interval': 20,
'monasca_statsd_forward_host': None,
'monasca_statsd_forward_port': 8125,
'monasca_statsd_port': 8125},
'Logging': {'disable_file_logging': False,
'log_level': None,
'collector_log_file': DEFAULT_LOG_DIR + '/collector.log',
'forwarder_log_file': DEFAULT_LOG_DIR + '/forwarder.log',
'statsd_log_file': DEFAULT_LOG_DIR + '/statsd.log',
'jmxfetch_log_file': DEFAULT_LOG_DIR + '/jmxfetch.log',
'log_to_event_viewer': False,
'log_to_syslog': False,
'syslog_host': None,
'syslog_port': None}}
# Load values from configuration file into config file dictionary
for section in config.sections():
for option in config.options(section):
try:
option_value = config.get(section, option)
if option_value == -1:
log.debug("Config option missing: {0}, using default value of {1}".format(option,
the_config[section][
option]))
else:
the_config[section][option] = option_value
except Exception:
log.error("exception on %s!" % option)
return the_config
def _skip_leading_wsp(self, file):
"""Works on a file, returns a file-like object"""
return cstringio.StringIO("\n".join(map(string.strip, file.readlines())))
def _parse_config(self):
# Parse_dimensions
if self._config['Main']['dimensions'] is not None:
# parse comma separated dimensions into a dimension list
dimensions = {}
try:
dim_list = [dim.split(':') for dim in self._config['Main']['dimensions'].split(',')]
dimensions.update(dict((key.strip(), value.strip()) for key, value in dim_list))
except ValueError:
log.info("Unable to process dimensions.")
dimensions = {}
self._config['Main']['dimensions'] = dimensions
# Parse system metrics
if self._config['Main']['system_metrics']:
# parse comma separated system metrics into a metrics list
try:
metrics_list = [x.strip() for x in self._config['Main']['system_metrics'].split(',')]
except ValueError:
log.info("Unable to process system_metrics.")
metrics_list = []
self._config['Main']['system_metrics'] = metrics_list
try:
with open(self._configFile, 'r') as f:
log.debug('Loading config file from {0}'.format(self._configFile))
config = yaml.load(f.read(), Loader=Loader)
[self._config[section].update(config[section]) for section in config.keys()]
except Exception as e:
log.exception('Error loading config file from {0}'.format(self._configFile))
raise e
def get_confd_path(self):
path = os.path.join(os.path.dirname(self._configFile), 'conf.d')
@ -196,9 +147,14 @@ def main():
configuration = Config()
config = configuration.get_config()
api_config = configuration.get_config('Api')
statsd_config = configuration.get_config('Statsd')
logging_config = configuration.get_config('Logging')
print "Main Configuration: \n {0}".format(config)
print "\nApi Configuration: \n {0}".format(api_config)
print "\nStatsd Configuration: \n {0}".format(statsd_config)
print "\nLogging Configuration: \n {0}".format(logging_config)
if __name__ == "__main__":
logging.basicConfig()
main()

View File

@ -494,7 +494,7 @@ def get_hostname():
Tries, in order:
* agent config (agent.conf, "hostname:")
* agent config (agent.yaml, "hostname:")
* 'hostname -f' (on unix)
* socket.gethostname()
"""
@ -536,9 +536,9 @@ def get_hostname():
if hostname is None:
log.critical(
'Unable to reliably determine host name. You can define one in agent.conf or in your hosts file')
'Unable to reliably determine host name. You can define one in agent.yaml or in your hosts file')
raise Exception(
'Unable to reliably determine host name. You can define one in agent.conf or in your hosts file')
'Unable to reliably determine host name. You can define one in agent.yaml or in your hosts file')
else:
return hostname

View File

@ -28,7 +28,7 @@ log = logging.getLogger(__name__)
PREFIX_DIR = os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))
def write_template(template_path, out_path, variables, group):
def write_template(template_path, out_path, variables, group, is_yaml=False):
""" Write a file using a simple python string template.
Assumes 640 for the permissions and root:group for ownership.
:param template_path: Location of the Template to use
@ -40,8 +40,15 @@ def write_template(template_path, out_path, variables, group):
print("Error no template found at {0}".format(template_path))
sys.exit(1)
with open(template_path, 'r') as template:
contents = template.read().format(**variables)
with open(out_path, 'w') as conf:
conf.write(template.read().format(**variables))
if is_yaml:
conf.write(yaml.safe_dump(yaml.safe_load(contents),
encoding='utf-8',
allow_unicode=True,
default_flow_style=False))
else:
conf.write(contents)
os.chown(out_path, 0, group)
os.chmod(out_path, 0640)
@ -73,7 +80,7 @@ def main(argv=None):
parser.add_argument('--headless', help="Run in a non-interactive mode", action="store_true")
parser.add_argument('--overwrite',
help="Overwrite existing plugin configuration. " +
"The default is to merge. Agent.conf is always overwritten.",
"The default is to merge. agent.yaml is always overwritten.",
action="store_true")
parser.add_argument('--skip_enable', help="By default the service is enabled, " +
"which requires the script run as root. Set this to skip that step.",
@ -129,18 +136,21 @@ def main(argv=None):
agent_service.enable()
gid = pwd.getpwnam(args.user).pw_gid
# Write the main agent.conf - Note this is always overwritten
# Write the main agent.yaml - Note this is always overwritten
log.info('Configuring base Agent settings.')
dimensions = {}
# Join service in with the dimensions
if args.service:
if args.dimensions is None:
args.dimensions = 'service:' + args.service
else:
args.dimensions = ','.join([args.dimensions, 'service:' + args.service])
write_template(os.path.join(args.template_dir, 'agent.conf.template'),
os.path.join(args.config_dir, 'agent.conf'),
dimensions.update({'service': args.service})
if args.dimensions:
dimensions.update(dict(item.strip().split(":") for item in args.dimensions.split(",")))
args.dimensions = {name: value for name, value in dimensions.iteritems()}
write_template(os.path.join(args.template_dir, 'agent.yaml.template'),
os.path.join(args.config_dir, 'agent.yaml'),
{'args': args, 'hostname': socket.getfqdn() },
gid)
gid,
is_yaml=True)
# Write the supervisor.conf
write_template(os.path.join(args.template_dir, 'supervisor.conf.template'),
@ -174,9 +184,12 @@ def main(argv=None):
with open(config_path, 'w') as config_file:
os.chmod(config_path, 0o640)
os.chown(config_path, 0, gid)
config_file.write(yaml.safe_dump(value, encoding='utf-8', allow_unicode=True))
config_file.write(yaml.safe_dump(value,
encoding='utf-8',
allow_unicode=True,
default_flow_style=False))
# Now that the config is build start the service
# Now that the config is built, start the service
try:
agent_service.start(restart=True)
except subprocess.CalledProcessError:

View File

@ -37,7 +37,7 @@ source:
cp -r $(SRC)/monasca_agent $(ROOT)/
cp -r $(SRC)/conf.d $(ROOT)/
cp -r $(SRC)/LICENSE* $(ROOT)/
cp -r $(SRC)/agent.conf.template $(ROOT)/
cp -r $(SRC)/agent.yaml.template $(ROOT)/
find $(ROOT) -name "*.pyc" -exec rm {} \;

View File

@ -15,7 +15,7 @@ PATH=$PATH:/sbin # add the location of start-stop-daemon on Debian
export PYTHONPATH=$PYTHONPATH:/usr/monasca/agent/
AGENTPATH="/usr/local/bin/monasca-collector"
AGENTCONF="/etc/monasca/agent/agent.conf"
AGENTCONF="/etc/monasca/agent/agent.yaml"
MONASCASTATSDPATH="/usr/local/bin/monasca-statsd"
AGENTUSER="monasca-agent"
FORWARDERPATH="/usr/local/bin/monasca-forwarder"

View File

@ -26,9 +26,9 @@ case "$1" in
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
if [ $RETVAL -eq 3 ]; then
# No agent.conf file is present. The user is probably following
# No agent.yaml file is present. The user is probably following
# the step-by-step instructions and will add the config file next.
echo "No /etc/monasca/agent/agent.conf found, exiting"
echo "No /etc/monasca/agent/agent.yaml found, exiting"
exit 0
else
exit $?

View File

@ -14,7 +14,7 @@ PATH=$PATH:/usr/local/bin # supervisord might live here
PATH=$PATH:/sbin
AGENTPATH="{prefix}/bin/monasca-collector"
AGENTCONF="{config_dir}/agent.conf"
AGENTCONF="{config_dir}/agent.yaml"
MONASCASTATSDPATH="{prefix}/bin/monasca-statsd"
AGENTUSER="monasca-agent"
FORWARDERPATH="{prefix}/bin/monasca-forwarder"

View File

@ -21,7 +21,7 @@ packages =
monasca_setup
data_files=
share/monasca/agent =
agent.conf.template
agent.yaml.template
packaging/supervisor.conf.template
packaging/monasca-agent.init.template
share/monasca/agent/conf.d = conf.d/*

View File

@ -2,7 +2,7 @@ Tests for the mon agent.
Run with `nosestests -w tests`
For many tests to work an agent.conf must be in either /etc/monasca/agent/agent.conf or in the working directory.
For many tests to work an agent.yaml must be in either /etc/monasca/agent/agent.yaml or in the working directory.
Many tests require specific applications enabled in order for the test to run, these are skipped by default. See
https://nose.readthedocs.org/en/latest/plugins/skip.html for details.
https://nose.readthedocs.org/en/latest/plugins/skip.html for details.