context deadline exceeded on Large table size
OjerDev opened this issue · comments
In my SQL table, I am having 10 million rows. all other metrics I am getting except this one. previously I have checked with fewer rows that time query returned the correct values.
Below attaching my timeout config lines of both YML files and the error and the query I used for getting the table size.
Error:
6808 promhttp.go:38] Error gathering metrics: [from Gatherer #1] [, collector="mssql_standard", query="mssql_table_size"] context deadline exceeded
Prometheus.yml fine:
# my global config global: scrape_interval: 2m # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 2m # Evaluate rules every 15 seconds. The default is every 1 minute. scrape_timeout: 10s
SQL exporter yml file:
global: scrape_timeout_offset: 500ms min_interval: 0s max_connections: 3 max_idle_connections: 3
Query i have used for SQL table used, unused, total spaces:
`IF OBJECT_ID('tempdb.dbo.#space') IS NOT NULL
DROP TABLE #space
CREATE TABLE #space (
[db_name] SYSNAME
, obj_name SYSNAME
, total_pages BIGINT
, used_pages BIGINT
, total_rows BIGINT
)
DECLARE @SQL NVARCHAR(MAX)
SELECT @SQL = STUFF((
SELECT '
USE [' + d.name + ']
INSERT INTO #space ([db_name], obj_name, total_pages, used_pages, total_rows)
SELECT DB_NAME(), SCHEMA_NAME(o.[schema_id]) + ''.'' + o.name, t.total_pages, t.used_pages, t.total_rows
FROM (
SELECT
i.[object_id]
, total_pages = SUM(a.total_pages)
, used_pages = SUM(a.used_pages)
, total_rows = SUM(CASE WHEN i.index_id IN (0, 1) AND a.[type] = 1 THEN p.[rows] END)
FROM sys.indexes i
JOIN sys.partitions p ON i.[object_id] = p.[object_id] AND i.index_id = p.index_id
JOIN sys.allocation_units a ON p.[partition_id] = a.container_id
WHERE i.is_disabled = 0
AND i.is_hypothetical = 0
GROUP BY i.[object_id]
) t
JOIN sys.objects o ON t.[object_id] = o.[object_id]
WHERE o.name NOT LIKE ''dt%''
AND o.is_ms_shipped = 0
AND o.type = ''U''
AND o.[object_id] > 255;'
FROM sys.databases d
WHERE d.[state] = 0
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '')
EXEC sys.sp_executesql @SQL
SELECT
[db_name] as db
, obj_name
, total_space = CAST(total_pages * 1024.0 * 8. AS DECIMAL(18,2))
, used_space = CAST(used_pages * 1024.0 * 8. AS DECIMAL(18,2))
, unused_space = CAST((total_pages - used_pages) * 1024.0 * 8. AS DECIMAL(18,2))
FROM #space`