SQL Server Memory Manager – How to Query Performance Counters in DMV

dmvmemorymemory-managerperformance-counterssql-server-2017

Is there any system catalog views or DMVs that can be used to query (in SSMS for example) below performance counters from SQL Server:Memory Manager ?

Free Memory (KB)
Target Server Memory
Total Server Memory
Maximum Workspace Memory (KB)
Database Cache Memory (KB)
Granted Workspace Memory (KB)
Lock Memory (KB)
Log Pool Memory (KB)
Optimizer Memory (KB)
Connection Memory (KB)
SQL Cache Memory (KB)
Reserved Server Memory (KB)
Stolen Server Memory (KB)

Best Answer

The information you seek is available in the DMV sys.dm_os_performance_counters.

select object_name, 
       counter_name, 
       instance_name, 
       cntr_value, 
       cntr_type
  from sys.dm_os_performance_counters
 where 1=1
   and [object_name] = 'SQLServer:Memory Manager'