{"id":129,"date":"2019-03-10T16:17:44","date_gmt":"2019-03-10T15:17:44","guid":{"rendered":"http:\/\/deleforterie.com\/wordpress\/?p=129"},"modified":"2023-01-18T08:53:11","modified_gmt":"2023-01-18T07:53:11","slug":"adding-custom-metrics-in-ambari-metrics","status":"publish","type":"post","link":"https:\/\/deleforterie.com\/wordpress\/index.php\/2019\/03\/10\/adding-custom-metrics-in-ambari-metrics\/","title":{"rendered":"Adding custom metrics in Ambari Metrics"},"content":{"rendered":"\n<p>In this article I will show you how to add custom metrics in the Hortonworks Ambari Metrics for following Zookeeper health with Grafana.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Previously I wrote an article on <a href=\"https:\/\/deleforterie.com\/wordpress\/index.php\/2019\/03\/10\/zookeeper-4-letters-words-admin-commands\/\">how to use the 4lw commands for monitor the Zookeeper health<\/a>.<\/p>\n\n\n\n<p>But following the Zookeeper health is interresting if we could use Grafana to make dashboard and understand better the Zookeeper performance and bottleneck.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ambari Metrics API<\/h2>\n\n\n\n<p>For  create custom metrics in Ambari Metrics, we will use the Collector from <a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/AMBARI\/Metrics\">Ambari Metrics API<\/a> <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">POST http:\/\/&lt;ambari-metrics-collector>:6188\/ws\/v1\/timeline\/metrics<\/pre>\n\n\n\n<p>Instead of using a curl, I have updated my <a href=\"https:\/\/github.com\/EricDele\/BigDataApi\">BigDataApi<\/a> to add an AmbariMetricsApi class for get or put metrics in AMS Collector.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using BigDataApi to send metrics<\/h2>\n\n\n\n<p>I choose to make a <a href=\"https:\/\/github.com\/EricDele\/BigDataApi\/blob\/master\/test_ams.py\">python script<\/a> which could be use to get output of the 4lw command in its stdin and use it to send to AMS collector.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[BigDataApi]> echo mntr | nc localhost 2181 | .\/test_ams.py --type mntr --hostname sandbox-hdp.hortonworks.com\n[BigDataApi]> echo wchc | nc localhost 2181 | cut -d'\/' -f2| egrep -v \"^0x|^$\" | sort | uniq -c | sort -n |.\/test_ams.py --type wchc --hostname sandbox-hdp.hortonworks.com\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Control in AMS-HBase <\/h2>\n\n\n\n<p>You can use phoenix to control that your metrics are in the AMS metadata<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[ams@sandbox-hdp ~]$ export HBASE_CONF_DIR=\/etc\/ambari-metrics-collector\/conf\n[ams@sandbox-hdp ~]$ \/usr\/hdp\/current\/phoenix-client\/bin\/sqlline.py sandbox-hdp.hortonworks.com:61181:\/ams-hbase-unsecure\n<\/pre>\n\n\n\n<p>If you are on a kerberized cluster use \/ams-hbase-secure<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[ams@sandbox-hdp ~]$ export HBASE_CONF_DIR=\/etc\/ambari-metrics-collector\/conf\n[ams@sandbox-hdp ~]$ \/usr\/hdp\/current\/phoenix-client\/bin\/sqlline.py sandbox-hdp.hortonworks.com:61181:\/ams-hbase-secure\n<\/pre>\n\n\n\n<p>If your Ambari Metrics  is not embedded but distributed, use the zookeeper port 2181<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[ams@sandbox-hdp ~]$ export HBASE_CONF_DIR=\/etc\/ambari-metrics-collector\/conf\n[ams@sandbox-hdp ~]$ \/usr\/hdp\/current\/phoenix-client\/bin\/sqlline.py sandbox-hdp.hortonworks.com:2181:\/ams-hbase-secure\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Check Metadata<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">0: jdbc:phoenix:sandbox-hdp.hortonworks.com:6> !tables\n+------------+--------------+--------------------------+---------------+\n| TABLE_CAT  | TABLE_SCHEM  |        TABLE_NAME        |  TABLE_TYPE   |\n+------------+--------------+--------------------------+---------------+\n|            | SYSTEM       | CATALOG                  | SYSTEM TABLE  |\n|            | SYSTEM       | FUNCTION                 | SYSTEM TABLE  |\n|            | SYSTEM       | SEQUENCE                 | SYSTEM TABLE  |\n|            | SYSTEM       | STATS                    | SYSTEM TABLE  |\n|            |              | CONTAINER_METRICS        | TABLE         |\n|            |              | HOSTED_APPS_METADATA     | TABLE         |\n|            |              | INSTANCE_HOST_METADATA   | TABLE         |\n|            |              | METRICS_METADATA         | TABLE         |\n|            |              | METRIC_AGGREGATE         | TABLE         |\n|            |              | METRIC_AGGREGATE_DAILY   | TABLE         |\n|            |              | METRIC_AGGREGATE_HOURLY  | TABLE         |\n|            |              | METRIC_AGGREGATE_MINUTE  | TABLE         |\n|            |              | METRIC_RECORD            | TABLE         |\n|            |              | METRIC_RECORD_DAILY      | TABLE         |\n|            |              | METRIC_RECORD_HOURLY     | TABLE         |\n|            |              | METRIC_RECORD_MINUTE     | TABLE         |\n+------------+--------------+--------------------------+---------------+\n0: jdbc:phoenix:sandbox-hdp.hortonworks.com:6> select METRIC_NAME,APP_ID,START_TIME,SUPPORTS_AGGREGATION from METRICS_METADATA where APP_ID='zookeeper';\n+-------------------------------------------+------------+----------------+-----------------------+\n|                METRIC_NAME                |   APP_ID   |   START_TIME   | SUPPORTS_AGGREGATION  |\n+-------------------------------------------+------------+----------------+-----------------------+\n| zookeeper.zk_approximate_data_size        | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_avg_latency                  | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_ephemerals_count             | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_max_file_descriptor_count    | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_max_latency                  | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_min_latency                  | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_num_alive_connections        | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_open_file_descriptor_count   | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_outstanding_requests         | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_packets_received             | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_packets_sent                 | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_path.ambari-metrics-cluster  | zookeeper  | 1552227826949  | true                  |\n| zookeeper.zk_path.hiveserver2             | zookeeper  | 1552227826949  | true                  |\n| zookeeper.zk_pathambari-metrics-cluster   | zookeeper  | 1552227577993  | true                  |\n| zookeeper.zk_pathhiveserver2              | zookeeper  | 1552227577993  | true                  |\n| zookeeper.zk_watch_count                  | zookeeper  | 1552221892508  | true                  |\n| zookeeper.zk_znode_count                  | zookeeper  | 1552221892508  | true                  |\n+-------------------------------------------+------------+----------------+-----------------------+\n15 rows selected (0.185 seconds)\n0: jdbc:phoenix:sandbox-hdp.hortonworks.com:6>  select METRIC_NAME,APP_ID,SERVER_TIME,METRIC_MAX from METRIC_AGGREGATE where METRIC_NAME='zookeeper.zk_packets_sent' order by SERVER_TIME;\n+----------------------------+------------+----------------+-------------+\n|        METRIC_NAME         |   APP_ID   |  SERVER_TIME   | METRIC_MAX  |\n+----------------------------+------------+----------------+-------------+\n| zookeeper.zk_packets_sent  | zookeeper  | 1552221780000  | 47645.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552221810000  | 47645.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552221840000  | 47645.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552221870000  | 47645.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552221900000  | 47645.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552221930000  | 47645.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552221960000  | 47645.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552221990000  | 47645.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222260000  | 50858.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222290000  | 50858.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222320000  | 50858.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222350000  | 50858.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222380000  | 50858.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222410000  | 50858.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222440000  | 50858.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222470000  | 50858.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222620000  | 51991.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222650000  | 51991.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222680000  | 51991.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552222710000  | 51991.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552223820000  | 56439.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552223850000  | 56439.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552223880000  | 56439.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552223910000  | 56439.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552223940000  | 56439.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552223970000  | 56439.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552224000000  | 56439.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552224030000  | 56439.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552227780000  | 11388.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552227810000  | 11388.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552227840000  | 11388.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552227870000  | 11388.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552227900000  | 11388.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552227930000  | 11388.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552227960000  | 11388.0     |\n| zookeeper.zk_packets_sent  | zookeeper  | 1552227990000  | 11388.0     |\n+----------------------------+------------+----------------+-------------+\n36 rows selected (0.075 seconds)\n\n<\/pre>\n\n\n\n<p>As you can see we have metrics in the AMS Hbase.<\/p>\n\n\n\n<p>There is a trap with AMS Collector, if the metrics are older than 2 minutes (default value) they will not be insert in the <strong>METRIC_RECORD<\/strong> table but they will be in the <strong>METRICS_METADATA<\/strong> table. <\/p>\n\n\n\n<p>The impact in Grafana is the possibility to see the component and the metric name but never see any point \/ graph.<\/p>\n\n\n\n<p>So if you want to load some metrics older than the default window, add in custom ams-site this parameter to allow metrics old up to a day.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"ini\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">timeline.metrics.service.outofband.time.allowance.millis=86400000<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Zookeeper Dashboard in Grafana<\/h2>\n\n\n\n<p>Connect to Grafana via Ambari (Ambari Metrics-&gt;Quick Links) and connect with an account that have permission to create a Dashboard.<\/p>\n\n\n\n<p>In the combo Dashboard select +New and in the green row, add panel, select graph<\/p>\n\n\n\n<p>You will be able to select in the component name zookeeper and then in the metric name one of the zookeeper metric<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-1-1024x411.png\" alt=\"\" class=\"wp-image-145\" width=\"1193\" height=\"478\" srcset=\"https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-1-1024x411.png 1024w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-1-300x120.png 300w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-1-768x308.png 768w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-1.png 1084w\" sizes=\"auto, (max-width: 1193px) 100vw, 1193px\" \/><\/figure>\n\n\n\n<p>You have now the possibility to create very interesting dashboard for filling the lack of Zookeeper metrics on the Hortonworks distribution.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-1024x487.png\" alt=\"\" class=\"wp-image-143\" width=\"1192\" height=\"566\" srcset=\"https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-1024x487.png 1024w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-300x143.png 300w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/image-768x365.png 768w\" sizes=\"auto, (max-width: 1192px) 100vw, 1192px\" \/><\/figure>\n\n\n\n<p>The more important metrics are the <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Outstanding requests<\/li><li>Latency<\/li><li>Alive connections<\/li><li>Followers<\/li><li>Watch count<\/li><li>ZK Paths<\/li><\/ul>\n\n\n\n<p>Feel free to feedback to me all your comments on this article that I hope will help you in your Zookeeper supervision duty<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong>Update 2020\/06\/19<\/strong><\/span><\/p>\n<p>I have added a new metrics during the Covid-19 confinement as the network have some trouble with the bandwidth.<\/p>\n<p>So using the same api with the <a href=\"https:\/\/www.speedtest.net\/apps\/cli\">speedtest client<\/a> to have some graph of the availability of my network connection.<\/p>\n<p>Adding this simple piece of code in my crontab for generating some stats every 5 minutes and send the result to the ambari-metrics api<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Shellscript\">*\/5 * * * * echo \"YES\\n\" |speedtest --progress=no| (cd \/Developpement\/Python\/BigDataApi &amp;&amp; .\/test_ams.py --type speedtest --hostname sandbox-hdp.hortonworks.com)\n<\/pre>\n<p>With Grafana I have made a dashboard to show the network bandwidth availability and sent it to the support (seems they don&#8217;t have tools like that \ud83d\ude42 ).<\/p>\n<p><a href=\"https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/Nordnet-bandwith-2020-03-20-22-11-10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-193 size-large\" src=\"https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/Nordnet-bandwith-2020-03-20-22-11-10-1024x434.png\" alt=\"\" width=\"1024\" height=\"434\" srcset=\"https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/Nordnet-bandwith-2020-03-20-22-11-10-1024x434.png 1024w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/Nordnet-bandwith-2020-03-20-22-11-10-300x127.png 300w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/Nordnet-bandwith-2020-03-20-22-11-10-768x326.png 768w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/Nordnet-bandwith-2020-03-20-22-11-10-1536x651.png 1536w, https:\/\/deleforterie.com\/wordpress\/wp-content\/uploads\/2019\/03\/Nordnet-bandwith-2020-03-20-22-11-10-2048x869.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article I will show you how to add custom metrics in the Hortonworks Ambari Metrics for following Zookeeper health with Grafana.<\/p>\n","protected":false},"author":2,"featured_media":150,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[22,23,4,21,15,5,7,24],"tags":[],"class_list":["post-129","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ambari","category-ambari-metrics","category-bigdata","category-hbase","category-hortonworks","category-linux","category-python","category-zookeeper"],"_links":{"self":[{"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":20,"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"predecessor-version":[{"id":195,"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/129\/revisions\/195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media\/150"}],"wp:attachment":[{"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/deleforterie.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}