stats.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2017, OpenCensus 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 readme generates the README.
  15. package readme // import "go.opencensus.io/internal/readme"
  16. import (
  17. "context"
  18. "log"
  19. "go.opencensus.io/stats"
  20. "go.opencensus.io/stats/view"
  21. )
  22. // README.md is generated with the examples here by using embedmd.
  23. // For more details, see https://github.com/rakyll/embedmd.
  24. func statsExamples() {
  25. ctx := context.Background()
  26. videoSize := stats.Int64("example.com/video_size", "processed video size", "MB")
  27. // START aggs
  28. distAgg := view.Distribution(1<<32, 2<<32, 3<<32)
  29. countAgg := view.Count()
  30. sumAgg := view.Sum()
  31. // END aggs
  32. _, _, _ = distAgg, countAgg, sumAgg
  33. // START view
  34. if err := view.Register(&view.View{
  35. Name: "example.com/video_size_distribution",
  36. Description: "distribution of processed video size over time",
  37. Measure: videoSize,
  38. Aggregation: view.Distribution(1<<32, 2<<32, 3<<32),
  39. }); err != nil {
  40. log.Fatalf("Failed to register view: %v", err)
  41. }
  42. // END view
  43. // START record
  44. stats.Record(ctx, videoSize.M(102478))
  45. // END record
  46. }