/
types.go
107 lines (93 loc) · 3.74 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package api
import (
"encoding/json"
"fmt"
"sigs.k8s.io/yaml"
)
type CollectRule struct {
ID int64 `jso:id` // option rule.ID
Name string `json:"name"` // option Config.instances[$] ruleID
Type string `json:"type"` // required Config.Name checkName
Data string `json:"data"` // required Config.Instances[$]
Interval int `json:"step"` // -> Config.Instances[$].MinCollectionInterval
Tags string `json:"appendTags"` // -> Config.Instances[$].Tags a:b,b:c
CreatedAt int64 `json:"createAt"` // deprecated
UpdatedAt int64 `json:"updateAt"` // deprecated
Creator string `json:"createBy"` // deprecated
Updater string `json:"updateBy"` // deprecated
}
type CollectRulesSummary struct {
LatestUpdatedAt int64 `json:"latestUpdatedAt"`
Total int `json:"total"`
}
// from pkg/autodiscovery/providers/file.go: configFormat
// format of collectRule.Data
type ConfigFormat struct {
ADIdentifiers []string `json:"adIdentifiers"`
ClusterCheck bool `json:"clusterCheck"`
InitConfig interface{} `json:"initConfig"`
MetricConfig interface{} `json:"jmxMetrics"`
LogsConfig interface{} `json:"logs"`
Instances []interface{} `json:"instances"`
IgnoreAutodiscoveryTags bool `json:"ignoreAutodiscoveryTags"` // Use to ignore tags coming from autodiscovery
}
// Converts YAML to JSON then uses JSON to unmarshal into ConfigFormat
func ParseConfigFormatYaml(data []byte) (*ConfigFormat, error) {
var cf ConfigFormat
if err := yaml.Unmarshal(data, &cf); err != nil {
return nil, fmt.Errorf("yaml.Unmarshal %s", err)
}
return &cf, nil
}
func ParseConfigFormatJson(data []byte) (*ConfigFormat, error) {
var cf ConfigFormat
err := json.Unmarshal(data, &cf)
if err != nil {
return nil, fmt.Errorf("json.Unmarshal %s", err)
}
return &cf, nil
}
// CommonInstanceConfig holds the reserved fields for the yaml instance data
type CommonInstanceConfig struct {
MinCollectionInterval int `json:"minCollectionInterval"` // This changes the collection interval of the check - default: 15
EmptyDefaultHostname bool `json:"emptyDefaultHostname"` // This forces the check to send metrics with no hostname. This is useful for cluster-level checks.
Tags []string `json:"tags"` // A list of tags to attach to every metric and service check emitted by this instance, <key_1>:<value_1>
Service string `json:"service"` // Attach the tag `service:<SERVICE>` to every metric, event, and service check emitted by this integration.
Name string `json:"name"` //
Namespace string `json:"namespace"` //
}
type ScriptCollectFormat struct {
InitConfig struct {
Root string `json:"root"`
Env string `json:"env"`
Timeout int `json:"timeout"`
} `json:"initConfig"`
Instances []struct {
CommonInstanceConfig
FilePath string `json:"filePath"`
Root string `json:"root"`
Params string `json:"params"`
Env string `json:"env"`
Stdin string `json:"stdin"`
Timeout int `json:"timeout"`
} `json:"instances"`
}
type PortCollectFormat struct {
InitConfig struct {
Timeout int `json:"timeout"`
} `json:"initConfig"`
Instances []struct {
CommonInstanceConfig
Protocol string `json:"protocol" description:"udp or tcp"`
Port int `json:"port"`
} `json:"instances"`
}
type logCollectFormat struct {
Instances []struct {
CommonInstanceConfig
MetricName string `json:"metricName"` //
FilePath string `json:"filePath"` //
Pattern string `json:"pattern"` //
TagsPattern map[string]string `json:"tagsPattern"` //
} `json:"instances"`
}