example_metrics_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package clientv3_test
  15. import (
  16. "fmt"
  17. "io/ioutil"
  18. "log"
  19. "net/http"
  20. "github.com/prometheus/client_golang/prometheus"
  21. )
  22. func ExampleMetrics_All() {
  23. // listen for all prometheus metrics
  24. go func() {
  25. http.Handle("/metrics", prometheus.Handler())
  26. log.Fatal(http.ListenAndServe(":47989", nil))
  27. }()
  28. url := "http://localhost:47989/metrics"
  29. // make an http request to fetch all prometheus metrics
  30. resp, err := http.Get(url)
  31. if err != nil {
  32. log.Fatalf("fetch error: %v", err)
  33. }
  34. b, err := ioutil.ReadAll(resp.Body)
  35. resp.Body.Close()
  36. if err != nil {
  37. log.Fatalf("fetch error: reading %s: %v", url, err)
  38. }
  39. fmt.Printf("%s", b)
  40. }