...

Source file src/go.opencensus.io/internal/readme/stats.go

Documentation: go.opencensus.io/internal/readme

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

View as plain text