Skip to content

Getting Database Table Size? #679

Closed Answered by ihindegit
ihindegit asked this question in Q&A
Discussion options

You must be logged in to vote

Is it possibly something wrong with the definition? Below is my full metric.

  • metric_name: mssql_size
    type: gauge
    help: 'Table size'
    value_label: 'state'
    values: [TotalSpaceKB]
    query: SELECT SUM(a.total_pages) * 8 AS TotalSpaceKB
    FROM sys.tables t
    INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
    INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
    INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
    LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id
    WHERE
    t.NAME = 'MyTable'
    GROUP BY
    t.Name, s.Name, p.Rows
    ORDER BY
    TotalSpaceKB DESC

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ihindegit
Comment options

@burningalchemist
Comment options

@ihindegit
Comment options

Answer selected by ihindegit
@ihindegit
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants