在 Splunk 中将带参数的 url 合并为 1

发布于 2025-01-19 20:00:57 字数 727 浏览 0 评论 0 原文

我正在为我们的服务创建仪表板。我想为URL请求创建指标。 假设有一个类似的URL类似的URL:

/api/v1/users/{userId}/settings

我在Splunk中有关注的查询,

url=*/api/v1/users/*/settings 
| stats avg(timeTaken) as avg_latency, p99(timeTaken) as "p99(ms)", perc75(timeTaken) as "p75(ms)", count  as total_requests, count(eval(responseStatus=500)) as failed_requests by url 
| eval "success_rate"=round((total_requests - failed_requests)/total_requests*100,2) 
| eval avg = round(avg) 
| sort success_rate

我想要的就是有一个带有一个常见URL的桌子,显示了所有指标。但是,相反,我获得了一个带有不同参数的URL列表的表。

I am creating a dashboard for our service. And I want to create metrics for url requests.
Lets say have a similar url like this one:

/api/v1/users/{userId}/settings

And I have following query in Splunk

url=*/api/v1/users/*/settings 
| stats avg(timeTaken) as avg_latency, p99(timeTaken) as "p99(ms)", perc75(timeTaken) as "p75(ms)", count  as total_requests, count(eval(responseStatus=500)) as failed_requests by url 
| eval "success_rate"=round((total_requests - failed_requests)/total_requests*100,2) 
| eval avg = round(avg) 
| sort success_rate

All I want is to have a table with one common url showing all the metrics. But instead, I get a table with a list of all urls with different parameters.
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那些过往 2025-01-26 20:00:57

您要创建一个url的字段,该字段是URL减去用户ID部分,因此统计数据将分组为url。

您可以使用 split(URL,“/”)来做到这一点,以制作URL的MV字段,并根据URL取出两种方式之一。

mvfilter(evar(x!= userId))

或创建了一个新的mvfield,并使用以下方式在mvfield中删除了userId: add/edit/edit/edit/delete/delete mvfield

只要您对所有URL做同样的事情,就可以选择用“ {UserId}”替换用户ID,而不是删除用户ID。

然后,您可以使用 mvjoin(url,“/”)重新加入URL,

希望我能正确理解您的问题,这对您有帮助!

You want to create a field which is the URL minus the UserId part, And therefore the stats will be grouped by which url is called.

You can do this by using split(url,"/") to make a mv field of the url, and take out the UserId by one of two ways depending on the URLs.

Mvfilter: Eg: mvfilter(eval(x!=userId))

Or created a new mvfield with the userId removed by it's index in the mvfield using this: Add/Edit/Delete mvfield

Instead of removing you could also choose to replace the UserId with "{userId}", so long as you do the same for all Urls.

And then you can rejoin the url using mvjoin(url,"/")

I hope I understood your question correctly and this helps you!

枯寂 2025-01-26 20:00:57

您可以尝试使用 eval 在调用 stats 之前:

| eval url=replace(url,"\/\d+\/settings","/settings")

如果结果表明用户 ID 很重要,请在运行之前将其拉入自己的字段replace()

| rex field=url "\/(?<userid>\d+)\/settings"

注释扩展

对于 URL 的多种可能结尾,请尝试如下操作:

index=ndx sourcetype=srctp URL IN("*/api/v1/users/*/settings","*/api/v1/users/*/logout","*/api/v1/users/*/profile")
| rex field=url "\/(?<url_type>\w+)$"
| eval url=replace(url,"\/\d+\/\w+$","")
| stats avg(timeTaken) as avg_latency, p99(timeTaken) as "p99(ms)", perc75(timeTaken) as "p75(ms)", count  as total_requests, count(eval(responseStatus=500)) as failed_requests by url type
| eval "success_rate"=round((total_requests - failed_requests)/total_requests*100,2) 
| eval avg = round(avg) 
| sort success_rate

这会将“类型”(注销、配置文件、设置)提取到新字段中,然后清理 URL删除从 userid 到末尾的所有内容

You could try doing a replace() on your URL field with eval before calling stats:

| eval url=replace(url,"\/\d+\/settings","/settings")

If it turns out the userid is important to hold onto, pull it into its own field prior to running replace():

| rex field=url "\/(?<userid>\d+)\/settings"

expansion for comment

For multiple possible endings of your URL, try something like this:

index=ndx sourcetype=srctp URL IN("*/api/v1/users/*/settings","*/api/v1/users/*/logout","*/api/v1/users/*/profile")
| rex field=url "\/(?<url_type>\w+)
quot;
| eval url=replace(url,"\/\d+\/\w+
quot;,"")
| stats avg(timeTaken) as avg_latency, p99(timeTaken) as "p99(ms)", perc75(timeTaken) as "p75(ms)", count  as total_requests, count(eval(responseStatus=500)) as failed_requests by url type
| eval "success_rate"=round((total_requests - failed_requests)/total_requests*100,2) 
| eval avg = round(avg) 
| sort success_rate

This will extract the "type" (logout, profile, settings) into a new field, then cleanup the URL by removing everything from userid to the end

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文