Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Upstream update #4

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
2020 Sep 10 Miranda Zhang <[email protected]>

ic2datadog.py:
Skip metrics with empty value.
Make print compatible in both python 2 & 3.
README.md:
Updated link to setup instructions.
13 changes: 7 additions & 6 deletions configuration.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"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]",
"app_key":"[datadog app key]"
},
"ic_options":
{
"user_name":"[instaclustr user name]",
"api_key":"[instaclustr password]"
}
}
"user_name":"instaclustr-user-name",
"api_key":"instaclustr-password"
},
"tags":["tag_name:tag_value"]
}
51 changes: 38 additions & 13 deletions ic2datadog.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python
__author__ = '[email protected]'

from datadog import initialize
from time import sleep
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()
Expand All @@ -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)
Expand All @@ -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)