-
Notifications
You must be signed in to change notification settings - Fork 185
/
net.go
67 lines (56 loc) · 1.92 KB
/
net.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
package net
import (
"github.com/aws/amazon-cloudwatch-agent/translator"
parent "github.com/aws/amazon-cloudwatch-agent/translator/translate/metrics/metrics_collect"
"github.com/aws/amazon-cloudwatch-agent/translator/translate/metrics/util"
)
var ChildRule = map[string]translator.Rule{}
const SectionKey_Net_Linux = "net"
const SectionKey_Net_Windows = "Network Interface"
func GetCurPath() string {
curPath := parent.GetCurPath() + SectionKey_Net_Linux + "/"
return curPath
}
func RegisterRule(fieldname string, r translator.Rule) {
ChildRule[fieldname] = r
}
type Net struct {
}
func (n *Net) ApplyRule(input interface{}) (returnKey string, returnVal interface{}) {
m := input.(map[string]interface{})
resArray := []interface{}{}
result := map[string]interface{}{}
//Generate the config file for monitoring system metrics on linux
//Check if this plugin exist in the input instance
//If not, not process
if _, ok := m[SectionKey_Net_Linux]; !ok {
returnKey = ""
returnVal = ""
} else {
/*
In JSON config file, it represents as "cpu" : {//specification config information}
To check the specification config entry
*/
//Check if there are some config entry with rules applied
result = translator.ProcessRuleToApply(m[SectionKey_Net_Linux], ChildRule, result)
//Process common config, like measurement
hasValidMetric := util.ProcessLinuxCommonConfig(m[SectionKey_Net_Linux], SectionKey_Net_Linux, GetCurPath(), result)
if hasValidMetric {
//Process report_deltas
util.ProcessReportDeltasForNet(m[SectionKey_Net_Linux], result)
resArray = append(resArray, result)
returnKey = SectionKey_Net_Linux
returnVal = resArray
} else {
returnKey = ""
}
}
return
}
func init() {
n := new(Net)
parent.RegisterLinuxRule(SectionKey_Net_Linux, n)
parent.RegisterDarwinRule(SectionKey_Net_Linux, n)
}