Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/prometheus/exporter/mssql/mssql.go
4096 views
1
package mssql
2
3
import (
4
"errors"
5
"time"
6
7
"github.com/grafana/agent/component"
8
"github.com/grafana/agent/component/prometheus/exporter"
9
"github.com/grafana/agent/pkg/integrations"
10
"github.com/grafana/agent/pkg/integrations/mssql"
11
"github.com/grafana/agent/pkg/river/rivertypes"
12
config_util "github.com/prometheus/common/config"
13
)
14
15
func init() {
16
component.Register(component.Registration{
17
Name: "prometheus.exporter.mssql",
18
Args: Arguments{},
19
Exports: exporter.Exports{},
20
Build: exporter.New(createExporter, "mssql"),
21
})
22
}
23
24
func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, error) {
25
a := args.(Arguments)
26
return a.Convert().NewIntegration(opts.Logger)
27
}
28
29
// DefaultArguments holds the default settings for the mssql exporter
30
var DefaultArguments = Arguments{
31
MaxIdleConnections: 3,
32
MaxOpenConnections: 3,
33
Timeout: 10 * time.Second,
34
}
35
36
// Arguments controls the mssql exporter.
37
type Arguments struct {
38
ConnectionString rivertypes.Secret `river:"connection_string,attr"`
39
MaxIdleConnections int `river:"max_idle_connections,attr,optional"`
40
MaxOpenConnections int `river:"max_open_connections,attr,optional"`
41
Timeout time.Duration `river:"timeout,attr,optional"`
42
}
43
44
// UnmarshalRiver implements River unmarshalling for Arguments.
45
func (a *Arguments) UnmarshalRiver(f func(interface{}) error) error {
46
*a = DefaultArguments
47
48
type args Arguments
49
if err := f((*args)(a)); err != nil {
50
return err
51
}
52
return a.Validate()
53
}
54
55
func (a *Arguments) Validate() error {
56
if a.MaxOpenConnections < 1 {
57
return errors.New("max_open_connections must be at least 1")
58
}
59
60
if a.MaxIdleConnections < 1 {
61
return errors.New("max_idle_connections must be at least 1")
62
}
63
64
if a.Timeout <= 0 {
65
return errors.New("timeout must be positive")
66
}
67
return nil
68
}
69
70
func (a *Arguments) Convert() *mssql.Config {
71
return &mssql.Config{
72
ConnectionString: config_util.Secret(a.ConnectionString),
73
MaxIdleConnections: a.MaxIdleConnections,
74
MaxOpenConnections: a.MaxOpenConnections,
75
Timeout: a.Timeout,
76
}
77
}
78
79