Sql Server - Disk Space Measurement (#7214)
This commit is contained in:
parent
73911d00f1
commit
c56596dec2
|
@ -48,27 +48,35 @@ GO
|
||||||
|
|
||||||
## Optional parameter, setting this to 2 will use a new version
|
## Optional parameter, setting this to 2 will use a new version
|
||||||
## of the collection queries that break compatibility with the original
|
## of the collection queries that break compatibility with the original
|
||||||
## dashboards. All new functionality is under V2
|
## dashboards.
|
||||||
|
## Version 2 - is compatible from SQL Server 2012 and later versions and also for SQL Azure DB
|
||||||
query_version = 2
|
query_version = 2
|
||||||
|
|
||||||
## If you are using AzureDB, setting this to true will gather resource utilization metrics
|
## If you are using AzureDB, setting this to true will gather resource utilization metrics
|
||||||
# azuredb = true
|
# azuredb = false
|
||||||
|
|
||||||
## Possible queries:
|
## Possible queries
|
||||||
|
## Version 2:
|
||||||
## - PerformanceCounters
|
## - PerformanceCounters
|
||||||
## - WaitStatsCategorized
|
## - WaitStatsCategorized
|
||||||
## - DatabaseIO
|
## - DatabaseIO
|
||||||
## - DatabaseProperties
|
## - ServerProperties
|
||||||
|
## - MemoryClerk
|
||||||
|
## - Schedulers
|
||||||
|
## - SqlRequests
|
||||||
|
## - VolumeSpace
|
||||||
|
## Version 1:
|
||||||
|
## - PerformanceCounters
|
||||||
|
## - WaitStatsCategorized
|
||||||
## - CPUHistory
|
## - CPUHistory
|
||||||
|
## - DatabaseIO
|
||||||
## - DatabaseSize
|
## - DatabaseSize
|
||||||
## - DatabaseStats
|
## - DatabaseStats
|
||||||
|
## - DatabaseProperties
|
||||||
## - MemoryClerk
|
## - MemoryClerk
|
||||||
## - VolumeSpace
|
## - VolumeSpace
|
||||||
## - Schedulers
|
## - PerformanceMetrics
|
||||||
## - AzureDBResourceStats
|
|
||||||
## - AzureDBResourceGovernance
|
|
||||||
## - SqlRequests
|
|
||||||
## - ServerProperties
|
|
||||||
## A list of queries to include. If not specified, all the above listed queries are used.
|
## A list of queries to include. If not specified, all the above listed queries are used.
|
||||||
# include_query = []
|
# include_query = []
|
||||||
|
|
||||||
|
@ -79,7 +87,7 @@ GO
|
||||||
### Metrics:
|
### Metrics:
|
||||||
To provide backwards compatibility, this plugin support two versions of metrics queries.
|
To provide backwards compatibility, this plugin support two versions of metrics queries.
|
||||||
|
|
||||||
**Note**: Version 2 queries are not backwards compatible with the old queries. Any dashboards or queries based on the old query format will not work with the new format. The version 2 queries are written in such a way as to only gather SQL specific metrics (no disk space or overall CPU related metrics) and they only report raw metrics, no math has been done to calculate deltas. To graph this data you must calculate deltas in your dashboarding software.
|
**Note**: Version 2 queries are not backwards compatible with the old queries. Any dashboards or queries based on the old query format will not work with the new format. The version 2 queries are written in such a way as to only gather SQL specific metrics (no overall CPU related metrics) and they only report raw metrics, no math has been done to calculate deltas. To graph this data you must calculate deltas in your dashboarding software.
|
||||||
|
|
||||||
#### Version 1 (deprecated in 1.6):
|
#### Version 1 (deprecated in 1.6):
|
||||||
The original metrics queries provide:
|
The original metrics queries provide:
|
||||||
|
@ -115,6 +123,7 @@ The new (version 2) metrics provide:
|
||||||
- *SqlRequests* - This captures a snapshot of dm_exec_requests and
|
- *SqlRequests* - This captures a snapshot of dm_exec_requests and
|
||||||
dm_exec_sessions that gives you running requests as well as wait types and
|
dm_exec_sessions that gives you running requests as well as wait types and
|
||||||
blocking sessions.
|
blocking sessions.
|
||||||
|
- *VolumeSpace* - uses sys.dm_os_volume_stats to get total, used and occupied space on every disk that contains a data or log file. (Note that even if enabled it won't get any data from Azure SQL Database or SQL Managed Instance). It is pointless to run this with high frequency (ie: every 10s), but it won't cause any problem.
|
||||||
|
|
||||||
In order to allow tracking on a per statement basis this query produces a
|
In order to allow tracking on a per statement basis this query produces a
|
||||||
unique tag for each query. Depending on the database workload, this may
|
unique tag for each query. Depending on the database workload, this may
|
||||||
|
|
|
@ -35,46 +35,53 @@ type MapQuery map[string]Query
|
||||||
const defaultServer = "Server=.;app name=telegraf;log=1;"
|
const defaultServer = "Server=.;app name=telegraf;log=1;"
|
||||||
|
|
||||||
const sampleConfig = `
|
const sampleConfig = `
|
||||||
## Specify instances to monitor with a list of connection strings.
|
## Specify instances to monitor with a list of connection strings.
|
||||||
## All connection parameters are optional.
|
## All connection parameters are optional.
|
||||||
## By default, the host is localhost, listening on default port, TCP 1433.
|
## By default, the host is localhost, listening on default port, TCP 1433.
|
||||||
## for Windows, the user is the currently running AD user (SSO).
|
## for Windows, the user is the currently running AD user (SSO).
|
||||||
## See https://github.com/denisenkom/go-mssqldb for detailed connection
|
## See https://github.com/denisenkom/go-mssqldb for detailed connection
|
||||||
## parameters, in particular, tls connections can be created like so:
|
## parameters, in particular, tls connections can be created like so:
|
||||||
## "encrypt=true;certificate=<cert>;hostNameInCertificate=<SqlServer host fqdn>"
|
## "encrypt=true;certificate=<cert>;hostNameInCertificate=<SqlServer host fqdn>"
|
||||||
# servers = [
|
# servers = [
|
||||||
# "Server=192.168.1.10;Port=1433;User Id=<user>;Password=<pw>;app name=telegraf;log=1;",
|
# "Server=192.168.1.10;Port=1433;User Id=<user>;Password=<pw>;app name=telegraf;log=1;",
|
||||||
# ]
|
# ]
|
||||||
|
|
||||||
## Optional parameter, setting this to 2 will use a new version
|
## Optional parameter, setting this to 2 will use a new version
|
||||||
## of the collection queries that break compatibility with the original
|
## of the collection queries that break compatibility with the original
|
||||||
## dashboards.
|
## dashboards.
|
||||||
query_version = 2
|
## Version 2 - is compatible from SQL Server 2012 and later versions and also for SQL Azure DB
|
||||||
|
query_version = 2
|
||||||
|
|
||||||
## If you are using AzureDB, setting this to true will gather resource utilization metrics
|
## If you are using AzureDB, setting this to true will gather resource utilization metrics
|
||||||
# azuredb = false
|
# azuredb = false
|
||||||
|
|
||||||
## Possible queries:
|
## Possible queries
|
||||||
## - PerformanceCounters
|
## Version 2:
|
||||||
## - WaitStatsCategorized
|
## - PerformanceCounters
|
||||||
## - DatabaseIO
|
## - WaitStatsCategorized
|
||||||
## - DatabaseProperties
|
## - DatabaseIO
|
||||||
## - CPUHistory
|
## - ServerProperties
|
||||||
## - DatabaseSize
|
## - MemoryClerk
|
||||||
## - DatabaseStats
|
## - Schedulers
|
||||||
## - MemoryClerk
|
## - SqlRequests
|
||||||
## - VolumeSpace
|
## - VolumeSpace
|
||||||
## - PerformanceMetrics
|
## Version 1:
|
||||||
## - Schedulers
|
## - PerformanceCounters
|
||||||
## - AzureDBResourceStats
|
## - WaitStatsCategorized
|
||||||
## - AzureDBResourceGovernance
|
## - CPUHistory
|
||||||
## - SqlRequests
|
## - DatabaseIO
|
||||||
## - ServerProperties
|
## - DatabaseSize
|
||||||
## A list of queries to include. If not specified, all the above listed queries are used.
|
## - DatabaseStats
|
||||||
# include_query = []
|
## - DatabaseProperties
|
||||||
|
## - MemoryClerk
|
||||||
|
## - VolumeSpace
|
||||||
|
## - PerformanceMetrics
|
||||||
|
|
||||||
## A list of queries to explicitly ignore.
|
## A list of queries to include. If not specified, all the above listed queries are used.
|
||||||
exclude_query = [ 'Schedulers' , 'SqlRequests']
|
# include_query = []
|
||||||
|
|
||||||
|
## A list of queries to explicitly ignore.
|
||||||
|
exclude_query = [ 'Schedulers' , 'SqlRequests']
|
||||||
`
|
`
|
||||||
|
|
||||||
// SampleConfig return the sample configuration
|
// SampleConfig return the sample configuration
|
||||||
|
@ -109,6 +116,7 @@ func initQueries(s *SQLServer) error {
|
||||||
queries["MemoryClerk"] = Query{Script: sqlMemoryClerkV2, ResultByRow: false}
|
queries["MemoryClerk"] = Query{Script: sqlMemoryClerkV2, ResultByRow: false}
|
||||||
queries["Schedulers"] = Query{Script: sqlServerSchedulersV2, ResultByRow: false}
|
queries["Schedulers"] = Query{Script: sqlServerSchedulersV2, ResultByRow: false}
|
||||||
queries["SqlRequests"] = Query{Script: sqlServerRequestsV2, ResultByRow: false}
|
queries["SqlRequests"] = Query{Script: sqlServerRequestsV2, ResultByRow: false}
|
||||||
|
queries["VolumeSpace"] = Query{Script: sqlServerVolumeSpaceV2, ResultByRow: false}
|
||||||
} else {
|
} else {
|
||||||
queries["PerformanceCounters"] = Query{Script: sqlPerformanceCounters, ResultByRow: true}
|
queries["PerformanceCounters"] = Query{Script: sqlPerformanceCounters, ResultByRow: true}
|
||||||
queries["WaitStatsCategorized"] = Query{Script: sqlWaitStatsCategorized, ResultByRow: false}
|
queries["WaitStatsCategorized"] = Query{Script: sqlWaitStatsCategorized, ResultByRow: false}
|
||||||
|
@ -1554,6 +1562,37 @@ SELECT
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const sqlServerVolumeSpaceV2 string = `
|
||||||
|
/* Only for on-prem version of SQL Server
|
||||||
|
Gets data about disk space, only if the disk is used by SQL Server
|
||||||
|
EngineEdition:
|
||||||
|
1 = Personal or Desktop Engine
|
||||||
|
2 = Standard
|
||||||
|
3 = Enterprise
|
||||||
|
4 = Express
|
||||||
|
5 = SQL Database
|
||||||
|
6 = SQL Data Warehouse
|
||||||
|
8 = Managed Instance
|
||||||
|
*/
|
||||||
|
IF SERVERPROPERTY('EngineEdition') NOT IN (5,8)
|
||||||
|
BEGIN
|
||||||
|
SELECT DISTINCT
|
||||||
|
'sqlserver_disk_space' AS [measurement]
|
||||||
|
,SERVERPROPERTY('machinename') AS [server_name]
|
||||||
|
,REPLACE(@@SERVERNAME,'\',':') AS [sql_instance]
|
||||||
|
,IIF( RIGHT(vs.[volume_mount_point],1) = '\' /*Tag value cannot end with \ */
|
||||||
|
,LEFT(vs.[volume_mount_point],LEN(vs.[volume_mount_point])-1)
|
||||||
|
,vs.[volume_mount_point]
|
||||||
|
) AS [volume_mount_point]
|
||||||
|
,vs.[total_bytes] AS [total_space_bytes]
|
||||||
|
,vs.[available_bytes] AS [available_space_bytes]
|
||||||
|
,vs.[total_bytes] - vs.[available_bytes] AS [used_space_bytes]
|
||||||
|
FROM
|
||||||
|
sys.master_files as mf
|
||||||
|
CROSS APPLY sys.dm_os_volume_stats(mf.database_id, mf.file_id) as vs
|
||||||
|
END
|
||||||
|
`
|
||||||
|
|
||||||
// Queries V1
|
// Queries V1
|
||||||
const sqlPerformanceMetrics string = `SET DEADLOCK_PRIORITY -10;
|
const sqlPerformanceMetrics string = `SET DEADLOCK_PRIORITY -10;
|
||||||
SET NOCOUNT ON;
|
SET NOCOUNT ON;
|
||||||
|
|
|
@ -16,13 +16,13 @@ func TestSqlServer_QueriesInclusionExclusion(t *testing.T) {
|
||||||
cases := []map[string]interface{}{
|
cases := []map[string]interface{}{
|
||||||
{
|
{
|
||||||
"IncludeQuery": []string{},
|
"IncludeQuery": []string{},
|
||||||
"ExcludeQuery": []string{"WaitStatsCategorized", "DatabaseIO", "ServerProperties", "MemoryClerk", "Schedulers"},
|
"ExcludeQuery": []string{"WaitStatsCategorized", "DatabaseIO", "ServerProperties", "MemoryClerk", "Schedulers", "VolumeSpace"},
|
||||||
"queries": []string{"PerformanceCounters", "SqlRequests"},
|
"queries": []string{"PerformanceCounters", "SqlRequests"},
|
||||||
"queriesTotal": 2,
|
"queriesTotal": 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"IncludeQuery": []string{"PerformanceCounters", "SqlRequests"},
|
"IncludeQuery": []string{"PerformanceCounters", "SqlRequests"},
|
||||||
"ExcludeQuery": []string{"SqlRequests", "WaitStatsCategorized", "DatabaseIO"},
|
"ExcludeQuery": []string{"SqlRequests", "WaitStatsCategorized", "DatabaseIO", "VolumeSpace"},
|
||||||
"queries": []string{"PerformanceCounters"},
|
"queries": []string{"PerformanceCounters"},
|
||||||
"queriesTotal": 1,
|
"queriesTotal": 1,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue