Skip to content

Commit 8c5fbd6

Browse files
Merge pull request #41 from tianxiaoliang/master
misused timing metrics api
2 parents dc14791 + cbea66a commit 8c5fbd6

File tree

11 files changed

+385
-56
lines changed

11 files changed

+385
-56
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ jobs:
3636
- bash scripts/travis/goCycloChecker.sh
3737
- stage: Unit Test
3838
script:
39+
- export GOPROXY=https://goproxy.io
3940
- bash scripts/travis/unit_test.sh

README.md

+47-42
Original file line numberDiff line numberDiff line change
@@ -65,49 +65,54 @@ cse:
6565

6666
Every 2 sec data will be posted to monitoring server if serverUri is correct and enable is true
6767

68-
The data formate after post
68+
The data format
6969
```
70-
[
71-
[
72-
{
73-
"time": 1526905902632,
74-
"appId": "default",
75-
"version": "0.0.1",
76-
"qps": 0.16,
77-
"latency": 0,
78-
"failureRate": 0,
79-
"total": 2,
80-
"breakerRateAgg": 0,
81-
"circuitBreakerOpen": false,
82-
"failure": 0,
83-
"shortCircuited": 0,
84-
"semaphoreRejected": 0,
85-
"threadPoolRejected": 0,
86-
"countTimeout": 0,
87-
"l995": 0,
88-
"l99": 0,
89-
"l90": 0,
90-
"l75": 0,
91-
"l50": 0,
92-
"l25": 0,
93-
"l5": 0,
94-
"instanceId": "6a0895085cf211e8bb850255ac105551",
95-
"thread": 11,
96-
"cpu": 4,
97-
"memory": {
98-
"heapAlloc": 2294040,
99-
"heapIdle": 1671168,
100-
"heapInUse": 3768320,
101-
"heapObjects": 19609,
102-
"heapReleased": 0,
103-
"heapSys": 5439488
104-
},
105-
"functionCount": 1,
106-
"customs": null,
107-
"name": "root1-ThinkPad-T440p"
108-
}
109-
]
110-
]
70+
{
71+
"data": {
72+
"appId": "default",
73+
"version": "1.0.0",
74+
"name": "order",
75+
"environment": "",
76+
"instance": "order-c3bbef-8457f585dc-c69cz",
77+
"thread": 14,
78+
"customs": null,
79+
"interfaces": [
80+
{
81+
"name": "Consumer.restaurant.rest",
82+
"desc": "Consumer.restaurant.rest",
83+
"qps": 0,
84+
"latency": 1,
85+
"l995": 0,
86+
"l99": 0,
87+
"l90": 0,
88+
"l75": 0,
89+
"l50": 0,
90+
"l25": 0,
91+
"l5": 0,
92+
"rate": 1,
93+
"total": 0,
94+
"failure": 0,
95+
"shortCircuited": 0,
96+
"circuitBreakerOpen": false,
97+
"semaphoreRejected": 0,
98+
"threadPoolRejected": 0,
99+
"countTimeout": 0,
100+
"failureRate": 0
101+
}
102+
],
103+
"cpu": 4,
104+
"memory": {
105+
"heapAlloc": 3041688,
106+
"heapIdle": 61628416,
107+
"heapInUse": 4399104,
108+
"heapObjects": 28501,
109+
"heapReleased": 61595648,
110+
"heapSys": 66027520
111+
},
112+
"serviceId": "32370e6ed839834a0493dddc3e7a7d5cb6d5db59",
113+
"instanceId": "7c91fbb922ef11ea99b30255ac1004a6"
114+
}
115+
}
111116
112117
```
113118

cse_reporter.go

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func GetReporter() (*Reporter, error) {
4343
if err != nil {
4444
openlogging.GetLogger().Warnf("Get Monitoring URL failed, CSE monitoring function disabled, err: %v", err)
4545
errResult = err
46+
return
47+
4648
}
4749
openlogging.GetLogger().Infof("init monitoring client : %s", monitorServerURL)
4850
tlsConfig, err := getTLSForClient(monitorServerURL)

cse_resort_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package metricsink_test
19+
20+
import (
21+
"encoding/json"
22+
"github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
23+
"github.com/huaweicse/cse-collector/pkg/monitoring"
24+
"testing"
25+
"time"
26+
)
27+
28+
func TestGetReporter(t *testing.T) {
29+
hystrix.Do("cmd", func() error {
30+
time.Sleep(20 * time.Millisecond)
31+
return nil
32+
}, nil)
33+
hystrix.Do("cmd", func() error {
34+
time.Sleep(10 * time.Millisecond)
35+
return nil
36+
}, nil)
37+
hystrix.Do("cmd", func() error {
38+
time.Sleep(2 * time.Millisecond)
39+
return nil
40+
}, nil)
41+
time.Sleep(1 * time.Second)
42+
data := &monitoring.MonitorData{}
43+
cb, _, _ := hystrix.GetCircuit("cmd")
44+
data.AppendInterfaceInfo(cb)
45+
b, _ := json.MarshalIndent(data, "", " ")
46+
t.Log(string(b))
47+
}

example/order/conf/monitoring.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cse:
2+
metrics:
3+
apiPath: /metrics # we can also give api path having prefix "/" ,like /someurl/metrics
4+
enable: true
5+
enableGoRuntimeMetrics: true
6+
flushInterval: 10s

example/restaurant/conf/chassis.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
cse:
33
service:
44
registry:
5-
address: http://127.0.0.1:30100 # If type is File then address will be the path of the file
5+
address: https://cse.cn-north-1.myhuaweicloud.com # If type is File then address will be the path of the file
66
protocols:
77
rest:
88
listenAddress: 127.0.0.1:5001
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
#Private property of microservices
33
service_description:
4-
name: restaurantService
4+
name: restaurant
55
version: 1.0.0

go.mod

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
module github.com/huaweicse/cse-collector
22

33
require (
4-
github.com/go-chassis/foundation v0.1.0
5-
github.com/go-chassis/go-archaius v0.24.0
6-
github.com/go-chassis/go-chassis v1.7.6
4+
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4
5+
github.com/go-chassis/go-archaius v1.0.0
6+
github.com/go-chassis/go-chassis v1.8.1-0.20191218064704-90f4208e31e1
77
github.com/go-mesh/openlogging v1.0.1
8-
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
98
github.com/huaweicse/auth v1.1.2
109
)
1110

0 commit comments

Comments
 (0)