Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
fb038039
Commit
fb038039
authored
Jun 30, 2023
by
李科
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 普罗米修斯指标&标签查询
parent
0110717b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
136 additions
and
11 deletions
+136
-11
src/bean/vo/request/prometheus.go
src/bean/vo/request/prometheus.go
+5
-0
src/bean/vo/response/prometheus.go
src/bean/vo/response/prometheus.go
+25
-0
src/common/conf/options.go
src/common/conf/options.go
+1
-0
src/controller/prometheus.go
src/controller/prometheus.go
+25
-0
src/main.go
src/main.go
+12
-11
src/router/prometheusrouter.go
src/router/prometheusrouter.go
+16
-0
src/router/router.go
src/router/router.go
+2
-0
src/service/prometheus.go
src/service/prometheus.go
+50
-0
No files found.
src/bean/vo/request/prometheus.go
0 → 100644
View file @
fb038039
package
request
type
PrometheusLabel
struct
{
LabelName
string
`json:"label_name" form:"label_name"`
}
src/bean/vo/response/prometheus.go
0 → 100644
View file @
fb038039
package
response
type
PrometheusItem
struct
{
Serial
}
type
PrometheusList
struct
{
TotalCount
int64
`json:"total_count"`
List
[]
string
`json:"list"`
}
type
PrometheusLabel
struct
{
Status
string
`json:"status"`
Data
[]
string
`json:"data"`
}
type
PrometheusSeries
struct
{
Status
string
`json:"status"`
Data
[]
map
[
string
]
string
`json:"data"`
}
type
Serial
struct
{
Name
string
`json:"name"`
Value
string
`json:"value,omitempty"`
Children
[]
Serial
`json:"children,omitempty"`
}
src/common/conf/options.go
View file @
fb038039
...
@@ -31,6 +31,7 @@ type Config struct {
...
@@ -31,6 +31,7 @@ type Config struct {
MinioSecretKey
string
MinioSecretKey
string
MinioBucket
string
MinioBucket
string
TempDirPrefix
string
TempDirPrefix
string
PrometheusHost
string
}
}
const
(
const
(
...
...
src/controller/prometheus.go
0 → 100644
View file @
fb038039
package
controller
import
(
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
func
PrometheusLabel
(
c
*
gin
.
Context
)
{
var
req
request
.
PrometheusLabel
if
err
:=
c
.
ShouldBind
(
&
req
);
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
TranslateError
(
err
),
nil
)
return
}
svc
:=
service
.
PrometheusSvc
{
User
:
header
.
GetUser
(
c
)}
data
,
err
:=
svc
.
Label
(
req
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
FAIL
.
WithError
(
err
),
nil
)
return
}
SendJsonResponse
(
c
,
resp
.
OK
,
data
)
}
src/main.go
View file @
fb038039
...
@@ -54,17 +54,18 @@ func initConfig() {
...
@@ -54,17 +54,18 @@ func initConfig() {
RedisURL
:
util
.
SetEnvStr
(
"REDIS_URL"
,
"localhost:7001"
),
RedisURL
:
util
.
SetEnvStr
(
"REDIS_URL"
,
"localhost:7001"
),
RedisDB
:
0
,
RedisDB
:
0
,
RedisTag
:
"bg"
,
RedisTag
:
"bg"
,
LogDirPrefix
:
util
.
SetEnvStr
(
"LOG_DIR_PREFIX"
,
"/app/log"
),
// 日志目录
LogDirPrefix
:
util
.
SetEnvStr
(
"LOG_DIR_PREFIX"
,
"/app/log"
),
// 日志目录
LogDirName
:
util
.
SetEnvStr
(
"LOG_NAME"
,
"syslog"
),
// 日志名称
LogDirName
:
util
.
SetEnvStr
(
"LOG_NAME"
,
"syslog"
),
// 日志名称
LogSaveDays
:
util
.
SetEnvInt
(
"LOG_SAVE_DAYS"
,
7
),
// 日志最大存储天数
LogSaveDays
:
util
.
SetEnvInt
(
"LOG_SAVE_DAYS"
,
7
),
// 日志最大存储天数
LogMode
:
util
.
SetEnvInt
(
"LOG_MODE"
,
1
),
// 1.标准打印 2.输出文件
LogMode
:
util
.
SetEnvInt
(
"LOG_MODE"
,
1
),
// 1.标准打印 2.输出文件
ArgBool
:
util
.
SetEnvBool
(
"ARG_BOOL"
,
false
),
// 示例参数
ArgBool
:
util
.
SetEnvBool
(
"ARG_BOOL"
,
false
),
// 示例参数
ArgInt
:
util
.
SetEnvInt
(
"ARG_INT"
,
10
),
// 示例参数
ArgInt
:
util
.
SetEnvInt
(
"ARG_INT"
,
10
),
// 示例参数
MinioServer
:
util
.
SetEnvStr
(
"MINIO_SERVER"
,
"cache.wodcloud.com"
),
// Minio 服务地址
MinioServer
:
util
.
SetEnvStr
(
"MINIO_SERVER"
,
"cache.wodcloud.com"
),
// Minio 服务地址
MinioAccessKey
:
util
.
SetEnvStr
(
"MINIO_ACCESS_KEY"
,
"beagleadmin"
),
// Minio Access Key
MinioAccessKey
:
util
.
SetEnvStr
(
"MINIO_ACCESS_KEY"
,
"beagleadmin"
),
// Minio Access Key
MinioSecretKey
:
util
.
SetEnvStr
(
"MINIO_SECRET_KEY"
,
"H76cPmwvH7vJ"
),
// Minio Secret
MinioSecretKey
:
util
.
SetEnvStr
(
"MINIO_SECRET_KEY"
,
"H76cPmwvH7vJ"
),
// Minio Secret
MinioBucket
:
util
.
SetEnvStr
(
"MINIO_BUCKET"
,
"so-operation"
),
// Minio Bucket
MinioBucket
:
util
.
SetEnvStr
(
"MINIO_BUCKET"
,
"so-operation"
),
// Minio Bucket
TempDirPrefix
:
util
.
SetEnvStr
(
"TEMP_DIR_PREFIX"
,
"/app/xlsx/"
),
//模板目录前缀
TempDirPrefix
:
util
.
SetEnvStr
(
"TEMP_DIR_PREFIX"
,
"/app/xlsx/"
),
//模板目录前缀
PrometheusHost
:
util
.
SetEnvStr
(
"PROMETHEUS_HOST"
,
"https://prometheus.wodcloud.com"
),
// Prometheus Host
}
}
}
}
...
...
src/router/prometheusrouter.go
0 → 100644
View file @
fb038039
package
router
import
(
"fmt"
"github.com/gin-gonic/gin"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
)
// InitPrometheusRouter 初始化prometheus路由
func
InitPrometheusRouter
(
e
*
gin
.
Engine
)
{
group
:=
e
.
Group
(
fmt
.
Sprintf
(
"%s/prometheus"
,
conf
.
Options
.
Prefix
))
{
group
.
GET
(
""
,
controller
.
PrometheusLabel
)
}
}
src/router/router.go
View file @
fb038039
...
@@ -38,4 +38,6 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
...
@@ -38,4 +38,6 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
InitOrganizationRouter
(
r
)
InitOrganizationRouter
(
r
)
// 初始化指标配置路由
// 初始化指标配置路由
InitMetricConfigRouter
(
r
)
InitMetricConfigRouter
(
r
)
// 初始化prometheus路由
InitPrometheusRouter
(
r
)
}
}
src/service/prometheus.go
0 → 100644
View file @
fb038039
package
service
import
(
"fmt"
json
"github.com/json-iterator/go"
"github.com/thoas/go-funk"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
"net/http"
"sort"
)
type
PrometheusSvc
struct
{
User
entity
.
SystemUserInfo
}
func
(
m
*
PrometheusSvc
)
Label
(
req
request
.
PrometheusLabel
)
(
resp
response
.
PrometheusList
,
err
error
)
{
var
(
prometheusLabel
response
.
PrometheusLabel
prometheusSeries
response
.
PrometheusSeries
)
if
req
.
LabelName
!=
""
{
url
:=
fmt
.
Sprintf
(
"%s%s"
,
conf
.
Options
.
PrometheusHost
,
"/api/v1/series"
)
bytes
,
_
:=
util
.
Request
(
url
,
http
.
MethodPost
,
[]
byte
(
fmt
.
Sprintf
(
"match[]=%s"
,
req
.
LabelName
)),
map
[
string
]
string
{
"Content-Type"
:
util
.
MediaTypeForm
})
_
=
json
.
Unmarshal
(
bytes
,
&
prometheusSeries
)
for
_
,
v
:=
range
prometheusSeries
.
Data
{
for
k
,
_
:=
range
v
{
resp
.
List
=
append
(
resp
.
List
,
k
)
}
}
resp
.
List
=
funk
.
UniqString
(
resp
.
List
)
sort
.
Strings
(
resp
.
List
)
resp
.
TotalCount
=
int64
(
len
(
resp
.
List
))
}
else
{
url
:=
fmt
.
Sprintf
(
"%s%s"
,
conf
.
Options
.
PrometheusHost
,
"/api/v1/label/__name__/values"
)
bytes
,
_
:=
util
.
Request
(
url
,
http
.
MethodGet
,
nil
,
nil
)
_
=
json
.
Unmarshal
(
bytes
,
&
prometheusLabel
)
resp
.
TotalCount
=
int64
(
len
(
prometheusLabel
.
Data
))
resp
.
List
=
prometheusLabel
.
Data
}
return
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment