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

context deadline exceeded on Large table size #114

Open
OjerDev opened this issue Jan 7, 2022 · 0 comments
Open

context deadline exceeded on Large table size #114

OjerDev opened this issue Jan 7, 2022 · 0 comments

Comments

@OjerDev
Copy link

OjerDev commented Jan 7, 2022

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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant