Sql Server - Disk Space Measurement (#7214)
This commit is contained in:
committed by
GitHub
parent
73911d00f1
commit
c56596dec2
@@ -35,46 +35,53 @@ type MapQuery map[string]Query
|
||||
const defaultServer = "Server=.;app name=telegraf;log=1;"
|
||||
|
||||
const sampleConfig = `
|
||||
## Specify instances to monitor with a list of connection strings.
|
||||
## All connection parameters are optional.
|
||||
## By default, the host is localhost, listening on default port, TCP 1433.
|
||||
## for Windows, the user is the currently running AD user (SSO).
|
||||
## See https://github.com/denisenkom/go-mssqldb for detailed connection
|
||||
## parameters, in particular, tls connections can be created like so:
|
||||
## "encrypt=true;certificate=<cert>;hostNameInCertificate=<SqlServer host fqdn>"
|
||||
# servers = [
|
||||
# "Server=192.168.1.10;Port=1433;User Id=<user>;Password=<pw>;app name=telegraf;log=1;",
|
||||
# ]
|
||||
## Specify instances to monitor with a list of connection strings.
|
||||
## All connection parameters are optional.
|
||||
## By default, the host is localhost, listening on default port, TCP 1433.
|
||||
## for Windows, the user is the currently running AD user (SSO).
|
||||
## See https://github.com/denisenkom/go-mssqldb for detailed connection
|
||||
## parameters, in particular, tls connections can be created like so:
|
||||
## "encrypt=true;certificate=<cert>;hostNameInCertificate=<SqlServer host fqdn>"
|
||||
# servers = [
|
||||
# "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
|
||||
## of the collection queries that break compatibility with the original
|
||||
## dashboards.
|
||||
query_version = 2
|
||||
## Optional parameter, setting this to 2 will use a new version
|
||||
## of the collection queries that break compatibility with the original
|
||||
## dashboards.
|
||||
## 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
|
||||
# azuredb = false
|
||||
## If you are using AzureDB, setting this to true will gather resource utilization metrics
|
||||
# azuredb = false
|
||||
|
||||
## Possible queries:
|
||||
## - PerformanceCounters
|
||||
## - WaitStatsCategorized
|
||||
## - DatabaseIO
|
||||
## - DatabaseProperties
|
||||
## - CPUHistory
|
||||
## - DatabaseSize
|
||||
## - DatabaseStats
|
||||
## - MemoryClerk
|
||||
## - VolumeSpace
|
||||
## - PerformanceMetrics
|
||||
## - Schedulers
|
||||
## - AzureDBResourceStats
|
||||
## - AzureDBResourceGovernance
|
||||
## - SqlRequests
|
||||
## - ServerProperties
|
||||
## A list of queries to include. If not specified, all the above listed queries are used.
|
||||
# include_query = []
|
||||
## Possible queries
|
||||
## Version 2:
|
||||
## - PerformanceCounters
|
||||
## - WaitStatsCategorized
|
||||
## - DatabaseIO
|
||||
## - ServerProperties
|
||||
## - MemoryClerk
|
||||
## - Schedulers
|
||||
## - SqlRequests
|
||||
## - VolumeSpace
|
||||
## Version 1:
|
||||
## - PerformanceCounters
|
||||
## - WaitStatsCategorized
|
||||
## - CPUHistory
|
||||
## - DatabaseIO
|
||||
## - DatabaseSize
|
||||
## - DatabaseStats
|
||||
## - DatabaseProperties
|
||||
## - MemoryClerk
|
||||
## - VolumeSpace
|
||||
## - PerformanceMetrics
|
||||
|
||||
## A list of queries to explicitly ignore.
|
||||
exclude_query = [ 'Schedulers' , 'SqlRequests']
|
||||
## A list of queries to include. If not specified, all the above listed queries are used.
|
||||
# include_query = []
|
||||
|
||||
## A list of queries to explicitly ignore.
|
||||
exclude_query = [ 'Schedulers' , 'SqlRequests']
|
||||
`
|
||||
|
||||
// SampleConfig return the sample configuration
|
||||
@@ -109,6 +116,7 @@ func initQueries(s *SQLServer) error {
|
||||
queries["MemoryClerk"] = Query{Script: sqlMemoryClerkV2, ResultByRow: false}
|
||||
queries["Schedulers"] = Query{Script: sqlServerSchedulersV2, ResultByRow: false}
|
||||
queries["SqlRequests"] = Query{Script: sqlServerRequestsV2, ResultByRow: false}
|
||||
queries["VolumeSpace"] = Query{Script: sqlServerVolumeSpaceV2, ResultByRow: false}
|
||||
} else {
|
||||
queries["PerformanceCounters"] = Query{Script: sqlPerformanceCounters, ResultByRow: true}
|
||||
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
|
||||
const sqlPerformanceMetrics string = `SET DEADLOCK_PRIORITY -10;
|
||||
SET NOCOUNT ON;
|
||||
|
||||
Reference in New Issue
Block a user