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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
# OpenCensus Examples
## To build the examples use
### Gradle
```bash
./gradlew installDist
```
### Maven
```bash
mvn package appassembler:assemble
```
To build Spring Servlet example
```bash
cd spring/servlet
mvn package appassembler:assemble
```
## To run "TagContextExample" use
### Gradle
```bash
./build/install/opencensus-examples/bin/TagContextExample
```
### Maven
```bash
./target/appassembler/bin/TagContextExample
```
## To run "ZPagesTester"
### Gradle
```bash
./build/install/opencensus-examples/bin/ZPagesTester
```
### Maven
```bash
./target/appassembler/bin/ZPagesTester
```
Available pages:
* For tracing page go to [localhost:8080/tracez][ZPagesTraceZLink].
* For tracing config page go to [localhost:8080/traceconfigz][ZPagesTraceConfigZLink].
* For RPC stats page go to [localhost:8080/rpcz][ZPagesRpcZLink].
* For stats and measures on all registered views go to [localhost:8080/statsz][ZPagesStatsZLink].
[ZPagesTraceZLink]: http://localhost:8080/tracez
[ZPagesTraceConfigZLink]: http://localhost:8080/traceconfigz
[ZPagesRpcZLink]: http://localhost:8080/rpcz
[ZPagesStatsZLink]: http://localhost:8080/statsz
## To run "QuickStart" example use
### Gradle
```bash
./build/install/opencensus-examples/bin/QuickStart
```
### Maven
```bash
./target/appassembler/bin/QuickStart
```
## To run "gRPC Hello World" example use
Please note all the arguments are optional. If you do not specify these arguments, default values
will be used:
* host and serverPort will be "localhost:50051"
* user will be "world"
* cloudProjectId will be null (which means no stats/spans will be exported to Stackdriver)
* server zPagePort will be 3000
* client zPagePort will be 3001
* Prometheus port will be 9090
However, if you want to specify any of these arguements, please make sure they are in order.
### Gradle
```bash
./build/install/opencensus-examples/bin/HelloWorldServer serverPort cloudProjectId zPagePort prometheusPort
./build/install/opencensus-examples/bin/HelloWorldClient user host serverPort cloudProjectId zPagePort
```
### Maven
```bash
./target/appassembler/bin/HelloWorldServer serverPort cloudProjectId zPagePort prometheusPort
./target/appassembler/bin/HelloWorldClient user host serverPort cloudProjectId zPagePort
```
## To run "Repl" example
See the full tutorial on [OpenCensus website](https://opencensus.io/quickstart/java/metrics/).
First run:
### Gradle
```bash
./build/install/opencensus-examples/bin/Repl
```
### Maven
```bash
./target/appassembler/bin/Repl
```
Then start the Prometheus process:
```bash
cd src/main/java/io/opencensus/examples/quickstart/
prometheus --config.file=prometheus.yaml
```
Stats will be shown on Prometheus UI on http://localhost:9090.
## To run "StackdriverQuickstart" use
See the full tutorial on [OpenCensus website](https://opencensus.io/guides/exporters/supported-exporters/java/stackdriver/).
### Gradle
```bash
./build/install/opencensus-examples/bin/StackdriverQuickstart
```
### Maven
```
./target/appassembler/bin/StackdriverQuickstart
```
## To run HTTP Server and Client
`HttpJettyServer` is a web service using Jetty Server on top of http-servlet.
`HttpJettyClient` is a web client using Jetty Client that sends request to `HttpettyServer`.
Both `HttpJettyServer` and `HttpJettyClient` are instrumented with OpenCensus.
Traces from both client and server can be viewed in their respective logs on console.
Stats are available from Prometheus server running at
- http://localhost:9091/metrics - for client stats
- http://localhost:9090/metrics - for server stats
### Gradle
```bash
./build/install/opencensus-examples/bin/HttpJettyServer
./build/install/opencensus-examples/bin/HttpJettyClient
```
### Maven
```bash
./target/appassembler/bin/HttpJettyServer
./target/appassembler/bin/HttpJettyClient
```
## To run OcAgentExportersQuickStart
### Gradle
```bash
./build/install/opencensus-examples/bin/OcAgentExportersQuickStart agentEndpoint # default is localhost:56678
```
### Maven
```bash
./target/appassembler/bin/OcAgentExportersQuickStart agentEndpoint # default is localhost:56678
```
You also need to install and start OpenCensus-Agent in order to receive the traces and metrics.
For more information on setting up Agent, see [tutorial](https://opencensus.io/agent/).
## To run Spring HTTP Server and Client
`SpringServletApplication` is a web service application using Spring framework. The application
is instrumented with opencensus simply by incuding opencensus-contrib-spring-starter package.
The instrumentation enables tracing on incoming and outgoing http requests. On receiving GET
request, the server originates multiple GET requests to itself using AsyncRestTemplate on different
endpoint.
Send a http GET request using curl to see the traces on console.
```
curl http://localhost:8080
```
Stats are available from Prometheus server running at
- http://localhost:9090/metrics - for server and client stats
### Gradle
```bash
cd spring/servlet
./gradlew bootRun
```
### Maven
```bash
cd spring/servlet
./target/appassembler/bin/SpringServletApplication
```
|