diff --git a/README.md b/README.md index 72626d5..f6a1a2e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # ICAPI-DataDog Provides a simple integration script to push data from the Instaclustr Monitoring REST API to DataDog. -For detailed instructions on how to set up see: https://support.instaclustr.com/hc/en-us/articles/215566468 +For detailed instructions on how to set up see: https://www.instaclustr.com/support/api-integrations/integrations/using-the-instaclustr-monitoring-api-with-data-dog/ + + +Please see https://www.instaclustr.com/support/documentation/announcements/instaclustr-open-source-project-status/ for Instaclustr support status of this project diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..d89d520 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,7 @@ +2020 Sep 10 Miranda Zhang + + ic2datadog.py: + Skip metrics with empty value. + Make print compatible in both python 2 & 3. + README.md: + Updated link to setup instructions. diff --git a/configuration.json b/configuration.json index ee30975..e5f75d7 100644 --- a/configuration.json +++ b/configuration.json @@ -1,6 +1,6 @@ { - "cluster_id":"[instaclustr cluster id]", - "metrics_list":"n::cpuutilization,n::cassandraReads,n::cassandraWrites,n::nodeStatus", + "cluster_id":"instaclustr-cluster-id", + "metrics_list":"n::cpuutilization,n::reads,n::writes", "dd_options": { "api_key":"[datadog API key]", @@ -8,7 +8,8 @@ }, "ic_options": { - "user_name":"[instaclustr user name]", - "api_key":"[instaclustr password]" - } -} \ No newline at end of file + "user_name":"instaclustr-user-name", + "api_key":"instaclustr-password" + }, + "tags":["tag_name:tag_value"] +} diff --git a/ic2datadog.py b/ic2datadog.py old mode 100644 new mode 100755 index 103cef9..703e864 --- a/ic2datadog.py +++ b/ic2datadog.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python __author__ = 'ben.slater@instaclustr.com' from datadog import initialize @@ -5,8 +6,9 @@ from datadog import statsd import requests, json from requests.auth import HTTPBasicAuth +import os -configFile = "configuration.json" +configFile = os.path.dirname(os.path.realpath(__file__)) + "/configuration.json" f = open(configFile) configuration = json.loads(f.read()) f.close() @@ -26,7 +28,7 @@ if not response.ok: # got an error response from the Instaclustr API - raise an alert in DataDog after 3 consecutive fails consecutive_fails += 1 - print "Error retrieving metrics from Instaclustr API: {0} - {1}".format(response.status_code, response.content) + print("Error retrieving metrics from Instaclustr API: {0} - {1}".format(response.status_code, response.content)) if consecutive_fails > 3: statsd.event("Instaclustr monitoring API error", "Error code is: {0}".format(response.status_code)) sleep(20) @@ -36,20 +38,43 @@ metrics = json.loads(response.content) for node in metrics: public_ip = node["publicIp"] - for metric in node["payload"]: - dd_metric_name = 'instaclustr.{0}.{1}'.format(public_ip,metric["metric"]) - if metric["metric"] == "nodeStatus": - # node status metric maps to a data dog service check - if metric["values"][0]["value"] =="WARN": - statsd.service_check(dd_metric_name, 1) # WARN status + private_ip = node["privateIp"] + rack_name = node["rack"]["name"] + data_centre_custom_name = node["rack"]["dataCentre"]["customDCName"] + data_centre_name = node["rack"]["dataCentre"]["name"] + data_centre_provider = node["rack"]["dataCentre"]["provider"] + provider_account_name = node["rack"]["providerAccount"]["name"] + provider_account_provider = node["rack"]["providerAccount"]["provider"] - else: - statsd.service_check(dd_metric_name, 0) # OK status + tag_list = ['ic_public_ip:' + public_ip, + 'ic_private_ip:' + private_ip, + 'ic_rack_name:' + rack_name, + 'ic_data_centre_custom_name:' + data_centre_custom_name, + 'ic_data_centre_name:' + data_centre_name, + 'ic_data_centre_provider:' + data_centre_provider, + 'ic_provider_account_name:' + provider_account_name, + 'ic_provider_account_provider:' + provider_account_provider + ] + if data_centre_provider == 'AWS_VPC': + tag_list = tag_list + [ + 'region:' + node["rack"]["dataCentre"]["name"].lower().replace("_", "-"), + 'availability_zone:' + node["rack"]["name"] + ] + for metric in node["payload"]: + dd_metric_name = 'instaclustr.{0}'.format(metric["metric"]) + if len(metric["values"]) > 0: + if metric["metric"] == "nodeStatus": + # node status metric maps to a data dog service check + if metric["values"][0]["value"] =="WARN": + statsd.service_check(dd_metric_name, 1, tags=configuration['tags'] + tag_list) # WARN status + else: + statsd.service_check(dd_metric_name, 0, tags=configuration['tags'] + tag_list) # OK status + else: + # all other metrics map to a data dog guage + statsd.gauge(dd_metric_name, metric["values"][0]["value"], tags=configuration['tags'] + tag_list) else: - # all other metrics map to a data dog guage - statsd.gauge(dd_metric_name, metric["values"][0]["value"]) - + print("Metric {0} of type '{1}' returned no value.".format(dd_metric_name,metric["type"])) sleep(20)