Path: blob/main/component/prometheus/exporter/mssql/mssql.go
4096 views
package mssql12import (3"errors"4"time"56"github.com/grafana/agent/component"7"github.com/grafana/agent/component/prometheus/exporter"8"github.com/grafana/agent/pkg/integrations"9"github.com/grafana/agent/pkg/integrations/mssql"10"github.com/grafana/agent/pkg/river/rivertypes"11config_util "github.com/prometheus/common/config"12)1314func init() {15component.Register(component.Registration{16Name: "prometheus.exporter.mssql",17Args: Arguments{},18Exports: exporter.Exports{},19Build: exporter.New(createExporter, "mssql"),20})21}2223func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, error) {24a := args.(Arguments)25return a.Convert().NewIntegration(opts.Logger)26}2728// DefaultArguments holds the default settings for the mssql exporter29var DefaultArguments = Arguments{30MaxIdleConnections: 3,31MaxOpenConnections: 3,32Timeout: 10 * time.Second,33}3435// Arguments controls the mssql exporter.36type Arguments struct {37ConnectionString rivertypes.Secret `river:"connection_string,attr"`38MaxIdleConnections int `river:"max_idle_connections,attr,optional"`39MaxOpenConnections int `river:"max_open_connections,attr,optional"`40Timeout time.Duration `river:"timeout,attr,optional"`41}4243// UnmarshalRiver implements River unmarshalling for Arguments.44func (a *Arguments) UnmarshalRiver(f func(interface{}) error) error {45*a = DefaultArguments4647type args Arguments48if err := f((*args)(a)); err != nil {49return err50}51return a.Validate()52}5354func (a *Arguments) Validate() error {55if a.MaxOpenConnections < 1 {56return errors.New("max_open_connections must be at least 1")57}5859if a.MaxIdleConnections < 1 {60return errors.New("max_idle_connections must be at least 1")61}6263if a.Timeout <= 0 {64return errors.New("timeout must be positive")65}66return nil67}6869func (a *Arguments) Convert() *mssql.Config {70return &mssql.Config{71ConnectionString: config_util.Secret(a.ConnectionString),72MaxIdleConnections: a.MaxIdleConnections,73MaxOpenConnections: a.MaxOpenConnections,74Timeout: a.Timeout,75}76}777879