Skip to content

Commit 56cdf84

Browse files
committed
trival fix
1 parent 7ded2dd commit 56cdf84

File tree

5 files changed

+84
-89
lines changed

5 files changed

+84
-89
lines changed

SDK/go/utils/connection/connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func IRetry(ctx context.Context, netRetry INetRetry, config Config) (err error)
4545
if delay >= config.MaxDelaySec {
4646
delay = config.MaxDelaySec
4747
}
48-
retries = retries + 1
48+
retries++
4949
zap.S().Warnf("trying %s after %d seconds, retries:%d, error:%v", netRetry.String(), delay, retries, e)
5050
ticker.Reset(time.Second * time.Duration(delay))
5151
select {

agent/metrics/metric_agent.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
cpuLogicalNum int
3030
cpuMhz string
3131
cpuName string
32-
Memory uint64
32+
memory uint64
3333

3434
bootTime uint64
3535
)
@@ -51,7 +51,7 @@ func init() {
5151
cpuMhz = strconv.FormatFloat(mhz/1000, 'f', 1, 64)
5252

5353
if m, err := mem.VirtualMemory(); err == nil {
54-
Memory = m.Total
54+
memory = m.Total
5555
}
5656
bootTime, _ = host.BootTime()
5757
arch, _ = host.KernelArch()
@@ -115,7 +115,7 @@ func (m *AgentMetric) Flush(now time.Time) {
115115
m.CpuLogicalNum = strconv.Itoa(cpuLogicalNum)
116116
m.CpuMhz = cpuMhz
117117
m.CpuName = cpuName
118-
m.TotalMemory = strconv.FormatUint(Memory, 10)
118+
m.TotalMemory = strconv.FormatUint(memory, 10)
119119
m.BootTime = strconv.FormatUint(bootTime, 10)
120120

121121
pid := os.Getpid()
@@ -155,8 +155,8 @@ func (m *AgentMetric) Flush(now time.Time) {
155155
m.Load5 = strconv.FormatFloat(avg.Load5, 'f', 2, 64)
156156
m.Load15 = strconv.FormatFloat(avg.Load15, 'f', 2, 64)
157157
}
158-
// daemon.SdNotify(false, "WATCHDOG=1")
159158
}
159+
160160
rec := &proto.Record{
161161
DataType: config.DTAgentStatus,
162162
Timestamp: now.Unix(),

agent/metrics/metric_host.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import (
1010

1111
const max = 5
1212

13-
func init() {
14-
addMetric(&HostMetric{})
15-
}
16-
1713
type HostMetric struct{}
1814

1915
func (h *HostMetric) Name() string {
@@ -77,3 +73,7 @@ func (h *HostMetric) Flush(time.Time) {
7773
agent.PrivateIPv6.Store(privateIPv6)
7874
agent.PublicIPv6.Store(publicIPv6)
7975
}
76+
77+
func init() {
78+
addMetric(&HostMetric{})
79+
}

agent/metrics/metric_plugin.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ func (h *PluginMetric) Init() bool {
4343

4444
func (m *PluginMetric) Flush(now time.Time) {
4545
plgs := plugin.PluginManager.GetAll()
46+
rec := &proto.Record{
47+
DataType: config.DTPluginStatus,
48+
Timestamp: now.Unix(),
49+
Data: &proto.Payload{
50+
Fields: map[string]string{},
51+
},
52+
}
4653
// send an empty packet if there is no plugin
4754
if len(plgs) == 0 {
48-
rec := &proto.Record{
49-
DataType: config.DTPluginStatus,
50-
Timestamp: now.Unix(),
51-
Data: &proto.Payload{
52-
Fields: map[string]string{},
53-
},
54-
}
5555
transport.Trans.Transmission(rec, false)
5656
return
5757
}
@@ -82,13 +82,8 @@ func (m *PluginMetric) Flush(now time.Time) {
8282

8383
fields := make(map[string]string, 20)
8484
if err := mapstructure.Decode(m, &fields); err == nil {
85-
rec := &proto.Record{
86-
DataType: config.DTPluginStatus,
87-
Timestamp: now.Unix(),
88-
Data: &proto.Payload{
89-
Fields: fields,
90-
},
91-
}
85+
rec.Timestamp = now.Unix()
86+
rec.Data.Fields = fields
9287
transport.Trans.Transmission(rec, false)
9388
}
9489
}

agent/proto/grpc.proto

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,71 @@ option go_package = "proto";
44
package grpc;
55

66
message PackagedData {
7-
repeated Record records = 1;
8-
repeated Payload payloads = 2; // backport
9-
string agent_id = 3;
10-
repeated string intranet_ipv4 = 4;
11-
repeated string extranet_ipv4 = 5;
12-
repeated string intranet_ipv6 = 6;
13-
repeated string extranet_ipv6 = 7;
14-
string hostname = 8;
15-
string version = 9;
16-
string product = 10;
17-
}
18-
19-
message EncodedRecord {
20-
int32 data_type = 1;
21-
int64 timestamp = 2;
22-
bytes data = 3;
23-
}
24-
25-
message Record {
26-
int32 data_type = 1;
27-
int64 timestamp = 2;
28-
Payload data = 3;
29-
}
30-
31-
message Payload { map<string, string> fields = 1; }
32-
33-
message Command {
34-
Task task = 2;
35-
repeated Config configs = 3;
36-
}
37-
38-
message Task {
39-
int32 data_type = 1;
40-
string object_name = 2;
41-
string data = 3;
42-
string token = 4;
43-
}
44-
45-
message Config {
46-
string name = 1;
47-
string type = 2;
48-
string version = 3;
49-
string sha256 = 4;
50-
string signature = 5;
51-
repeated string download_urls = 6;
52-
string detail = 7;
53-
}
54-
55-
service Transfer {
56-
rpc Transfer(stream PackagedData) returns (stream Command) {}
57-
}
58-
59-
message FileUploadRequest {
60-
string token = 1;
61-
bytes data = 2;
62-
}
63-
64-
message FileUploadResponse {
65-
enum StatusCode {
66-
SUCCESS = 0;
67-
FAILED = 1;
68-
}
69-
StatusCode status = 1;
7+
repeated Record records = 1;
8+
repeated Payload payloads = 2; // backport
9+
string agent_id = 3;
10+
repeated string intranet_ipv4 = 4;
11+
repeated string extranet_ipv4 = 5;
12+
repeated string intranet_ipv6 = 6;
13+
repeated string extranet_ipv6 = 7;
14+
string hostname = 8;
15+
string version = 9;
16+
string product = 10;
17+
}
18+
19+
message EncodedRecord {
20+
int32 data_type = 1;
21+
int64 timestamp = 2;
22+
bytes data = 3;
23+
}
24+
25+
message Record {
26+
int32 data_type = 1;
27+
int64 timestamp = 2;
28+
Payload data = 3;
29+
}
30+
31+
message Payload { map<string, string> fields = 1; }
32+
33+
message Command {
34+
Task task = 2;
35+
repeated Config configs = 3;
36+
}
37+
38+
message Task {
39+
int32 data_type = 1;
40+
string object_name = 2;
41+
string data = 3;
42+
string token = 4;
43+
}
44+
45+
message Config {
46+
string name = 1;
47+
string type = 2;
48+
string version = 3;
49+
string sha256 = 4;
50+
string signature = 5;
51+
repeated string download_urls = 6;
52+
string detail = 7;
53+
}
54+
55+
service Transfer {
56+
rpc Transfer(stream PackagedData) returns (stream Command) {}
57+
}
58+
59+
message FileUploadRequest {
60+
string token = 1;
61+
bytes data = 2;
62+
}
63+
64+
message FileUploadResponse {
65+
enum StatusCode {
66+
SUCCESS = 0;
67+
FAILED = 1;
7068
}
69+
StatusCode status = 1;
70+
}
7171

72-
service FileExt {
73-
rpc Upload(stream FileUploadRequest) returns (FileUploadResponse);
74-
}
72+
service FileExt {
73+
rpc Upload(stream FileUploadRequest) returns (FileUploadResponse);
74+
}

0 commit comments

Comments
 (0)