metrics.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Package metrics defines the metrics APIs used by Smithy clients.
  2. package metrics
  3. import (
  4. "context"
  5. "github.com/aws/smithy-go"
  6. )
  7. // MeterProvider is the entry point for creating a Meter.
  8. type MeterProvider interface {
  9. Meter(scope string, opts ...MeterOption) Meter
  10. }
  11. // MeterOption applies configuration to a Meter.
  12. type MeterOption func(o *MeterOptions)
  13. // MeterOptions represents configuration for a Meter.
  14. type MeterOptions struct {
  15. Properties smithy.Properties
  16. }
  17. // Meter is the entry point for creation of measurement instruments.
  18. type Meter interface {
  19. // integer/synchronous
  20. Int64Counter(name string, opts ...InstrumentOption) (Int64Counter, error)
  21. Int64UpDownCounter(name string, opts ...InstrumentOption) (Int64UpDownCounter, error)
  22. Int64Gauge(name string, opts ...InstrumentOption) (Int64Gauge, error)
  23. Int64Histogram(name string, opts ...InstrumentOption) (Int64Histogram, error)
  24. // integer/asynchronous
  25. Int64AsyncCounter(name string, callback Int64Callback, opts ...InstrumentOption) (AsyncInstrument, error)
  26. Int64AsyncUpDownCounter(name string, callback Int64Callback, opts ...InstrumentOption) (AsyncInstrument, error)
  27. Int64AsyncGauge(name string, callback Int64Callback, opts ...InstrumentOption) (AsyncInstrument, error)
  28. // floating-point/synchronous
  29. Float64Counter(name string, opts ...InstrumentOption) (Float64Counter, error)
  30. Float64UpDownCounter(name string, opts ...InstrumentOption) (Float64UpDownCounter, error)
  31. Float64Gauge(name string, opts ...InstrumentOption) (Float64Gauge, error)
  32. Float64Histogram(name string, opts ...InstrumentOption) (Float64Histogram, error)
  33. // floating-point/asynchronous
  34. Float64AsyncCounter(name string, callback Float64Callback, opts ...InstrumentOption) (AsyncInstrument, error)
  35. Float64AsyncUpDownCounter(name string, callback Float64Callback, opts ...InstrumentOption) (AsyncInstrument, error)
  36. Float64AsyncGauge(name string, callback Float64Callback, opts ...InstrumentOption) (AsyncInstrument, error)
  37. }
  38. // InstrumentOption applies configuration to an instrument.
  39. type InstrumentOption func(o *InstrumentOptions)
  40. // InstrumentOptions represents configuration for an instrument.
  41. type InstrumentOptions struct {
  42. UnitLabel string
  43. Description string
  44. }
  45. // Int64Counter measures a monotonically increasing int64 value.
  46. type Int64Counter interface {
  47. Add(context.Context, int64, ...RecordMetricOption)
  48. }
  49. // Int64UpDownCounter measures a fluctuating int64 value.
  50. type Int64UpDownCounter interface {
  51. Add(context.Context, int64, ...RecordMetricOption)
  52. }
  53. // Int64Gauge samples a discrete int64 value.
  54. type Int64Gauge interface {
  55. Sample(context.Context, int64, ...RecordMetricOption)
  56. }
  57. // Int64Histogram records multiple data points for an int64 value.
  58. type Int64Histogram interface {
  59. Record(context.Context, int64, ...RecordMetricOption)
  60. }
  61. // Float64Counter measures a monotonically increasing float64 value.
  62. type Float64Counter interface {
  63. Add(context.Context, float64, ...RecordMetricOption)
  64. }
  65. // Float64UpDownCounter measures a fluctuating float64 value.
  66. type Float64UpDownCounter interface {
  67. Add(context.Context, float64, ...RecordMetricOption)
  68. }
  69. // Float64Gauge samples a discrete float64 value.
  70. type Float64Gauge interface {
  71. Sample(context.Context, float64, ...RecordMetricOption)
  72. }
  73. // Float64Histogram records multiple data points for an float64 value.
  74. type Float64Histogram interface {
  75. Record(context.Context, float64, ...RecordMetricOption)
  76. }
  77. // AsyncInstrument is the universal handle returned for creation of all async
  78. // instruments.
  79. //
  80. // Callers use the Stop() API to unregister the callback passed at instrument
  81. // creation.
  82. type AsyncInstrument interface {
  83. Stop()
  84. }
  85. // Int64Callback describes a function invoked when an async int64 instrument is
  86. // read.
  87. type Int64Callback func(context.Context, Int64Observer)
  88. // Int64Observer is the interface passed to async int64 instruments.
  89. //
  90. // Callers use the Observe() API of this interface to report metrics to the
  91. // underlying collector.
  92. type Int64Observer interface {
  93. Observe(context.Context, int64, ...RecordMetricOption)
  94. }
  95. // Float64Callback describes a function invoked when an async float64
  96. // instrument is read.
  97. type Float64Callback func(context.Context, Float64Observer)
  98. // Float64Observer is the interface passed to async int64 instruments.
  99. //
  100. // Callers use the Observe() API of this interface to report metrics to the
  101. // underlying collector.
  102. type Float64Observer interface {
  103. Observe(context.Context, float64, ...RecordMetricOption)
  104. }
  105. // RecordMetricOption applies configuration to a recorded metric.
  106. type RecordMetricOption func(o *RecordMetricOptions)
  107. // RecordMetricOptions represents configuration for a recorded metric.
  108. type RecordMetricOptions struct {
  109. Properties smithy.Properties
  110. }