Skip to content

Instantly share code, notes, and snippets.

@bfink13
Created February 9, 2021 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bfink13/df7a72b46ce5c21ae9888ff60a36d54e to your computer and use it in GitHub Desktop.
Save bfink13/df7a72b46ce5c21ae9888ff60a36d54e to your computer and use it in GitHub Desktop.
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package main
import (
"crypto/tls"
"log"
"time"
"go.mongodb.org/mongo-driver/x/mongo/driver/address"
"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
)
func main() {
s, err := topology.ConnectServer(
address.Address("localhost:27017"),
nil,
topology.WithHeartbeatInterval(func(time.Duration) time.Duration { return 1 * time.Second }),
topology.WithConnectionOptions(func(...topology.ConnectionOption) []topology.ConnectionOption {
return []topology.ConnectionOption{topology.WithTLSConfig(func(c *tls.Config) *tls.Config { return &tls.Config{InsecureSkipVerify: true} })}
}),
)
if err != nil {
log.Fatalf("could not start server: %v", err)
}
sub, err := s.Subscribe()
if err != nil {
log.Fatalf("could not subscribe to server: %v", err)
}
for desc := range sub.C {
avgrtt := desc.AverageRTT
avgrttset := desc.AverageRTTSet
log.Printf("Average RTT: %v set: %v", avgrtt.Nanoseconds(), avgrttset)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment