Skip to content

Latest commit

 

History

History
 
 

grpc

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Example RPC server

This example uses:

  • gRPC to create an RPC server and client.
  • The OpenCensus gRPC plugin to instrument the RPC server.
  • The Stackdriver exporter to export stats and traces.
  • The Prometheus exporter to export stats.
  • Debugging exporters to print stats and traces to stdout.

Usage:

bazel build :all
../../bazel-bin/examples/grpc/hello_server 9001
../../bazel-bin/examples/grpc/hello_client "[::]:9001"

You can see the Prometheus stats on http://127.0.0.1:8080/metrics

To increase gRPC verbosity, try:

env GRPC_VERBOSITY=DEBUG ../../bazel-bin/examples/grpc/hello_server 9001
env GRPC_VERBOSITY=DEBUG ../../bazel-bin/examples/grpc/hello_client "[::]:9001"

Stackdriver

In order to be able to push your stats to Stackdriver Monitoring, you must:

  1. Create a Cloud project.
  2. Enable billing.
  3. Enable the Stackdriver Monitoring API.
  4. Make sure you have a Premium Stackdiver account.

To use our Stackdriver Stats exporter, your Stackdriver account needs to have permission to create custom metrics, and that requires a Premium tier Stackdriver account. Please note that by default all new Stackdriver accounts are Basic tier. To upgrade to a Premium tier Stackdriver account, follow the instructions here.

Running the example on GCE

Log in to a GCE instance:

gcloud compute --project myproject ssh myinstance

Install the build tools:

sudo apt install pkg-config zip g++ zlib1g-dev unzip python
wget https://github.com/bazelbuild/bazel/releases/download/0.11.0/bazel-0.11.0-installer-linux-x86_64.sh
chmod +x bazel-0.11.0-installer-linux-x86_64.sh
./bazel-0.11.0-installer-linux-x86_64.sh --user

Build the example:

git clone https://github.com/census-instrumentation/opencensus-cpp.git
cd opencensus-cpp/examples/grpc
bazel build :all

Install the gRPC certificates on the VM: (you only need to do this once)

sudo mkdir -p /usr/share/grpc
sudo cp $(bazel info output_base)/external/com_github_grpc_grpc/etc/roots.pem /usr/share/grpc/roots.pem

Run the server but set STACKDRIVER_PROJECT_ID, e.g.:

env STACKDRIVER_PROJECT_ID=myproject ../../bazel-bin/examples/grpc/hello_server 9001
env STACKDRIVER_PROJECT_ID=myproject ../../bazel-bin/examples/grpc/hello_client [::]:9001

When running on GCE, the credentials used to authenticate to Stackdriver are determined automatically from the VM.

Stats

Go to https://console.cloud.google.com/monitoring to see stats:

  • Click on Resources → Metrics Explorer.
  • Choose the "global" Resource Type.

Example:

Example of stats

Tracing

Go to https://console.cloud.google.com/traces/traces to see traces. Example:

Example trace