Skip to content

Commit

Permalink
add monitoring example
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoliang committed Feb 23, 2019
1 parent f8fab43 commit 29174c4
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 12 deletions.
22 changes: 10 additions & 12 deletions go.mod
@@ -1,27 +1,25 @@
module github.com/go-chassis/go-chassis-examples

require (
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
github.com/DataDog/zstd v1.3.5 // indirect
github.com/Shopify/sarama v1.20.1 // indirect
github.com/eapache/go-resiliency v1.1.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/go-chassis/go-chassis v1.2.0
github.com/go-chassis/go-chassis v1.2.3-0.20190222074658-6cd393ddbb42
github.com/go-chassis/go-chassis-plugins v0.0.0-20181108070724-c19e5b01b867
github.com/go-mesh/mesher v1.5.2-0.20181112024919-f35794494256
github.com/go-mesh/mesher v1.6.2-0.20190220074152-33c7aab883e2
github.com/go-mesh/openlogging v0.0.0-20181205082104-3d418c478b2d
github.com/gogo/googleapis v1.1.0 // indirect

github.com/golang/protobuf v1.2.0
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/lyft/protoc-gen-validate v0.0.11 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/huaweicse/auth v0.0.0-20190215074843-46b97a7adc3f
github.com/huaweicse/cse-collector v0.0.0-20190218064311-6b8009138adb
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492 // indirect
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/urfave/cli v1.20.1-0.20181029213200-b67dcf995b6a // indirect
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
google.golang.org/grpc v1.14.0
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/genproto v0.0.0-20181221175505-bd9b4fb69e2f // indirect
google.golang.org/grpc v1.16.0
)

