How to use datadog - 10 common examples

To help you get started, we’ve selected a few datadog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DataDog / Miscellany / update_host_tags_using_metadata_example.py View on Github external
def get_hosts(filter_string):
    host_count = api.Hosts.search(filter=initial_filter_string)['total_matching']
    print('%r hosts matching initial_filter_string' % host_count)
    num_req = host_count // 100 + 1
    print('%r number of api requests to query all matching hosts' % num_req)
    matching_hosts = []
    start_index = 0
    for i in range(1, num_req+1):
        print('api request %r of %r' % (i, num_req))
        host_list = api.Hosts.search(filter=initial_filter_string, sort_field='apps', count=100, start=start_index)['host_list']
        start_index += 100
        for host in host_list:
            matching_hosts.append(host)
    return matching_hosts
github DataDog / Miscellany / update_host_tags_using_metadata_example.py View on Github external
def get_hosts(filter_string):
    host_count = api.Hosts.search(filter=initial_filter_string)['total_matching']
    print('%r hosts matching initial_filter_string' % host_count)
    num_req = host_count // 100 + 1
    print('%r number of api requests to query all matching hosts' % num_req)
    matching_hosts = []
    start_index = 0
    for i in range(1, num_req+1):
        print('api request %r of %r' % (i, num_req))
        host_list = api.Hosts.search(filter=initial_filter_string, sort_field='apps', count=100, start=start_index)['host_list']
        start_index += 100
        for host in host_list:
            matching_hosts.append(host)
    return matching_hosts
github kiwicom / crane / tests / integration / test_hooks_datadog.py View on Github external
def test_create_event(monkeypatch, mocker, repo, commits, event, text):
    old_version = repo.head.commit.hexsha
    for commit in commits:
        repo.index.commit(commit)

    tags = ["releaser:picky@kiwi.com", "project:foo/bar", "environment:a-b/c-d"]

    fake_create = mocker.patch.object(datadog.api.Event, "create")
    fake_deployment = Deployment(repo=repo, new_version="HEAD", old_version=old_version)

    monkeypatch.setattr(uut, "deployment", fake_deployment)

    dd_hook = uut.Hook()
    if event == "success":
        dd_hook.after_upgrade_success()
    elif event == "error":
        dd_hook.after_upgrade_failure()

    fake_create.assert_called_with(
        title="foo/bar deployment", text=text, tags=tags, alert_type=event
    )
github NCI-GDC / gdcdatamodel / zug / datamodel / latest_urls.py View on Github external
def parse_archive_url(archive):
    archive_url = archive['dcc_archive_url']
    archive_ok = True
    if (archive_url.startswith(OPEN_BASE_URL)):
        # open archive
        archive['protected'] = False
    elif (archive_url.startswith(PROTECTED_BASE_URL)):
        # protected archive
        archive['protected'] = True
    else:
        tags = [
            'tcga_latest_urls',
        ]

        statsd.event(
            'TCGA URL not found',
            'URL {} has unexpected prefix'.format(archive["dcc_archive_url"]),
            source_type_name='tcga_archive_check',
            alert_type='warning',
            tags=tags
        )
        logger.warning("url {} has unexpected prefix".format(archive["dcc_archive_url"]))
        archive_ok = False
        #raise RuntimeError("url {} has unexpected prefix".format(archive["dcc_archive_url"]))

    if archive_ok:
        logger.debug('archive_url: %s' % archive_url)
        parts = archive_url.split('/')

        if (parts[8].upper() != archive['disease_code']):
            logger.warning("Unmatched disease code between Archive URL and "
github DataDog / datadogpy / tests / unit / threadstats / test_threadstats.py View on Github external
def test_init(self):
        # Test compress_payload setting
        t = ThreadStats(compress_payload=True)
        t.start()
        assert t.reporter.compress_payload is True
        t.stop()
        # Default value
        t = ThreadStats()
        t.start()
        assert t.reporter.compress_payload is False
        t.stop()
github DataDog / datadogpy / tests / unit / api / helper.py View on Github external
def tearDown(self):
        super(DatadogAPINoInitialization, self).tearDown()
        # Restore default values
        api._api_key = None
        api._application_key = None
        api._api_host = None
        api._host_name = None
        api._proxies = None
github DataDog / datadogpy / tests / unit / api / test_api.py View on Github external
def test_return_raw_response(self):
        # Test default initialization sets return_raw_response to False
        initialize()
        assert not api._return_raw_response
        # Assert that we can set this to True
        initialize(return_raw_response=True)
        assert api._return_raw_response
        # Assert we get multiple fields back when set to True
        initialize(api_key="aaaaaaaaaa", app_key="123456", return_raw_response=True)
        data, raw = api.Monitor.get_all()
github mozilla / testpilot / testpilot / metrics / views.py View on Github external
def handle_metric(metric):
    # will eventually handle multiple types of metrics, including
    # statsd types.
    datadog.api.Event.create(title=metric['title'], text=json.dumps(metric),
                             tags=metric['event-data']['tags'])
github DataDog / datadogpy / tests / unit / api / test_api.py View on Github external
def test_submit_event_wrong_alert_type(self):
        """
        Assess that an event submitted with a wrong alert_type raises the correct Exception
        """
        with pytest.raises(ApiError) as excinfo:
            Event.create(
                title="test no hostname", text="test no hostname", attach_host_name=False, alert_type="wrong_type"
            )
        assert "Parameter alert_type must be either error, warning, info or success" in str(excinfo.value)
github DataDog / datadogpy / tests / unit / api / test_api.py View on Github external
def test_metric_submit_query_switch(self):
        """
        Endpoints are different for submission and queries.
        """
        Metric.send(points=(123, 456))
        self.request_called_with('POST', API_HOST + "/api/v1/series",
                                 data={'series': [{'points': [[123, 456.0]], 'host': api._host_name}]})

        Metric.query(start="val1", end="val2")
        self.request_called_with('GET', API_HOST + "/api/v1/query",
                                 params={'from': "val1", 'to': "val2"})