CPU,Memory,IO,disk usage according to Database montly or weekly or daily report in sql server 2016

  • hi all,
    how to get the usage of CPU,Memory,IO,disk usage according to Database montly or weekly or daily report in sql server 2016....
    please pass me the script of any tool which can do this......

    thanks
     Ivan

  • Can use the below for Memory usage and waits stats (which can help in getting IO related to latches) .

    -------------------------
    Query to get the type and count of OS Waits of SQL threads
    -------------------------

    select *
    from sys.dm_os_wait_stats
    -- where wait_type like 'PAGEIOLATCH%' or wait_type like 'LCK_M%' or wait_type like 'ASYNC_IO_COMPLETION%' or wait_type like 'IO_COMPLETION%' or wait_type like 'ACCESS_METHODS_DATASET_PARENT%'  or wait_type like 'ACCESS_METHODS_SCAN_RANGE_GENERATOR%' or wait_type like 'SOS_SCHEDULER_YIELD%' or wait_type like 'LATCH%' or wait_type like 'CXPACKET%' or wait_type like 'EXECSYNC%' or wait_type like 'ASYNC_NETWORK_IO%'
    ORDER BY wait_type asc;
    ----------------------------------------------------
    Buffer Usage By Database and Objects in a database
    ----------------------------------------------------
    -- Find out how big buffer pool is and determine percentage used by each database
    DECLARE @total_buffer INT;
    SELECT @total_buffer = cntr_value   FROM sys.dm_os_performance_counters
    WHERE RTRIM([object_name]) LIKE '%Buffer Manager'   AND counter_name = 'Total Pages';
    ;WITH src AS(   SELECT        database_id, db_buffer_pages = COUNT_BIG(*)
    FROM sys.dm_os_buffer_descriptors       --WHERE database_id BETWEEN 5 AND 32766      
    GROUP BY database_id)SELECT   [db_name] = CASE [database_id] WHEN 32767        THEN 'Resource DB'        ELSE DB_NAME([database_id]) END,   db_buffer_pages,   db_buffer_MB = db_buffer_pages / 128,   db_buffer_percent = CONVERT(DECIMAL(6,3),        db_buffer_pages * 100.0 / @total_buffer)
    FROM src
    ORDER BY db_buffer_MB DESC;
    --then drill down into memory used by objects in database of your choice
    USE issuer;
    WITH src AS(   SELECT       [Object] = o.name,       [Type] = o.type_desc,       [Index] = COALESCE(i.name, ''),       [Index_Type] = i.type_desc,       p.[object_id],       p.index_id,       au.allocation_unit_id  
    FROM       sys.partitions AS p   INNER JOIN       sys.allocation_units AS au       ON p.hobt_id = au.container_id   INNER JOIN       sys.objects AS o       ON p.[object_id] = o.[object_id]   INNER JOIN       sys.indexes AS i       ON o.[object_id] = i.[object_id]       AND p.index_id = i.index_id   WHERE       au.[type] IN (1,2,3)       AND o.is_ms_shipped = 0)
    SELECT   src.[Object],   src.[Type],   src.[Index],   src.Index_Type,   buffer_pages = COUNT_BIG(b.page_id),   buffer_mb = COUNT_BIG(b.page_id) / 128
    FROM   src
    INNER JOIN   sys.dm_os_buffer_descriptors AS b 
     ON src.allocation_unit_id = b.allocation_unit_id
    WHERE   b.database_id = DB_ID()
    GROUP BY   src.[Object],   src.[Type],   src.[Index],   src.Index_Type
    ORDER BY   buffer_pages DESC;

    CPU usage for code/SP's running more than 10 seconds (modify for ur environment)
    -------------------------------------------------------------------------------------------------------------

    ----------------------------------------------------------------------
    All queries that are running with Execution time more than 10 seconds

    ----------------------------------------------------------------------
    SELECT SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
    ((CASE qs.statement_end_offset
    WHEN -1 THEN DATALENGTH(qt.TEXT)
    ELSE qs.statement_end_offset
    END - qs.statement_start_offset)/2)+1),
    qp.query_plan ,
    qs.execution_count,
    qs.total_logical_reads, qs.last_logical_reads,
    qs.total_logical_writes, qs.last_logical_writes,
    qs.total_physical_reads,
    qs.last_physical_reads,
    qt.dbid,
    qs.total_worker_time,
    qs.last_worker_time,
    qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
    qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
    qs.last_execution_time
    FROM sys.dm_exec_query_stats qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
    CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
    where qs.execution_count > 10
    ORDER BY last_elapsed_time_in_S       DESC -- CPU
    -- ORDER BY qs.total_worker_time DESC -- CPU
    -- ORDER BY qs.total_logical_reads DESC -- logical reads
    -- ORDER BY qs.total_logical_writes DESC -- logical writes

    If you are looking for summed up values for these, looking into using PerfMon.

  • You would have to collect this information periodically over time, using queries from the Ring Buffer or DMVs like Arsh mentioned, and then query the collected information for your weekly or monthly report.  Many DBAs have a special database just for themselves to store such collected data in.  There are third party tools that are also designed to collect this kind of data for you, if you're willing to pay of course 😉

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply