Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Nightingale
提交
7f4cb388
N
Nightingale
项目概览
jobily
/
Nightingale
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7f4cb388
编写于
1月 11, 2022
作者:
U
UlricQin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support falcon datamodel
上级
120c2fe5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
230 addition
and
1 deletion
+230
-1
Makefile
Makefile
+1
-1
src/server/router/router.go
src/server/router/router.go
+1
-0
src/server/router/router_openfalcon.go
src/server/router/router_openfalcon.go
+228
-0
未找到文件。
Makefile
浏览文件 @
7f4cb388
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
NOW
=
$(
shell
date
-u
'+%Y%m%d%I%M%S'
)
NOW
=
$(
shell
date
-u
'+%Y%m%d%I%M%S'
)
RELEASE_VERSION
=
5.
2.2
RELEASE_VERSION
=
5.
3.0
APP
=
n9e
APP
=
n9e
SERVER_BIN
=
$(APP)
SERVER_BIN
=
$(APP)
...
...
src/server/router/router.go
浏览文件 @
7f4cb388
...
@@ -74,6 +74,7 @@ func configRoute(r *gin.Engine, version string) {
...
@@ -74,6 +74,7 @@ func configRoute(r *gin.Engine, version string) {
}
}
r
.
POST
(
"/opentsdb/put"
,
handleOpenTSDB
)
r
.
POST
(
"/opentsdb/put"
,
handleOpenTSDB
)
r
.
POST
(
"/openfalcon/push"
,
falconPush
)
r
.
POST
(
"/prometheus/v1/write"
,
remoteWrite
)
r
.
POST
(
"/prometheus/v1/write"
,
remoteWrite
)
r
.
POST
(
"/prometheus/v1/query"
,
queryPromql
)
r
.
POST
(
"/prometheus/v1/query"
,
queryPromql
)
...
...
src/server/router/router_openfalcon.go
0 → 100644
浏览文件 @
7f4cb388
package
router
import
(
"compress/gzip"
"encoding/json"
"fmt"
"io/ioutil"
"strconv"
"strings"
"time"
"github.com/didi/nightingale/v5/src/server/config"
"github.com/didi/nightingale/v5/src/server/idents"
"github.com/didi/nightingale/v5/src/server/memsto"
promstat
"github.com/didi/nightingale/v5/src/server/stat"
"github.com/didi/nightingale/v5/src/server/writer"
"github.com/gin-gonic/gin"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/prompb"
)
type
FalconMetric
struct
{
Metric
string
`json:"metric"`
Endpoint
string
`json:"endpoint"`
Timestamp
int64
`json:"timestamp"`
ValueUnTyped
interface
{}
`json:"value"`
Value
float64
`json:"-"`
Tags
string
`json:"tags"`
}
func
(
m
*
FalconMetric
)
Clean
()
error
{
if
m
.
Metric
==
""
{
return
fmt
.
Errorf
(
"metric is blank"
)
}
switch
v
:=
m
.
ValueUnTyped
.
(
type
)
{
case
string
:
if
f
,
err
:=
strconv
.
ParseFloat
(
v
,
64
);
err
==
nil
{
m
.
Value
=
f
}
else
{
return
fmt
.
Errorf
(
"unparseable value %v"
,
v
)
}
case
float64
:
m
.
Value
=
v
case
uint64
:
m
.
Value
=
float64
(
v
)
case
int64
:
m
.
Value
=
float64
(
v
)
case
int
:
m
.
Value
=
float64
(
v
)
default
:
return
fmt
.
Errorf
(
"unparseable value %v"
,
v
)
}
// if timestamp bigger than 32 bits, likely in milliseconds
if
m
.
Timestamp
>
0xffffffff
{
m
.
Timestamp
/=
1000
}
return
nil
}
func
(
m
*
FalconMetric
)
ToProm
()
(
*
prompb
.
TimeSeries
,
string
,
error
)
{
pt
:=
&
prompb
.
TimeSeries
{}
pt
.
Samples
=
append
(
pt
.
Samples
,
prompb
.
Sample
{
// use ms
Timestamp
:
m
.
Timestamp
*
1000
,
Value
:
m
.
Value
,
})
if
strings
.
IndexByte
(
m
.
Metric
,
'.'
)
!=
-
1
{
m
.
Metric
=
strings
.
ReplaceAll
(
m
.
Metric
,
"."
,
"_"
)
}
if
strings
.
IndexByte
(
m
.
Metric
,
'-'
)
!=
-
1
{
m
.
Metric
=
strings
.
ReplaceAll
(
m
.
Metric
,
"-"
,
"_"
)
}
if
!
model
.
MetricNameRE
.
MatchString
(
m
.
Metric
)
{
return
nil
,
""
,
fmt
.
Errorf
(
"invalid metric name: %s"
,
m
.
Metric
)
}
pt
.
Labels
=
append
(
pt
.
Labels
,
&
prompb
.
Label
{
Name
:
model
.
MetricNameLabel
,
Value
:
m
.
Metric
,
})
tagarr
:=
strings
.
Split
(
m
.
Tags
,
","
)
tagmap
:=
make
(
map
[
string
]
string
,
len
(
tagarr
)
+
1
)
for
i
:=
0
;
i
<
len
(
tagarr
);
i
++
{
tmp
:=
strings
.
SplitN
(
tagarr
[
i
],
"="
,
2
)
if
len
(
tmp
)
!=
2
{
continue
}
tagmap
[
tmp
[
0
]]
=
tmp
[
1
]
}
ident
:=
""
if
len
(
m
.
Endpoint
)
>
0
{
ident
=
m
.
Endpoint
if
id
,
exists
:=
tagmap
[
"ident"
];
exists
{
ident
=
id
// 以tags中的ident作为唯一标识
tagmap
[
"endpoint"
]
=
m
.
Endpoint
}
else
{
// 把endpoint塞到tags中,改key为ident
tagmap
[
"ident"
]
=
m
.
Endpoint
}
}
for
key
,
value
:=
range
tagmap
{
if
strings
.
IndexByte
(
key
,
'.'
)
!=
-
1
{
key
=
strings
.
ReplaceAll
(
key
,
"."
,
"_"
)
}
if
strings
.
IndexByte
(
key
,
'-'
)
!=
-
1
{
key
=
strings
.
ReplaceAll
(
key
,
"-"
,
"_"
)
}
if
!
model
.
LabelNameRE
.
MatchString
(
key
)
{
return
nil
,
""
,
fmt
.
Errorf
(
"invalid tag name: %s"
,
key
)
}
pt
.
Labels
=
append
(
pt
.
Labels
,
&
prompb
.
Label
{
Name
:
key
,
Value
:
value
,
})
}
return
pt
,
ident
,
nil
}
func
falconPush
(
c
*
gin
.
Context
)
{
var
bs
[]
byte
var
err
error
if
c
.
GetHeader
(
"Content-Encoding"
)
==
"gzip"
{
r
,
err
:=
gzip
.
NewReader
(
c
.
Request
.
Body
)
if
err
!=
nil
{
c
.
String
(
400
,
err
.
Error
())
return
}
defer
r
.
Close
()
bs
,
err
=
ioutil
.
ReadAll
(
r
)
}
else
{
defer
c
.
Request
.
Body
.
Close
()
bs
,
err
=
ioutil
.
ReadAll
(
c
.
Request
.
Body
)
}
if
err
!=
nil
{
c
.
String
(
400
,
err
.
Error
())
return
}
var
arr
[]
FalconMetric
if
bs
[
0
]
==
'['
{
err
=
json
.
Unmarshal
(
bs
,
&
arr
)
}
else
{
var
one
FalconMetric
err
=
json
.
Unmarshal
(
bs
,
&
one
)
arr
=
[]
FalconMetric
{
one
}
}
if
err
!=
nil
{
c
.
String
(
400
,
err
.
Error
())
return
}
var
(
succ
int
fail
int
msg
=
"data pushed to queue"
list
=
make
([]
interface
{},
0
,
len
(
arr
))
ts
=
time
.
Now
()
.
Unix
()
ids
=
make
(
map
[
string
]
interface
{})
)
for
i
:=
0
;
i
<
len
(
arr
);
i
++
{
if
err
:=
arr
[
i
]
.
Clean
();
err
!=
nil
{
fail
++
continue
}
pt
,
ident
,
err
:=
arr
[
i
]
.
ToProm
()
if
err
!=
nil
{
fail
++
continue
}
if
ident
!=
""
{
// register host
ids
[
ident
]
=
ts
// fill tags
target
,
has
:=
memsto
.
TargetCache
.
Get
(
ident
)
if
has
{
for
key
,
value
:=
range
target
.
TagsMap
{
pt
.
Labels
=
append
(
pt
.
Labels
,
&
prompb
.
Label
{
Name
:
key
,
Value
:
value
,
})
}
}
}
list
=
append
(
list
,
pt
)
succ
++
}
if
len
(
list
)
>
0
{
promstat
.
CounterSampleTotal
.
WithLabelValues
(
config
.
C
.
ClusterName
,
"openfalcon"
)
.
Add
(
float64
(
len
(
list
)))
if
!
writer
.
Writers
.
PushQueue
(
list
)
{
msg
=
"writer queue full"
}
idents
.
Idents
.
MSet
(
ids
)
}
c
.
JSON
(
200
,
gin
.
H
{
"succ"
:
succ
,
"fail"
:
fail
,
"msg"
:
msg
,
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录