Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SQL server log file size metrics #6711

Closed
Closed
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
2 changes: 2 additions & 0 deletions plugins/inputs/sqlserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ GO
## - AzureDBResourceGovernance
## - SqlRequests
## - ServerProperties
## - LogFileSizes
exclude_query = [ 'Schedulers' , 'SqlRequests']
```

Expand Down Expand Up @@ -110,6 +111,7 @@ The new (version 2) metrics provide:
- *Wait stats*: Wait time in ms, number of waiting tasks, resource wait time, signal wait time, max wait time in ms, wait type, and wait category. The waits are categorized using the same categories used in Query Store.
- *Schedulers* - This captures sys.dm_os_schedulers.
- *SqlRequests* - This captures a snapshot of dm_exec_requests and dm_exec_sessions that gives you running requests as well as wait types and blocking sessions
- _Log File Sizes_: Current and maximum log file sizes from `sys.master_files`
- *Azure Managed Instances*
- Stats from `sys.server_resource_stats`:
- cpu_count
Expand Down
20 changes: 20 additions & 0 deletions plugins/inputs/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const sampleConfig = `
## - AzureDBResourceGovernance
## - SqlRequests
## - ServerProperties
## - LogFileSizes
exclude_query = [ 'Schedulers' ]
`

Expand Down Expand Up @@ -104,6 +105,7 @@ func initQueries(s *SQLServer) {
queries["MemoryClerk"] = Query{Script: sqlMemoryClerkV2, ResultByRow: false}
queries["Schedulers"] = Query{Script: sqlServerSchedulersV2, ResultByRow: false}
queries["SqlRequests"] = Query{Script: sqlServerRequestsV2, ResultByRow: false}
queries["LogFileSizes"] = Query{Script: sqlLogFileSizesV2, ResultByRow: false}
} else {
queries["PerformanceCounters"] = Query{Script: sqlPerformanceCounters, ResultByRow: true}
queries["WaitStatsCategorized"] = Query{Script: sqlWaitStatsCategorized, ResultByRow: false}
Expand Down Expand Up @@ -1362,6 +1364,24 @@ BEGIN
END;
`

const sqlLogFileSizesV2 string = `SET DEADLOCK_PRIORITY -10;
WITH fs
AS
(
SELECT database_id, type, size * 8 / 1024 size, max_size * 8 / 1024 max_size
FROM sys.master_files
WHERE database_id NOT IN (3,1,4)
)
SELECT
'sqlserver_log_size' AS [measurement],
REPLACE(@@SERVERNAME,'\',':') AS [sql_instance],
DB_NAME() as [database_name],
(SELECT SUM(size) FROM fs WHERE type = 0 AND fs.database_id = db.database_id) log_size_mb,
(SELECT SUM(max_size) FROM fs WHERE type = 1 AND fs.database_id = db.database_id) max_log_size_mb
FROM sys.databases db
WHERE database_id NOT IN (3,1,4)
`

const sqlServerRequestsV2 string = `
SET NOCOUNT ON;
SELECT blocking_session_id into #blockingSessions FROM sys.dm_exec_requests WHERE blocking_session_id != 0
Expand Down