我可以通过Datadog REST API提取Datadog度量信息吗?

2024-04-25 12:18:41 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法通过API从DataDog中提取特定度量的标记信息

我需要与Metrics Explorer显示的信息(主机和标记列表)相同的信息,仅用于一个度量

我可以检索使用正则表达式模式过滤的标记:

def _load_metrics(from_time, filter_pattern: str):
    regex = re.compile(filter_pattern)
    all_metrics = api.Metric.list(from_time)['metrics']
    filtered = list(filter(regex.search, all_metrics))
    if not len(filtered):
        print('No metrics found with filter {}'.format(args.filter_pattern))
        return None
    print("Found {} metrics matching filter '{}'".format(len(filtered), args.filter_pattern))
    return filtered

我可以从一个度量中得到所有主机:

def get_hosts_from_tag(tag_name: str):
    hosts = api.Hosts.search(q='hosts:', filter='tag={}'.format(tag_name))
    for host in hosts['host_list']:
        print(host['name'])

使用datadogpyDataDog API如何从度量中获取所有标记?

谢谢


Tags: namefrom标记信息formathost度量tag

热门问题