Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
2bea8b7c
N
nightingale
项目概览
DiDi
/
nightingale
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
2bea8b7c
编写于
5月 17, 2022
作者:
U
Ulric Qin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add usage report
上级
dd5ae29f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
132 addition
and
24 deletion
+132
-24
src/server/common/conv/conv.go
src/server/common/conv/conv.go
+1
-1
src/server/config/config.go
src/server/config/config.go
+20
-19
src/server/engine/worker.go
src/server/engine/worker.go
+3
-2
src/server/router/router_prom.go
src/server/router/router_prom.go
+2
-2
src/server/server.go
src/server/server.go
+5
-0
src/server/usage/usage.go
src/server/usage/usage.go
+101
-0
未找到文件。
src/server/
engine/vector
.go
→
src/server/
common/conv/conv
.go
浏览文件 @
2bea8b7c
package
engine
package
conv
import
(
"math"
...
...
src/server/config/config.go
浏览文件 @
2bea8b7c
...
...
@@ -119,25 +119,26 @@ func MustLoad(fpaths ...string) {
}
type
Config
struct
{
RunMode
string
ClusterName
string
BusiGroupLabelKey
string
EngineDelay
int64
Log
logx
.
Config
HTTP
httpx
.
Config
BasicAuth
gin
.
Accounts
SMTP
SMTPConfig
Heartbeat
HeartbeatConfig
Alerting
Alerting
NoData
NoData
Redis
storage
.
RedisConfig
Gorm
storage
.
Gorm
MySQL
storage
.
MySQL
Postgres
storage
.
Postgres
WriterOpt
writer
.
GlobalOpt
Writers
[]
writer
.
Options
Reader
reader
.
Options
Ibex
Ibex
RunMode
string
ClusterName
string
BusiGroupLabelKey
string
EngineDelay
int64
DisableUsageReport
bool
Log
logx
.
Config
HTTP
httpx
.
Config
BasicAuth
gin
.
Accounts
SMTP
SMTPConfig
Heartbeat
HeartbeatConfig
Alerting
Alerting
NoData
NoData
Redis
storage
.
RedisConfig
Gorm
storage
.
Gorm
MySQL
storage
.
MySQL
Postgres
storage
.
Postgres
WriterOpt
writer
.
GlobalOpt
Writers
[]
writer
.
Options
Reader
reader
.
Options
Ibex
Ibex
}
type
HeartbeatConfig
struct
{
...
...
src/server/engine/worker.go
浏览文件 @
2bea8b7c
...
...
@@ -11,6 +11,7 @@ import (
"github.com/toolkits/pkg/str"
"github.com/didi/nightingale/v5/src/models"
"github.com/didi/nightingale/v5/src/server/common/conv"
"github.com/didi/nightingale/v5/src/server/config"
"github.com/didi/nightingale/v5/src/server/memsto"
"github.com/didi/nightingale/v5/src/server/naming"
...
...
@@ -106,7 +107,7 @@ func (r RuleEval) Work() {
return
}
r
.
judge
(
ConvertVectors
(
value
))
r
.
judge
(
conv
.
ConvertVectors
(
value
))
}
type
WorkersType
struct
{
...
...
@@ -172,7 +173,7 @@ func (ws *WorkersType) Build(rids []int64) {
}
}
func
(
r
RuleEval
)
judge
(
vectors
[]
Vector
)
{
func
(
r
RuleEval
)
judge
(
vectors
[]
conv
.
Vector
)
{
// 有可能rule的一些配置已经发生变化,比如告警接收人、callbacks等
// 这些信息的修改是不会引起worker restart的,但是确实会影响告警处理逻辑
// 所以,这里直接从memsto.AlertRuleCache中获取并覆盖
...
...
src/server/router/router_prom.go
浏览文件 @
2bea8b7c
...
...
@@ -13,8 +13,8 @@ import (
"github.com/toolkits/pkg/ginx"
"github.com/didi/nightingale/v5/src/server/common"
"github.com/didi/nightingale/v5/src/server/common/conv"
"github.com/didi/nightingale/v5/src/server/config"
"github.com/didi/nightingale/v5/src/server/engine"
"github.com/didi/nightingale/v5/src/server/idents"
"github.com/didi/nightingale/v5/src/server/memsto"
"github.com/didi/nightingale/v5/src/server/reader"
...
...
@@ -41,7 +41,7 @@ func queryPromql(c *gin.Context) {
return
}
c
.
JSON
(
200
,
engine
.
ConvertVectors
(
value
))
c
.
JSON
(
200
,
conv
.
ConvertVectors
(
value
))
}
func
remoteWrite
(
c
*
gin
.
Context
)
{
...
...
src/server/server.go
浏览文件 @
2bea8b7c
...
...
@@ -20,6 +20,7 @@ import (
"github.com/didi/nightingale/v5/src/server/reader"
"github.com/didi/nightingale/v5/src/server/router"
"github.com/didi/nightingale/v5/src/server/stat"
"github.com/didi/nightingale/v5/src/server/usage"
"github.com/didi/nightingale/v5/src/server/writer"
"github.com/didi/nightingale/v5/src/storage"
)
...
...
@@ -153,6 +154,10 @@ func (s Server) initialize() (func(), error) {
// register ident and nodata logic
idents
.
Handle
(
ctx
)
if
!
config
.
C
.
DisableUsageReport
{
go
usage
.
Report
()
}
// release all the resources
return
fns
.
Ret
(),
nil
}
...
...
src/server/usage/usage.go
0 → 100644
浏览文件 @
2bea8b7c
package
usage
import
(
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
"github.com/didi/nightingale/v5/src/server/common/conv"
"github.com/didi/nightingale/v5/src/server/reader"
)
const
(
url
=
"http://n9e.io/report"
request
=
"sum(rate(n9e_server_samples_received_total[5m]))"
)
type
Usage
struct
{
Samples
float64
`json:"samples"`
// per second
Maintainer
string
`json:"maintainer"`
Hostname
string
`json:"hostname"`
}
func
getSamples
()
(
float64
,
error
)
{
value
,
warns
,
err
:=
reader
.
Reader
.
Client
.
Query
(
context
.
Background
(),
request
,
time
.
Now
())
if
err
!=
nil
{
return
0
,
err
}
if
len
(
warns
)
>
0
{
return
0
,
fmt
.
Errorf
(
"occur some warnings: %v"
,
warns
)
}
lst
:=
conv
.
ConvertVectors
(
value
)
if
len
(
lst
)
==
0
{
return
0
,
fmt
.
Errorf
(
"convert result is empty"
)
}
return
lst
[
0
]
.
Value
,
nil
}
func
Report
()
{
for
{
time
.
Sleep
(
time
.
Minute
*
10
)
report
()
}
}
func
report
()
{
sps
,
err
:=
getSamples
()
if
err
!=
nil
{
return
}
hostname
,
err
:=
os
.
Hostname
()
if
err
!=
nil
{
return
}
maintainer
:=
"blank"
u
:=
Usage
{
Samples
:
sps
,
Hostname
:
hostname
,
Maintainer
:
maintainer
,
}
post
(
u
)
}
func
post
(
u
Usage
)
error
{
body
,
err
:=
json
.
Marshal
(
u
)
if
err
!=
nil
{
return
err
}
req
,
err
:=
http
.
NewRequest
(
"POST"
,
url
,
bytes
.
NewReader
(
body
))
if
err
!=
nil
{
return
err
}
cli
:=
http
.
Client
{
Timeout
:
time
.
Second
*
10
,
}
resp
,
err
:=
cli
.
Do
(
req
)
if
err
!=
nil
{
return
err
}
if
resp
.
StatusCode
!=
200
{
return
fmt
.
Errorf
(
"got %s"
,
resp
.
Status
)
}
_
,
err
=
ioutil
.
ReadAll
(
resp
.
Body
)
return
err
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录