{"id":75,"date":"2019-08-25T07:56:18","date_gmt":"2019-08-25T00:56:18","guid":{"rendered":"http:\/\/geeksops.com\/?p=75"},"modified":"2019-10-02T08:17:34","modified_gmt":"2019-10-02T01:17:34","slug":"how-to-monitoring-client-connected-aruba-with-prometheus-grafana","status":"publish","type":"post","link":"https:\/\/rotreein.com\/?p=75","title":{"rendered":"Monitoring Client Connected in Aruba with Prometheus and Grafana"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"566\" src=\"https:\/\/geeksops.com\/wp-content\/uploads\/2019\/08\/Untitled-Diagram.jpg\" alt=\"\" class=\"wp-image-105\" srcset=\"https:\/\/rotreein.com\/wp-content\/uploads\/2019\/08\/Untitled-Diagram.jpg 630w, https:\/\/rotreein.com\/wp-content\/uploads\/2019\/08\/Untitled-Diagram-300x270.jpg 300w\" sizes=\"(max-width: 630px) 100vw, 630px\" \/><\/figure>\n\n\n\n<p><br>This scenario which the environment using mode IAP. please install requirement below<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">apt-get install python python-pip nginx git -y<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">pip-install netmiko prometheus_client<\/p>\n\n\n\n<p>Then create a python script to collect data client per AP as IAP Collector, for example the script name &#8220;collect_iap.py&#8221; then copy the script below<\/p>\n\n\n\n<pre data-mode=\"python\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" class=\"wp-block-simple-code-block-ace\">#!\/usr\/bin\/env python\nfrom netmiko import ConnectHandler\nfrom netmiko.ssh_exception import NetMikoTimeoutException\nfrom netmiko.ssh_exception import AuthenticationException\nfrom paramiko.ssh_exception import SSHException\nimport json,time,os\n\nwith open('devices_iap') as f:\n    devices_list = f.read().splitlines()\n\nfor a_device in devices_list:\n    hostname = a_device\n    aos_device = {\n        'device_type': 'aruba_os',\n        'ip': hostname,\n        'username': 'your_username',\n        'password': 'your_password'\n    }\n    # if one of devices down, the script will running next job\n    try:\n        net_connect= ConnectHandler(**aos_device)\n    except (AuthenticationException):\n        print 'auth failure ' + hostname\n        continue\n    except (NetMikoTimeoutException):\n        print 'IP Timeout ' + hostname\n        continue\n    except (EOFError):\n        print 'End of file while attempting device ' + hostname\n        continue\n    except (SSHException):\n        print 'SSH not enble ' + hostname\n        continue\n    except Exception as unknown_error:\n        print 'unknown error ' + str(unknown_error)\n        continue\n    net_connect = ConnectHandler(**aos_device)\n    excecute_command = net_connect.send_command(\"show ap association | in Num\")\n    parse_command = excecute_command[12:16]\n    result = \"{} \".format(aos_device['ip']) +  parse_command + \"\\n\"\n    print result\n    output_file = open(\"output.txt\", \"a\")\n    output_file.write(result)\n    output_file.close()\nprint \"Convert to JSON File\"\ncommands = {}\nwith open(\"output.txt\") as fh:\n    for line in fh:\n        command, description = line.strip().split(' ', 1)\n        commands[command] = description.strip()\nprint(json.dumps(commands, indent=2, sort_keys=True))\n\nwith open('\/var\/www\/html\/aruba_iap.json', 'w') as json_file:\n    json.dump(commands, json_file)\ntime.sleep(20)\nremove_file = os.system(\"rm -rf output.txt\")\nprint \"Done\"<\/pre>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">root@vm-prom-collector:\/home\/aruba_os# chmod +x collect_iap.py<\/p>\n\n\n\n<p>Define list of devices in \/etc\/hosts<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">192.168.232.2 IAP325_02<br>192.168.232.3 IAP325_03<br>192.168.232.4 IAP325_04<br>192.168.232.5 IAP325_05<\/p>\n\n\n\n<p>Make sure the script is running properly<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">root@vm-prom-collector:\/home\/aruba_os# python collect_iap.py<br>Collecting data\u2026..<br>Convert to JSON File<br> {<br>  &#8220;IAP325_03&#8221;: &#8220;2&#8221;, <br>  &#8220;IAP325_03&#8221;: &#8220;6&#8221;, <br>  &#8220;IAP325_04&#8221;: &#8220;0&#8221;, <br>  &#8220;IAP325_05&#8221;: &#8220;4&#8221;, <br> }<br> Done<\/p>\n\n\n\n<p>Create JSON exporter, Actually the script already created by other. Please clone the script from repository<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">root@vm-prom-collector:\/home\/rohmat\/aruba_os# git clone https:\/\/github.com\/project-sunbird\/prometheus-jsonpath-exporter.git<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">root@vm-prom-collector:\/home\/rohmat\/aruba_os# cd prometheus-jsonpath-exporter\/<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">root@vm-prom-collector:\/home\/rohmat\/aruba_os\/prometheus-jsonpath-exporter# nano example\/config_aruba.yml<\/p>\n\n\n\n<p><br>Copy the script below in \/home\/rohmat\/aruba_os\/prometheus-jsonpath-exporter\/example\/config_aruba.yml<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">exporter_port: 9158 \n log_level: info\n json_data_url: http:\/\/192.168.38.60\/aruba_os.json \n metric_name_prefix: aruba\n metrics:\n - name: CAP325_02\n   description: Aruba test\n   path: $.CAP325_02\n - name: CAP325_02\n   description: Aruba test\n   path: $.CAP325_02\n - name: CAP325_03\n   description: Aruba test\n   path: $.CAP325_03\n - name: CAP325_04\n   description: Aruba test\n   path: $.AP325_04 <\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Create linux service in folder \/lib\/systemd\/system, so it can auto start after rebooted<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">root@vm-prom-collector:\/home\/rohmat\/aruba_os#nano \/lib\/systemd\/sysem\/aruba_exporter.service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Unit]\nDescription=service exporter iap aruba\nAfter=multi-user.target\n[Service]\nType=idle\nExecStart=\/usr\/bin\/python \/opt\/prometheus-jsonpath-exporter\/app\/exporter.py \/opt\/prometheus-jsonpath-exporter\/example\/config_aruba.yml\n[Install]\nWantedBy=multi-user.target<\/pre>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">root@vm-prom-collector:\/home\/rohmat\/aruba_os# systemctl daemon-reload<\/p>\n\n\n\n<p class=\"has-background has-small-font-size has-very-light-gray-background-color\">root@vm-prom-collector:\/home\/rohmat\/aruba_os# system restart aruba_exporter.service<\/p>\n\n\n\n<p>Setup Prometheus &amp; Grafana. I assumse this scenario already setup prometheus server, if you have no environment please follow this step : Prometheus :<a href=\"https:\/\/www.booleanworld.com\/install-use-prometheus-monitoring\/\"> https:\/\/www.booleanworld.com\/install-use-prometheus-monitoring\/<\/a><br>Grafana : <a href=\"https:\/\/grafana.com\/docs\/installation\/debian\/\">https:\/\/grafana.com\/docs\/installation\/debian\/<\/a><\/p>\n\n\n\n<p>Configure prometheus server to srap data from json exporter, this scenario prometheus server &amp; json exporter in the same server. please add configuration  file in \/etc\/prometheus\/prometheus.yml<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">job_name: 'aruba_os_iap' \nscrape_interval: 30s \nstatic_configs: \n  - targets: ['localhost:9158'] \n<\/pre>\n\n\n\n<p>Restart the service prometheus, &#8220;systemctl restart prometheus&#8221;<\/p>\n\n\n\n<p><br>Create metrics in Grafana<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"445\" src=\"https:\/\/geeksops.com\/wp-content\/uploads\/2019\/09\/image-17-1024x445.png\" alt=\"\" class=\"wp-image-421\" srcset=\"https:\/\/rotreein.com\/wp-content\/uploads\/2019\/09\/image-17-1024x445.png 1024w, https:\/\/rotreein.com\/wp-content\/uploads\/2019\/09\/image-17-300x130.png 300w, https:\/\/rotreein.com\/wp-content\/uploads\/2019\/09\/image-17-768x334.png 768w, https:\/\/rotreein.com\/wp-content\/uploads\/2019\/09\/image-17.png 1112w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption><br><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"470\" src=\"https:\/\/geeksops.com\/wp-content\/uploads\/2019\/08\/image-14-1024x470.png\" alt=\"\" class=\"wp-image-215\" srcset=\"https:\/\/rotreein.com\/wp-content\/uploads\/2019\/08\/image-14-1024x470.png 1024w, https:\/\/rotreein.com\/wp-content\/uploads\/2019\/08\/image-14-300x138.png 300w, https:\/\/rotreein.com\/wp-content\/uploads\/2019\/08\/image-14-768x353.png 768w, https:\/\/rotreein.com\/wp-content\/uploads\/2019\/08\/image-14.png 1799w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption><br><br><\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This scenario which the environment using mode IAP. please install requirement below apt-get install python python-pip nginx git -y pip-install netmiko prometheus_client Then create a python script to collect data client per AP as IAP Collector, for example the script name &#8220;collect_iap.py&#8221; then copy the script below root@vm-prom-collector:\/home\/aruba_os# chmod +x collect_iap.py Define list of devices&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[],"_links":{"self":[{"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/posts\/75"}],"collection":[{"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rotreein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=75"}],"version-history":[{"count":62,"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":430,"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions\/430"}],"wp:attachment":[{"href":"https:\/\/rotreein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rotreein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rotreein.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}