Skip to content

DBMON-5416 Collect table size metrics for SQLServer #20367

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

Merged
merged 14 commits into from
May 29, 2025

Conversation

edengorevoy
Copy link
Contributor

@edengorevoy edengorevoy commented May 23, 2025

What does this PR do?

This PR adds a configuration option to collect table size metrics, in kibibytes, for SQLserver:

sqlserver.table.row_count
sqlserver.table.total_size
sqlserver.table.used_size
sqlserver.table.data_size

Each is tagged by table, database and schema. We query from sys.dm_db_partition_stats and sys.allocation_units to grab this information.

SELECT 
        t.name AS table_name,
        s.name AS schema_name,
        db_name() AS database_name,
        SUM(p.row_count) AS row_count,
        CAST(SUM(a.total_pages) * 8.0 AS DECIMAL(18,2)) AS total_size,
        CAST(SUM(a.used_pages) * 8.0  AS DECIMAL(18,2)) AS used_size,
        CAST(SUM(a.data_pages) * 8.0  AS DECIMAL(18,2)) AS data_size
    FROM 
        sys.tables t
    INNER JOIN 
        sys.schemas s ON t.schema_id = s.schema_id
    INNER JOIN 
        sys.indexes i ON t.object_id = i.object_id
    INNER JOIN 
        sys.dm_db_partition_stats 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
    GROUP BY 
        t.name, s.name

tempdb is excluded from these metrics.

Motivation

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

@edengorevoy edengorevoy force-pushed the eden.gorevoy/table-size-metrics-sqlserver branch from 8d3f9f1 to 6ef6664 Compare May 23, 2025 20:49
@edengorevoy edengorevoy changed the title Eden.gorevoy/table size metrics sqlserver Collect table size metrics for SQLServer May 27, 2025
Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 97.87234% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.47%. Comparing base (d73f66d) to head (444e20e).
Report is 89 commits behind head on master.

Additional details and impacted files
Flag Coverage Δ
activemq ?
cassandra ?
confluent_platform ?
hive ?
hivemq ?
hudi ?
ignite ?
jboss_wildfly ?
kafka ?
presto ?
solr ?
sqlserver 91.21% <97.87%> (+4.66%) ⬆️
tomcat ?
weblogic ?

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

lu-zhengda
lu-zhengda previously approved these changes May 27, 2025
@temporal-github-worker-1 temporal-github-worker-1 bot dismissed lu-zhengda’s stale review May 27, 2025 20:07

Review from lu-zhengda is dismissed. Related teams and files:

  • database-monitoring-agent
    • sqlserver/metadata.csv
@edengorevoy edengorevoy force-pushed the eden.gorevoy/table-size-metrics-sqlserver branch from c75d9cc to 444e20e Compare May 28, 2025 16:55
@edengorevoy edengorevoy changed the title Collect table size metrics for SQLServer DBMON-5416 Collect table size metrics for SQLServer May 28, 2025
@edengorevoy edengorevoy requested a review from lu-zhengda May 28, 2025 21:54
@edengorevoy edengorevoy added this pull request to the merge queue May 29, 2025
Merged via the queue into master with commit ffb4d3b May 29, 2025
41 checks passed
@edengorevoy edengorevoy deleted the eden.gorevoy/table-size-metrics-sqlserver branch May 29, 2025 13:54
domalessi pushed a commit that referenced this pull request May 29, 2025
* Sqlserver table size metrics

* wip

* Wip

* Collect table size metrics for SQLServer

* Format

* Exclude tempdb

* Changelog

* Validate

* Integration test

* Style

* Metadata file

* License

* Skip table size metrics for windows

* Lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants