【问题标题】:create Datadog Graph to show my API endpoint hits per second创建 Datadog Graph 以显示我的 API 端点每秒点击次数
【发布时间】:2024-05-29 18:35:01
【问题描述】:

我有一个包含 10 个端点(合同)的 API。我正在将日志发送到 IIS 以从 API 发送到数据狗。我还在服务器上安装了数据狗代理。

现在我正在尝试为每秒所有端点命中创建图表。将只有一个图表,所有端点 TPS 将显示在图表上。我怎样才能做到这一点?有什么建议吗?

我尝试创建不同的矩阵但无法实现。

我已阅读需要创建解析器文件。

import time
from datetime import datetime
 ...
def my_log_parser(logger, test):
metric_name, date, metric_value, extras = line.split('|')
# Convert the iso8601 date into a unix timestamp, assuming the timestamp
# string is in the same timezone as the machine that's parsing it.
date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S.%f")
tags = extras.split(',')
date = time.mktime(date.timetuple())
metric_attributes = {
    'tags': tags,
    'metric_type': 'gauge',
}
return (metric_name, date, metric_value, metric_attributes)

【问题讨论】:

  • Datadog 几个月前开始提供日志管理。如果您真的要将日志发送到 Datadog(而不仅仅是将它们解析为 Datadog 代理上的指标),为什么不使用日志资源管理器的“分析”视图来获取它呢? docs.datadoghq.com/logs/graph

标签: python datadog


【解决方案1】:

其实你需要做的是创建一个泛型方法。

Create counter is the metric provided by the dataDog. 
val metric:mutable.Map[String, Counter]
def updateCounter(metricName:String, increment:Int, tags:Map[String, String])={
If(metric.isDefinedAt(metricName)){
//update the existing counter in metric map
}else{
//create the counter and update the metric map
}
}

现在,当您到达不同的不同端点时,只需调用 updateCounter 方法即可使用您的路线的特定名称捕获您的指标。

例如,您有像加减法这样的路线 然后使用度量名称 add 和 sub 调用更新计数器方法。

【讨论】: