Skip to content

Commit

Permalink
Merge pull request #8 from BuoyantIO/stevej/add_prometheus
Browse files Browse the repository at this point in the history
Add prometheus stats
  • Loading branch information
stevej authored May 4, 2017
2 parents 19bae62 + 45452c2 commit 010b197
Show file tree
Hide file tree
Showing 252 changed files with 76,810 additions and 13 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
strest-server
strest-client
strest.pb.go
strest-server*
strest-client*

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
Expand Down
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.8.0-alpine

WORKDIR /go/src/strest-grpc

ADD . /go/src/github.com/buoyantio/strest-grpc

RUN go build -o /go/bin/strest-server /go/src/github.com/buoyantio/strest-grpc/server/main.go
RUN go build -o /go/bin/strest-client /go/src/github.com/buoyantio/strest-grpc/client/main.go

ENTRYPOINT ["/go/bin/strest-server"]
188 changes: 188 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Godeps/Readme

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions bin/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -x

GOOS=linux GOARCH=amd64 go build -o strest-server-linux server/main.go
GOOS=linux GOARCH=amd64 go build -o strest-client-linux client/main.go

57 changes: 53 additions & 4 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"math"
"math/rand"
"net/http"
"os"
"os/signal"
"path"
Expand All @@ -17,10 +18,12 @@ import (
"syscall"
"time"

pb "../protos"
"github.com/buoyantio/strest-grpc/client/distribution"
"github.com/buoyantio/strest-grpc/client/percentiles"
pb "github.com/buoyantio/strest-grpc/protos"
"github.com/codahale/hdrhistogram"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -62,7 +65,40 @@ type Quantiles struct {
// 1 day in milliseconds
const DAY_IN_MS int64 = 24 * 60 * 60 * 1000000

var sizeSuffixes = []string{"B", "KB", "MB", "GB"}
var (
sizeSuffixes = []string{"B", "KB", "MB", "GB"}

promRequests = prometheus.NewCounter(prometheus.CounterOpts{
Name: "requests",
Help: "Number of requests",
})

promResponses = prometheus.NewCounter(prometheus.CounterOpts{
Name: "responses",
Help: "Number of successful responses",
})

promLatencyHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "latency_ms",
Help: "gRPC latency distributions in milliseconds.",
// 50 exponential buckets ranging from 0.5 ms to 3 minutes
// TODO: make this tunable
Buckets: prometheus.ExponentialBuckets(0.5, 1.3, 50),
})
promJitterHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "jitter_ms",
Help: "gRPC jitter distributions in milliseconds.",
// 50 exponential buckets ranging from 0.5 ms to 3 minutes
// TODO: make this tunable
Buckets: prometheus.ExponentialBuckets(0.5, 1.3, 50),
})
)

func registerMetrics() {
prometheus.MustRegister(promRequests)
prometheus.MustRegister(promResponses)
prometheus.MustRegister(promLatencyHistogram)
}

func formatBytes(bytes int64) string {
sz := float64(bytes)
Expand Down Expand Up @@ -137,7 +173,9 @@ func sendNonStreamingRequests(client pb.ResponderClient,
Latency: latencyDistribution.Get(r.Int31() % 1000)})

bytes := int64(len([]byte(resp.Body)))
received <- &MeasuredResponse{0, time.Since(start), bytes, err}
latency := time.Since(start)
promLatencyHistogram.Observe(float64(latency))
received <- &MeasuredResponse{0, latency, bytes, err}

if err != nil {
return err
Expand Down Expand Up @@ -200,7 +238,7 @@ func sendStreamingRequests(client pb.ResponderClient,
}

timeBetweenFrames := time.Duration(resp.CurrentFrameSent - resp.LastFrameSent)

promLatencyHistogram.Observe(float64(timeBetweenFrames))
bytes := int64(len([]byte(resp.Body)))
received <- &MeasuredResponse{
timeBetweenFrames,
Expand Down Expand Up @@ -248,6 +286,7 @@ func main() {
onlyFinalReport = flag.Bool("onlyFinalReport", false, "only print the final report, nothing intermediate")
streaming = flag.Bool("streaming", false, "use the streaming features of strest server")
streamingRatio = flag.String("streamingRatio", "1:1", "the ratio of streaming requests/responses")
metricAddr = flag.String("metric-addr", "", "address to serve metrics on")
)

flag.Usage = func() {
Expand Down Expand Up @@ -301,6 +340,14 @@ func main() {
timeout = time.After(*interval)
}

if *metricAddr != "" {
registerMetrics()
go func() {
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(*metricAddr, nil)
}()
}

var wg sync.WaitGroup
wg.Add(*concurrency)

Expand Down Expand Up @@ -368,6 +415,8 @@ func main() {
globalLatencyHist.RecordValue(latency)

jitter := resp.timeBetweenFrames.Nanoseconds() / 1000000
promJitterHistogram.Observe(float64(jitter))

jitterHist.RecordValue(jitter)
globalJitterHist.RecordValue(jitter)
}
Expand Down
Loading

0 comments on commit 010b197

Please sign in to comment.