replace (
Expand Down
35 changes: 35 additions & 0 deletions monitoring/README.md
@@ -0,0 +1,35 @@
# Quik start with examples

1. Launch service center
```sh
cd examples
docker-compose up
```

2. Run rest server

```sh
cd serverA
export CHASSIS_HOME=$PWD
go run main.go

```
```sh
cd serverB
export CHASSIS_HOME=$PWD
go run main.go

```
3. Run Rest client
```sh
cd client
export CHASSIS_HOME=$PWD
go run main.go

```

4. check zikpin at http://127.0.0.1:9411

5. check metrics at http://127.0.0.1:5001


10 changes: 10 additions & 0 deletions monitoring/client/conf/chassis.yaml
@@ -0,0 +1,10 @@
---
#APPLICATION_ID: CSE optional
cse:
service:
registry:
address: http://127.0.0.1:30100
handler:
chain:
Consumer:
default: bizkeeper-consumer,router,loadbalance,tracing-consumer,ratelimiter-consumer,transport
4 changes: 4 additions & 0 deletions monitoring/client/conf/microservice.yaml
@@ -0,0 +1,4 @@
---
#微服务的私有属性
service_description:
name: RESTClient
13 changes: 13 additions & 0 deletions monitoring/client/conf/monitoring.yaml
@@ -0,0 +1,13 @@
cse:
metrics:
apiPath: /metrics # we can also give api path having prefix "/" ,like /someurl/metrics
enable: true
enableGoRuntimeMetrics: true
flushInterval: 10s
tracing:
tracer: zipkin
settings:
collector: http
URI: http://127.0.0.1:9411/api/v1/spans
batchSize: 1
batchInterval: 1s
38 changes: 38 additions & 0 deletions monitoring/client/main.go
@@ -0,0 +1,38 @@
package main

import (
"context"

"github.com/go-chassis/go-chassis"
_ "github.com/go-chassis/go-chassis-plugins/tracing/zipkin"
_ "github.com/go-chassis/go-chassis/bootstrap"
"github.com/go-chassis/go-chassis/client/rest"
"github.com/go-chassis/go-chassis/core"
"github.com/go-chassis/go-chassis/core/lager"
"github.com/go-chassis/go-chassis/pkg/util/httputil"
"time"
)

//if you use go run main.go instead of binary run, plz export CHASSIS_HOME=/{path}/{to}/client/
func main() {
//Init framework
if err := chassis.Init(); err != nil {
lager.Logger.Error("Init failed." + err.Error())
return
}

req, err := rest.NewRequest("GET", "http://RESTServerA/trace", nil)
if err != nil {
lager.Logger.Error("new request failed." + err.Error())
return
}

resp, err := core.NewRestInvoker().ContextDo(context.TODO(), req)
if err != nil {
lager.Logger.Error("do request failed." + err.Error())
return
}
defer resp.Body.Close()
lager.Logger.Info("REST Server sayhello[GET]: " + string(httputil.ReadBody(resp)))
time.Sleep(2 * time.Second)
}
9 changes: 9 additions & 0 deletions monitoring/serverA/conf/chassis.yaml
@@ -0,0 +1,9 @@
---
cse:
service:
registry:
address: http://127.0.0.1:30100 # If type is File then address will be the path of the file
protocols:
rest:
listenAddress: 127.0.0.1:5001
advertiseAddress: 127.0.0.1:5001
4 changes: 4 additions & 0 deletions monitoring/serverA/conf/microservice.yaml
@@ -0,0 +1,4 @@
---
#微服务的私有属性
service_description:
name: RESTServerA
12 changes: 12 additions & 0 deletions monitoring/serverA/conf/monitoring.yaml
@@ -0,0 +1,12 @@
cse:
metrics:
apiPath: /metrics # we can also give api path having prefix "/" ,like /adas/metrics
enable: true
enableGoRuntimeMetrics: true
flushInterval: 10s
tracing:
tracer: zipkin
settings:
URI: http://127.0.0.1:9411/api/v1/spans
batchSize: 1
batchInterval: 1s
21 changes: 21 additions & 0 deletions monitoring/serverA/main.go
@@ -0,0 +1,21 @@
package main

import (
"github.com/go-chassis/go-chassis"
"github.com/go-chassis/go-chassis/core/lager"
"github.com/go-chassis/go-chassis/core/server"
"github.com/go-chassis/go-chassis/examples/schemas"
//tracers
_ "github.com/go-chassis/go-chassis-plugins/tracing/zipkin"
)

//if you use go run main.go instead of binary run, plz export CHASSIS_HOME=/{path}/{to}/serverA/

func main() {
chassis.RegisterSchema("rest", &schemas.TracingHello{}, server.WithSchemaID("TracingHello"))
if err := chassis.Init(); err != nil {
lager.Logger.Error("Init failed." + err.Error())
return
}
chassis.Run()
}
9 changes: 9 additions & 0 deletions monitoring/serverB/conf/chassis.yaml
@@ -0,0 +1,9 @@
---
cse:
service:
registry:
address: http://127.0.0.1:30100 # If type is File then address will be the path of the file
protocols:
rest:
listenAddress: 127.0.0.1:5002
advertiseAddress: 127.0.0.1:5002
4 changes: 4 additions & 0 deletions monitoring/serverB/conf/microservice.yaml
@@ -0,0 +1,4 @@
---
#微服务的私有属性
service_description:
name: RESTServerB
12 changes: 12 additions & 0 deletions monitoring/serverB/conf/monitoring.yaml
@@ -0,0 +1,12 @@
cse:
metrics:
apiPath: /metrics # we can also give api path having prefix "/" ,like /adas/metrics
enable: true
enableGoRuntimeMetrics: true
flushInterval: 10s
tracing:
tracer: zipkin
settings:
URI: http://127.0.0.1:9411/api/v1/spans
batchSize: 1
batchInterval: 1s
22 changes: 22 additions & 0 deletions monitoring/serverB/main.go
@@ -0,0 +1,22 @@
package main

import (
//tracers
_ "github.com/go-chassis/go-chassis-plugins/tracing/zipkin"

"github.com/go-chassis/go-chassis"
"github.com/go-chassis/go-chassis/core/server"
"github.com/go-chassis/go-chassis/examples/schemas"
"github.com/go-mesh/openlogging"
)

//if you use go run main.go instead of binary run, plz export CHASSIS_HOME=/{path}/{to}/serverB/

func main() {
chassis.RegisterSchema("rest", &schemas.RestFulHello{}, server.WithSchemaID("RestHelloService"))
if err := chassis.Init(); err != nil {
openlogging.Error("Init failed." + err.Error())
return
}
chassis.Run()
}

0 comments on commit 29174c4

Please sign in to comment.