def postToDataDog(self, numOfSitesWithStaleHistory): api.api_key = 'fe1cd13de75c73f4f4de29acd85c4b36' api.application_key = 'd0a1be7f8d3d141c8adda765ceb41f90422cbcda' metricName = 'foobar.staleHistory.numSites' self.logMsg("posting to DataDog: " + metricName + " = " + str(numOfSitesWithStaleHistory)) api.metric(metricName, numOfSitesWithStaleHistory)
def sendDataToDatadog(datadogApiKey, grokServer, grokApiKey, numRecords, metricId): """Get data from Grok and send to Datadog. This gets metric data for the metric matching metricId and converts it into two datasets in the Datadog format: one for the values and one for the anomaly scores. """ # Configure the Datadog library dog_http_api.api_key = datadogApiKey grok = GrokSession(server=grokServer, apikey=grokApiKey) server, metricName = _getMetricServerAndName(grok, metricId) valuesData, anomaliesData = _getMetricData(grok, metricId, numRecords) # Hack to limit number of records for Grok instances prior to version 1.3 # that don't respect the limit parameter when getting metric data. valuesData = valuesData[-numRecords:] anomaliesData = anomaliesData[-numRecords:] print "Sending %i records for metric %s on server %s" % ( len(valuesData), metricName, server) response = dog_http_api.metric(metricName + ".value", valuesData, host=server) if response["status"] != "ok": print "Datadog upload failed with response:\n\n%r" % response response = dog_http_api.metric(metricName + ".anomalyScore", anomaliesData, host=server) if response["status"] != "ok": print "Datadog upload failed with response:\n\n%r" % response
def mailgun_event(): ts = request.form['timestamp'] event_tag = "event_name:" + request.form['event'] api.metric('mailgun.event', (ts, 1), tags=[event_tag], metric_type='counter') return "200"
def sendDataToDatadog(datadogApiKey, YOMPServer, YOMPApiKey, numRecords, metricId): """Get data from YOMP and send to Datadog. This gets metric data for the metric matching metricId and converts it into two datasets in the Datadog format: one for the values and one for the anomaly scores. """ # Configure the Datadog library dog_http_api.api_key = datadogApiKey YOMP = YOMPSession(server=YOMPServer, apikey=YOMPApiKey) server, metricName = _getMetricServerAndName(YOMP, metricId) valuesData, anomaliesData = _getMetricData(YOMP, metricId, numRecords) # Hack to limit number of records for YOMP instances prior to version 1.3 # that don't respect the limit parameter when getting metric data. valuesData = valuesData[-numRecords:] anomaliesData = anomaliesData[-numRecords:] print "Sending %i records for metric %s on server %s" % ( len(valuesData), metricName, server) response = dog_http_api.metric(metricName + ".value", valuesData, host=server) if response["status"] != "ok": print "Datadog upload failed with response:\n\n%r" % response response = dog_http_api.metric(metricName + ".anomalyScore", anomaliesData, host=server) if response["status"] != "ok": print "Datadog upload failed with response:\n\n%r" % response
def postToDataDog(self, num): api.api_key = 'fe1cd13de75c73f4f4de29acd85c4b36' api.application_key = 'd0a1be7f8d3d141c8adda765ceb41f90422cbcda' metricName = 'foobar.liveServiceDown.numStations' self.logMessage("posting to DataDog: " + metricName + " = " + str(num)) api.metric(metricName, num)
def send_to_datadog(host, success): ts = int(time.time()) if success: result = "success" else: result = "failure" metric_name = "example.integration.{}".format(result) api.metric(metric_name, (ts, 1), tags=["host:{}".format(host)]) print ("POSTED to DataDog")
def report_metrics(metrics): """ Send metrics to DataDog. Arguments: metrics (dict): data to publish """ for key, value in metrics.iteritems(): print u"Sending {} ==> {}%".format(key, value) dog_http_api.metric(key, value)
def report_metrics(data, groups): """ Given a `CoverageData` object, send coverage percentages for each group to DataDog. `groups` is a dict mapping aggregate group names to source file patterns. Group names are used in the name of the metric sent to DataDog. """ for group_name, pattern in groups.iteritems(): metric = 'test_eng.coverage.{group}'.format(group=group_name.replace(' ', '_')) percent = data.coverage(pattern) if percent is not None: print u"Sending {} ==> {}%".format(metric, percent) dog_http_api.metric(metric, percent)
def push_to_datadog(qresults, team): ddog_url = "https://app.datadoghq.com/api/" api.api_key = "bc7d8263101c9dce7651f783a829f403" api.application_key = "7d37c0dfe91e953500c1dd5c8d24ae1ab9244a80" # Note timestamp must be ~current per datadog API, so not useful for back porting # or for really even sending ever, therefore we're just going to take the first item in the array # Datadog api requires a float to be passed in for single values and tuple for multi values # FIXME don't just send team-budget and team-actual make it dynamic budget_value = float(qresults[0]['budget']) budget_name = "'team.members.budget." + team.replace(" ", "_") + "." + qresults[0]['team'].replace(" ", "_") + "'" actual_value = float(qresults[0]['actual']) actual_name = "'team.members.actual." + team.replace(" ", "_") + "." + qresults[0]['team'].replace(" ", "_") + "'" ddtags = '"team:%s, subteam:%s' % (team.replace(" ", "_"), qresults[0]['team'].replace(" ", "_")) + '"' response = api.metric(budget_name, budget_value, tags=[ddtags]) #print("api.metric(%s, %s, tags=[%s])" % (budget_name, budget_value, ddtags)) print("Datadog - response - %s" % (response)) response = api.metric(actual_name, actual_value, tags=[ddtags]) #print("api.metric(%s, %s, tags=[%s])" % (actual_name, actual_value, ddtags)) print("Datadog - response - %s" % (response))
def push_to_datadog(json_data): ddog_url = "https://app.datadoghq.com/api/" api.api_key = "bc7d8263101c9dce7651f783a829f403" api.application_key = "7d37c0dfe91e953500c1dd5c8d24ae1ab9244a80" for metric in json_data: # Note timestamp must be ~current per datadog API, so not useful for back porting # or for really even sending ever # Datadog api requires a float/int to be passed in for single values and tuple for multi values metric_name = "'jenkins.custom.stats." + metric + "'" metric_value = json_data[metric][0]['value'] response = api.metric(metric_name, metric_value) #print("api.metric(%s, %s)" % (metric_name, metric_value)) print("DataDog response - %s" % (response))
def push_to_datadog(qresults, proj, team): ddog_url = "https://app.datadoghq.com/api/" api.api_key = "bc7d8263101c9dce7651f783a829f403" api.application_key = "7d37c0dfe91e953500c1dd5c8d24ae1ab9244a80" for metric in qresults: # Note timestamp must be ~current per datadog API, so not useful for back porting # or for really even sending ever # Datadog api requires a float to be passed in for single values and tuple for multi values metric_value = float(qresults[metric]['value']) metric_name = "'mingle." + metric.replace(" ", "_") + '.' + proj.replace(" ", "_") + '.' + team.replace(" ", "_") + "'" ddtags = '"project:%s, team:%s, minglemetric:%s' % (proj.replace(" ", "_"), team.replace(" ", "_"), metric.replace(" ", "_")) + '"' response = api.metric(metric_name, metric_value, tags=[ddtags]) #print("api.metric(%s, %s, tags=[%s])" % (metric_name, metric_value, ddtags)) print("response - %s" % (response))
def recordKeys(keys, keyType='inbox'): details = {} keyTypeLabel = "%sKeys" % keyType details["timestamp"] = str(datetime.datetime.now()) details[keyTypeLabel] = len(keys) keyNames = [] if len(keys) > 0: for key in keys: keyNames.append(key.name) details[keyTypeLabel] = keyNames lastRuns.append(details) if len(lastRuns) > 60: lastRuns.popleft() if options.datadogApiKey != None: api.api_key = options.datadogApiKey api.application_key = options.datadogAppKey api.timeout = 15 api.swallow = False metricName = "cloudops.yumrepomanager.%s.%s" % ( options.yumRepoBucketName.replace('-', '_'), keyTypeLabel) log("Publishing metric to datadog: %s..." % metricName) log(" --> %s" % json.dumps(api.metric(metricName, len(keys))))
from dogapi import dog_http_api as api api.api_key = 'apikey_3' api.application_key = '9d945c35fd7cc7abb1088fd0632ef8e25516af74' # Submit a single point with a timestamp of `now` api.metric('page.views', 1000) # Submit a point with a timestamp (must be ~current) api.metric('my.pair', (1317652676, 15)) # Submit multiple points. api.metric('my.series', [(1317652676, 15), (1317652800, 16)]) # Submit a point with a host and tags. api.metric('my.series', 100, host="myhost.example.com", tags=["version:1"])
import os import time from datetime import datetime as dt from datetime import timedelta as delta import math # import the simple dog client from dogapi import dog_http_api as dog # give dog your credentials (we're using os.environ to let you experiment via environment variables) # in this example we're only reporting data, so we only need an API key # see: https://github.com/DataDog/dogapi/wiki/Authentication for more on API authentication dog.api_key = os.environ.get("DATADOG_API_KEY") # emit points one by one. timestamp is determined at call time. dog.metric('test.api.test_metric', 4.0, host="some_host") time.sleep(1) dog.metric('test.api.test_metric', 5.0, host="another_host") # emit a list of points in one go as a list of (timestamp, value) # here we pretend to send a point a minute for the past hour now = dt.now() points = [] # create the list here (a list comprehension would do too) for i in range(60, 1, -1): t = time.mktime((now - delta(minutes=i)).timetuple()) points.append((t, math.cos(i) + 1.0))