Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugins/inputs/sqlserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ to use them.
## and following as optional (if mentioned in the include_query list)
## - SQLServerAvailabilityReplicaStates
## - SQLServerDatabaseReplicaStates

## Maximum number of open connections to the database, 0 allows the driver to decide.
# max_open_connections = 0

## Maximum number of idle connections in the connection pool, 0 allows the driver to decide.
# max_idle_connections = 0
```

### Additional Setup
Expand Down
6 changes: 6 additions & 0 deletions plugins/inputs/sqlserver/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@
## and following as optional (if mentioned in the include_query list)
## - SQLServerAvailabilityReplicaStates
## - SQLServerDatabaseReplicaStates

## Maximum number of open connections to the database, 0 allows the driver to decide.
# max_open_connections = 0

## Maximum number of idle connections in the connection pool, 0 allows the driver to decide.
# max_idle_connections = 0
30 changes: 21 additions & 9 deletions plugins/inputs/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ const (
)

type SQLServer struct {
Servers []*config.Secret `toml:"servers"`
QueryTimeout config.Duration `toml:"query_timeout"`
AuthMethod string `toml:"auth_method"`
ClientID string `toml:"client_id"`
DatabaseType string `toml:"database_type"`
IncludeQuery []string `toml:"include_query"`
ExcludeQuery []string `toml:"exclude_query"`
HealthMetric bool `toml:"health_metric"`
Log telegraf.Logger `toml:"-"`
Servers []*config.Secret `toml:"servers"`
QueryTimeout config.Duration `toml:"query_timeout"`
AuthMethod string `toml:"auth_method"`
ClientID string `toml:"client_id"`
DatabaseType string `toml:"database_type"`
IncludeQuery []string `toml:"include_query"`
ExcludeQuery []string `toml:"exclude_query"`
HealthMetric bool `toml:"health_metric"`
MaxOpenConnections int `toml:"max_open_connections"`
MaxIdleConnections int `toml:"max_idle_connections"`
Log telegraf.Logger `toml:"-"`

pools []*sql.DB
queries mapQuery
Expand Down Expand Up @@ -168,6 +170,16 @@ func (s *SQLServer) Start(acc telegraf.Accumulator) error {
return fmt.Errorf("unknown auth method: %v", s.AuthMethod)
}

// Use max_open_connections if any
if s.MaxOpenConnections > 0 {
pool.SetMaxOpenConns(s.MaxOpenConnections)
}

// Use max_idle_connections if any
if s.MaxIdleConnections > 0 {
pool.SetMaxIdleConns(s.MaxIdleConnections)
}

s.pools = append(s.pools, pool)
}

Expand Down
Loading