feat: script collect support append_tags and fix timeout

This commit is contained in:
710leo 2021-08-23 16:59:55 +08:00
parent 754ad160dc
commit 58093eedf0
2 changed files with 10 additions and 2 deletions

View File

@ -28,7 +28,7 @@ type CollectRule struct {
type PortConfig struct {
Port int `json:"port"`
Protocol string `json:"protocol"` // tcp or udp
Timeout int `json:"timeout "` // second
Timeout int `json:"timeout"` // second
}
type ProcConfig struct {
@ -41,7 +41,7 @@ type ScriptConfig struct {
Params string `json:"params"`
Stdin string `json:"stdin"`
Env map[string]string `json:"env"`
Timeout int `json:"timeout "` // second
Timeout int `json:"timeout"` // second
}
type LogConfig struct {

View File

@ -153,6 +153,11 @@ func changeCollectRule(rule *models.CollectRule) error {
return err
}
tags := strings.Fields(rule.AppendTags)
for i := 0; i < len(tags); i++ {
tags[i] = strings.Replace(tags[i], "=", ":", 1)
}
config := ScriptCollectFormat{
Instances: []struct {
MinCollectionInterval int `json:"min_collection_interval,omitempty"`
@ -162,6 +167,7 @@ func changeCollectRule(rule *models.CollectRule) error {
Env map[string]string `json:"env"`
Stdin string `json:"stdin"`
Timeout int `json:"timeout"`
Tags []string `json:"tags,omitempty"`
}{{
MinCollectionInterval: rule.Step,
FilePath: conf.Path,
@ -169,6 +175,7 @@ func changeCollectRule(rule *models.CollectRule) error {
Env: conf.Env,
Stdin: conf.Stdin,
Timeout: conf.Timeout,
Tags: tags,
}},
}
@ -257,6 +264,7 @@ type ScriptCollectFormat struct {
Env map[string]string `json:"env"`
Stdin string `json:"stdin"`
Timeout int `json:"timeout"`
Tags []string `json:"tags,omitempty"`
} `json:"instances"`
}