Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
5907817c
N
nightingale
项目概览
DiDi
/
nightingale
10 个月 前同步成功
通知
46
Star
7053
Fork
1161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5907817c
编写于
7月 07, 2022
作者:
U
Ulric Qin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
n9e-server: add http request stat
上级
aa97ac54
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
5 deletion
+31
-5
src/server/router/router.go
src/server/router/router.go
+21
-5
src/server/stat/stat.go
src/server/stat/stat.go
+10
-0
未找到文件。
src/server/router/router.go
浏览文件 @
5907817c
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"time"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
...
...
@@ -13,6 +14,8 @@ import (
"github.com/didi/nightingale/v5/src/pkg/aop"
"github.com/didi/nightingale/v5/src/server/config"
"github.com/didi/nightingale/v5/src/server/naming"
promstat
"github.com/didi/nightingale/v5/src/server/stat"
)
func
New
(
version
string
)
*
gin
.
Engine
{
...
...
@@ -66,7 +69,7 @@ func configRoute(r *gin.Engine, version string) {
})
// use apiKey not basic auth
r
.
POST
(
"/datadog/api/v1/series"
,
datadogSeries
)
r
.
POST
(
"/datadog/api/v1/series"
,
stat
(),
datadogSeries
)
r
.
POST
(
"/datadog/api/v1/check_run"
,
datadogCheckRun
)
r
.
GET
(
"/datadog/api/v1/validate"
,
datadogValidate
)
r
.
POST
(
"/datadog/api/v1/metadata"
,
datadogMetadata
)
...
...
@@ -77,10 +80,10 @@ func configRoute(r *gin.Engine, version string) {
r
.
Use
(
auth
)
}
r
.
POST
(
"/opentsdb/put"
,
handleOpenTSDB
)
r
.
POST
(
"/openfalcon/push"
,
falconPush
)
r
.
POST
(
"/prometheus/v1/write"
,
remoteWrite
)
r
.
POST
(
"/prometheus/v1/query"
,
queryPromql
)
r
.
POST
(
"/opentsdb/put"
,
stat
(),
handleOpenTSDB
)
r
.
POST
(
"/openfalcon/push"
,
stat
(),
falconPush
)
r
.
POST
(
"/prometheus/v1/write"
,
stat
(),
remoteWrite
)
r
.
POST
(
"/prometheus/v1/query"
,
stat
(),
queryPromql
)
r
.
GET
(
"/memory/alert-rule"
,
alertRuleGet
)
r
.
GET
(
"/memory/idents"
,
identsGets
)
...
...
@@ -95,3 +98,16 @@ func configRoute(r *gin.Engine, version string) {
service
:=
r
.
Group
(
"/v1/n9e"
)
service
.
POST
(
"/event"
,
pushEventToQueue
)
}
func
stat
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
start
:=
time
.
Now
()
c
.
Next
()
code
:=
fmt
.
Sprintf
(
"%d"
,
c
.
Writer
.
Status
())
method
:=
c
.
Request
.
Method
labels
:=
[]
string
{
"n9e-server"
,
code
,
c
.
FullPath
(),
method
}
promstat
.
RequestDuration
.
WithLabelValues
(
labels
...
)
.
Observe
(
float64
(
time
.
Since
(
start
)
.
Seconds
()))
}
}
src/server/stat/stat.go
浏览文件 @
5907817c
...
...
@@ -57,6 +57,15 @@ var (
Name
:
"sample_queue_size"
,
Help
:
"The size of sample queue."
,
},
[]
string
{
"cluster"
,
"channel_number"
})
// 一些重要的请求,比如接收数据的请求,应该统计一下延迟情况
RequestDuration
=
prometheus
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Buckets
:
[]
float64
{
.01
,
.1
,
1
},
Name
:
"http_request_duration_seconds"
,
Help
:
"HTTP request latencies in seconds."
,
},
[]
string
{
"service"
,
"code"
,
"path"
,
"method"
},
)
)
func
Init
()
{
...
...
@@ -68,5 +77,6 @@ func Init() {
CounterAlertsTotal
,
GaugeAlertQueueSize
,
GaugeSampleQueueSize
,
RequestDuration
,
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录