3 * Copyright 2016 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 "golang.org/x/net/context"
27 "google.golang.org/grpc"
28 "google.golang.org/grpc/grpclog"
29 metricspb "google.golang.org/grpc/stress/grpc_testing"
33 metricsServerAddress = flag.String("metrics_server_address", "", "The metrics server addresses in the fomrat <hostname>:<port>")
34 totalOnly = flag.Bool("total_only", false, "If true, this prints only the total value of all gauges")
37 func printMetrics(client metricspb.MetricsServiceClient, totalOnly bool) {
38 stream, err := client.GetAllGauges(context.Background(), &metricspb.EmptyMessage{})
40 grpclog.Fatalf("failed to call GetAllGuages: %v", err)
48 gaugeResponse, err := stream.Recv()
53 if _, ok := gaugeResponse.GetValue().(*metricspb.GaugeResponse_LongValue); !ok {
54 panic(fmt.Sprintf("gauge %s is not a long value", gaugeResponse.Name))
56 v := gaugeResponse.GetLongValue()
58 grpclog.Printf("%s: %d", gaugeResponse.Name, v)
62 if rpcStatus != io.EOF {
63 grpclog.Fatalf("failed to finish server streaming: %v", rpcStatus)
65 grpclog.Printf("overall qps: %d", overallQPS)
70 if *metricsServerAddress == "" {
71 grpclog.Fatalf("Metrics server address is empty.")
74 conn, err := grpc.Dial(*metricsServerAddress, grpc.WithInsecure())
76 grpclog.Fatalf("cannot connect to metrics server: %v", err)
80 c := metricspb.NewMetricsServiceClient(conn)
81 printMetrics(c, *totalOnly)