Documentation ¶
Overview ¶
Package metrics provides setup of metrics that can be used internally to measure various application states. All metrics for the application are defined here and other applications use this package to grab the metrics and use them. This package will also report any metric that is not used in the first 10 seconds after the app has started to prevent useless metrics from existing, as all metrics should be grabbed by that time.
In a package you want to set metrics, you can do it as follows:
var addCount metrics.Int64Counter func init() { addCounter = metrics.Get.Int64("petstore/server/AddPets/requests") } ... func (s *Server) AddPets(ctx context.Context, req *pb.AddPetsReq) (*pb.AddpetsResp, error) { ... // Do this if you have multiple changes that don't require special labels per update. metrics.Meter.RecordBatch(ctx, nil, addCounter.Measure(ctx, 1)) // Do this if you only need to make one change or need special labels. addCounter.Add(ctx, 1, attribute.String("label", "value") ... }
To cause metrics to be exported package main():
func main() { ... stop, err := metrics.Start(ctx, metrics.OTELGRPC{Addr: "ip:port"}) if err != nil { log.Fatal(err) } defer stop() ... }
Index ¶
- Variables
- type Controller
- type Lookups
- func (l *Lookups) Int64(s string) metric.Int64Counter
- func (l *Lookups) Int64Hist(s string) metric.Int64Histogram
- func (l *Lookups) Int64Hists(s ...string) []metric.Int64Histogram
- func (l *Lookups) Int64UD(s string) metric.Int64UpDownCounter
- func (l *Lookups) Int64UDs(s ...string) []metric.Int64UpDownCounter
- func (l *Lookups) Int64s(s ...string) []metric.Int64Counter
- type OTELGRPC
- type Stop
Constants ¶
This section is empty.
Variables ¶
var Get = newLookups()
Get is used to lookup metrics by name.
var Meter = global.Meter("petstore")
Meter is the meter for the petstore.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller interface {
// contains filtered or unexported methods
}
Controller represents the controller to send metrics to.
type Lookups ¶
type Lookups struct {
// contains filtered or unexported fields
}
Lookups provides lookups for metrics based on their names.
func (*Lookups) Int64 ¶
func (l *Lookups) Int64(s string) metric.Int64Counter
Int64 grabs the Int64Counter metric named "s". If not found, panics.
func (*Lookups) Int64Hist ¶
func (l *Lookups) Int64Hist(s string) metric.Int64Histogram
Int64Hist grabs the Int64Histogram metric named "s". If not found, panics.
func (*Lookups) Int64Hists ¶
func (l *Lookups) Int64Hists(s ...string) []metric.Int64Histogram
func (*Lookups) Int64UD ¶
func (l *Lookups) Int64UD(s string) metric.Int64UpDownCounter
Int64UD grabs the Int64UpDownCounter metric named "s". If not found, panics.