Contrail Insights User-Defined Plug-Ins
Contrail Insights plug-ins can be used to extend the set of metrics monitored and analyzed by Contrail Insights. Plug-ins are executed by a Contrail Insights Agent. The metrics produced by the plug-in are associated with the host on which the Agent executed.
Contrail Insights Ansible playbooks install a plug-in executable file on a host(s) and configure the plug-in in the Contrail Insights Platform.
Add a User-Defined Command Plug-In
To create a new plug-in in Contrail Insights, provide the executable
files with the valid output format. For this example, the check_nginx.py file is used, which has the following
output:
$ python ./check_nginx.py OK - nginx.node: 4qps nginx_concurrent_connections
$ cat /opt/appformix/manager/tailwind_manager/check_nginx.py
import sys
import traceback
import commands
def nginx_metrics():
result = {'connections': 0}
try:
command = "netstat -lanp | grep 'nginx: worker' | wc -l"
out = commands.getoutput(command)
result['connections'] = int(out)
except Exception as e:
traceback.print_exc()
return result
def main(argv):
result = nginx_metrics()
try:
msg = ('nginx.node: {0}qps nginx_concurrent_connections').\
format(
result['connections']
)
except Exception as e:
traceback.print_exc()
test_state = 0
logger_helper(
msg,
test_state
)
def logger_helper(message, state):
if state == 2:
print "CRITICAL - " + message
sys.exit(2)
elif state == 1:
print "WARNING - " + message
sys.exit(1)
elif state == 0:
print "OK - " + message
sys.exit(0)
else:
print "CRITICAL - Unexpected value : %d" % state + "; " + message
sys.exit(2)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
In the Contrail Insights installation directory, there is a
directory named user_defined_plugins. You
need to create a <PLUGIN_FILE>.json with the configuration for
the plug-in and the metrics it exposes. In the following example,
we create a nginx_connections.json for
the check_nginx.py plug-in referenced above.
$ cd appformix-<VERSION>/
$ touch appformix-<VERSION>/user_defined_plugins/<PLUGIN_NAME>.json
{
"AggregateId": "process_monitoring_A",
"Collection": "host_pythonchecknginxpy_collection",
"Config": {
"CommandLine": "python check_nginx.py"
},
"MetricMap": [
{
"Name": "nginx_concurrent_connections",
"Units": "qps"
}
],
"PluginId": "pythonchecknginxpy",
"PluginName": "nginx.node",
"PluginType": "command",
"Scope": "host",
"State": "enabled",
"status": "success"
}
The field MetricMap is a list of
metrics and its unit that is collected by this plug-in and field AggregateId indicates in what host aggregate you want
to run this plug-in. If the AggregateId is specified, then the plug-in will only apply to the hosts in that
aggregate. If AggregateId is not specified,
then the plug-in will run on all of the hosts monitored by Contrail
Insights.
Table 1 describes the fields in the sample configuration.
Field |
Description |
|---|---|
AggregateId |
Specifies a host aggregate. Plug-in is installed and configured to run on hosts in this aggregate. If AggregateId is not specified, then plug-in is configured to run on all hosts on which Contrail Insights Agent is installed. |
Collection |
A label applied to data produced by this plug-in. |
Config.CommandLine |
The command to execute. |
MetricMap |
A list of metrics produced by the plug-in and the units of each metric (for display in the Dashboard). |
PluginId |
Plug-in identifier in Contrail Insights. This must be unique among all configured plug-ins. |
PluginName |
Name of the plug-in. Name is used as a prefix for the name of all metrics produced by the plug-in. |
PluginType |
Type of the plug-in. Valid option: |
Scope |
Scope of this plug-in. Valid option: |
State |
Specifies if plug-in is active. Valid options: |
The user- defined plug-ins need to be specified in the group_vars as follows:
appformix_user_defined_plugins:
- { plugin_info: 'user_defined_plugins/nginx_connections.json',
plugin_file: 'user_defined_plugins/check_nginx.py'}
The Contrail Insights Ansible playbooks copies these two types
of files to all of the appropriate agents and then configures the
plug-in in the appformix_controller.
Configure a Supported Plug-In
Contrail Insights includes a set of supported plug-ins in the certified_plugins directory of the release bundle.
You can configure a supported plug-in to be installed by setting the appformix_plugins variable in Ansible and running the
installation playbook. For example:
appformix_plugins:
- { plugin_info: 'certified_plugins/contrail_vrouter.json' }
- { plugin_info: 'certified_plugins/cassandra_node_usage.json' }
- { plugin_info: 'certified_plugins/zookeeper_usage.json' }