You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  1. package redisprom
  2. type (
  3. // Options represents options to customize the exported metrics.
  4. Options struct {
  5. InstanceName string
  6. Namespace string
  7. DurationBuckets []float64
  8. }
  9. Option func(*Options)
  10. )
  11. // DefaultOptions returns the default options.
  12. func DefaultOptions() *Options {
  13. return &Options{
  14. InstanceName: "unnamed",
  15. Namespace: "",
  16. DurationBuckets: []float64{.001, .005, .01, .025, .05, .1, .25, .5, 1},
  17. }
  18. }
  19. func (options *Options) Merge(opts ...Option) {
  20. for _, opt := range opts {
  21. opt(options)
  22. }
  23. }
  24. // WithInstanceName sets the name of the Redis instance.
  25. func WithInstanceName(name string) Option {
  26. return func(options *Options) {
  27. options.InstanceName = name
  28. }
  29. }
  30. // WithNamespace sets the namespace of all metrics.
  31. func WithNamespace(namespace string) Option {
  32. return func(options *Options) {
  33. options.Namespace = namespace
  34. }
  35. }
  36. // WithDurationBuckets sets the duration buckets of single commands metrics.
  37. func WithDurationBuckets(buckets []float64) Option {
  38. return func(options *Options) {
  39. options.DurationBuckets = buckets
  40. }
  41. }