Import path:
gitlab.soludian.com/soludian/fountain/libs/metrics/cloudwatch
cloudwatch
import "gitlab.soludian.com/soludian/fountain/libs/metrics/cloudwatch"Index
- type CloudWatch
- func New(namespace string, svc CloudWatchAPI, options ...Option) *CloudWatch
- func (cw *CloudWatch) NewCounter(name string) metrics.Counter
- func (cw *CloudWatch) NewGauge(name string) metrics.Gauge
- func (cw *CloudWatch) NewHistogram(name string) metrics.Histogram
- func (cw *CloudWatch) Send(ctx context.Context) error
- func (cw *CloudWatch) WriteLoop(ctx context.Context, c <-chan time.Time)
- type CloudWatchAPI
- type Counter
- type Gauge
- type Histogram
- type Option
type CloudWatch
CloudWatch receives metrics observations and forwards them to CloudWatch. Create a CloudWatch object, use it to create metrics, and pass those metrics as dependencies to the components that will use them.
To regularly report metrics to CloudWatch, use the WriteLoop helper method.
type CloudWatch struct {
// contains filtered or unexported fields
}func New
func New(namespace string, svc CloudWatchAPI, options ...Option) *CloudWatchNew returns a CloudWatch object that may be used to create metrics. Namespace is applied to all created metrics and maps to the CloudWatch namespace. Callers must ensure that regular calls to Send are performed, either manually or with one of the helper methods.
func (*CloudWatch) NewCounter
func (cw *CloudWatch) NewCounter(name string) metrics.CounterNewCounter returns a counter. Observations are aggregated and emitted once per write invocation.
func (*CloudWatch) NewGauge
func (cw *CloudWatch) NewGauge(name string) metrics.GaugeNewGauge returns an gauge.
func (*CloudWatch) NewHistogram
func (cw *CloudWatch) NewHistogram(name string) metrics.HistogramNewHistogram returns a histogram.
func (*CloudWatch) Send
func (cw *CloudWatch) Send(ctx context.Context) errorfunc (*CloudWatch) WriteLoop
func (cw *CloudWatch) WriteLoop(ctx context.Context, c <-chan time.Time)WriteLoop is a helper method that invokes Send every time the passed channel fires. This method blocks until ctx is canceled, so clients probably want to run it in its own goroutine. For typical usage, create a time.Ticker and pass its C channel to this method.
type CloudWatchAPI
Định nghĩa interface thay thế cho cloudwatchiface.CloudWatchAPI
type CloudWatchAPI interface {
PutMetricData(ctx context.Context, params *cloudwatch.PutMetricDataInput, optFns ...func(*cloudwatch.Options)) (*cloudwatch.PutMetricDataOutput, error)
}type Counter
Counter is a counter. Observations are forwarded to a node object, and aggregated (summed) per time series.
type Counter struct {
// contains filtered or unexported fields
}func (*Counter) Add
func (c *Counter) Add(delta float64)Add implements metrics.Counter.
func (*Counter) With
func (c *Counter) With(labelValues ...string) metrics.CounterWith implements metrics.Counter.
type Gauge
Gauge is a gauge. Observations are forwarded to a node object, and aggregated (the last observation selected) per time series.
type Gauge struct {
// contains filtered or unexported fields
}func (*Gauge) Add
func (g *Gauge) Add(delta float64)Add implements metrics.Gauge.
func (*Gauge) Set
func (g *Gauge) Set(value float64)Set implements metrics.Gauge.
func (*Gauge) With
func (g *Gauge) With(labelValues ...string) metrics.GaugeWith implements metrics.Gauge.
type Histogram
Histogram is an Influx histrogram. Observations are aggregated into a generic.Histogram and emitted as per-quantile gauges to the Influx server.
type Histogram struct {
// contains filtered or unexported fields
}func (*Histogram) Observe
func (h *Histogram) Observe(value float64)Observe implements metrics.Histogram.
func (*Histogram) With
func (h *Histogram) With(labelValues ...string) metrics.HistogramWith implements metrics.Histogram.
type Option
Option is a function adapter to change config of the CloudWatch struct
type Option func(*CloudWatch)func WithConcurrentRequests
func WithConcurrentRequests(n int) OptionWithConcurrentRequests sets the upper limit on how many cloudwatch.PutMetricDataRequest may be under way at any given time. If n is greater than 20, 20 is used. By default, the max is set at 10 concurrent requests.
func WithLogger
func WithLogger(logger flog.FlogInf) OptionWithLogger sets the Logger that will receive error messages generated during the WriteLoop. By default, fmt logger is used.
func WithPercentiles
func WithPercentiles(percentiles ...float64) OptionWithPercentiles registers the percentiles to track, overriding the existing/default values. Reason is that Cloudwatch makes you pay per metric, so you can save half the money by only using 2 metrics instead of the default 4.
Generated by gomarkdoc