This blog provides you with steps to add metric widgets for a custom service in Ambari. It assumes that you have a running cluster with the Metrics Collector started and have the working custom service defined in the stack but not installed yet. It will cover the steps to add metric widgets to the service dashboard, collect metrics, push the metrics to the Metrics Collector, and deploy the service having metric widgets on the service dashboard.

In this example, VSFTPD in IOP 4.2 will be used as the custom service and temp_disk_usage as the metric widget. The structure of the Stack definition for the VSFTPD service as follows:

Add metric widgets to the service dashboard

To add metric widgets to a service dashboard, you must have a metrics.json file and a widgets.json file under the service stack path stacks/<stack_name>/<stack_version>/services/<service_name>.

In this example, the service is VSFTPD so the path is stacks/BigInsights/4.2/services/VSFTPD.

1. create metrics.json file for the service and add the metric definitions to it.

There are two types of metrics: ganglia and jmx. The ganglia type implies Metrics Service request will be fulfilled by either Ganglia (up to version 2.0) or Ambari Metrics (2.0 and above) backend service. For metric definition, check out Stack Defined Metrics.

The following example defines the metric temp_disk_usage as Ganglia type for the the component VSFTPD_MASTER of the service VSFTPD. So the metrics service requests will be handled by the Ambari Metrics Service.


metrics.json

2. create widgets.json file for the service dashboard and add the widget definitions with the metrics from metrics.json.

The following example defines the widget Temporary disk metrics for the service VSFTPD Summary page:


widgets.json

Collect the metrics for the service and push the metrics to the Metrics Collector

Once you have the metric widgets defined for the service dashboard, you need to collect the metrics and send them to the Metrics Collector in order to populate the widgets defined for the service dashboard.

1. Collect the metrics for the service
You need to have code to collect the metrics for the service.

In this example, a python script called vsftpd-metrics.py is created in stacks/BigInsights/4.2/services/VSFTPD/package/scripts and the method get_temp_disk_usage can be added to collect the metric temp_disk_usage for the service.

2. Push the metrics to the Metrics Collector
If the metric type is ganglia and Ambari version is 2.0 and above, you need to have code to push the metrics to the Metrics Collector in order to populate the widgets defined for the service dashboard.

In general, the Sink implementations are used. But in case you can not modify the service run-time source code, you can write your own code.

The Sink implementations are responsible for sending metrics to the Metrics Collector. You can writing your own Sink using Guide to writing your own Sink.

In this example, the method submit_metrics is added to the python script vsftpd-metrics.py to push the metrics to the Metrics Collector. The submit_metrics will be run on a thread and periodically send the metrics. The following code shows you the basic logic.

3. Start collecting and pushing the metrics to the Metrics Collector
You also need to have a logic to start collecting and pushing the metrics to the Metrics Collector.

In this example, a method called startMetrics can be added in vsftpd_master.py, the script used to start VSFTPD server. The new startMetrics will setup cron job to run vsftpd-metrics.py to submit the metrics periodically and it will be called at the end of the start function.

4. Stop collecting and pushing the metrics to the Metrics Collector
You also need to have a logic to stop collecting and pushing the metrics to the Metrics Collector.

In this example, a method called stopMetrics can be added in vsftpd_master.py, the script used to stop VSFTPD server. The new stopMetrics will remove the cron job at the beginning of the stop.

Deploy the custom service

If you haven’t installed the custom service yet, run ambari-server restart then install it. But if you already have installed the service, you need to uninstall it first. If you want to have a clean installation, you might need to run ambari-server reset first, then install the cluster and the new service.

In this example, you will see the custom service VSFTPD dashboard as follows:

Summary

This blog showed you how to add metric widgets for a custom service in Ambari. It went through the basic steps of adding metrics widgets for a custom service in BigInsights 4.2 stack.

Sample code pieces can be used as a reference or starting point for adding metric widgets for your custom service on top of IBM Open Platform. It is strongly recommended to use Sink implementations for sending metrics to the Metrics Collector.

Join The Discussion

Your email address will not be published. Required fields are marked *