/
options.go
116 lines (100 loc) · 2.39 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package meter
import (
"context"
"github.com/unistack-org/micro/v3/logger"
)
// Option powers the configuration for metrics implementations:
type Option func(*Options)
// Options for metrics implementations:
type Options struct {
// Logger used for logging
Logger logger.Logger
// Context holds external options
Context context.Context
// Name holds the meter name
Name string
// Address holds the address that serves metrics
Address string
// Path holds the path for metrics
Path string
// MetricPrefix holds the prefix for all metrics
MetricPrefix string
// LabelPrefix holds the prefix for all labels
LabelPrefix string
// Labels holds the default labels
Labels []string
// WriteProcessMetrics flag to write process metrics
WriteProcessMetrics bool
// WriteFDMetrics flag to write fd metrics
WriteFDMetrics bool
}
// NewOptions prepares a set of options:
func NewOptions(opt ...Option) Options {
opts := Options{
Address: DefaultAddress,
Path: DefaultPath,
Context: context.Background(),
Logger: logger.DefaultLogger,
MetricPrefix: DefaultMetricPrefix,
LabelPrefix: DefaultLabelPrefix,
}
for _, o := range opt {
o(&opts)
}
return opts
}
// Context sets the metrics context
func Context(ctx context.Context) Option {
return func(o *Options) {
o.Context = ctx
}
}
// Path used to serve metrics over HTTP
func Path(value string) Option {
return func(o *Options) {
o.Path = value
}
}
// Address is the listen address to serve metrics
func Address(value string) Option {
return func(o *Options) {
o.Address = value
}
}
/*
// TimingObjectives defines the desired spread of statistics for histogram / timing metrics:
func TimingObjectives(value map[float64]float64) Option {
return func(o *Options) {
o.TimingObjectives = value
}
}
*/
// Logger sets the logger
func Logger(l logger.Logger) Option {
return func(o *Options) {
o.Logger = l
}
}
func Labels(ls ...string) Option {
return func(o *Options) {
o.Labels = append(o.Labels, ls...)
}
}
// Name sets the name
func Name(n string) Option {
return func(o *Options) {
o.Name = n
}
}
// WriteProcessMetrics enable process metrics output for write
func WriteProcessMetrics(b bool) Option {
return func(o *Options) {
o.WriteProcessMetrics = b
}
}
// WriteFDMetrics enable fd metrics output for write
func WriteFDMetrics(b bool) Option {
return func(o *Options) {
o.WriteFDMetrics = b
}
}