DBAtlas · 数据库运维图谱

在数据库内查看服务器资源使用(CPU/IO)

Oracle

SELECT stat_name, value FROM v$osstat
WHERE stat_name IN ('NUM_CPUS','BUSY_TIME','IDLE_TIME','IOWAIT_TIME','PHYSICAL_MEMORY_BYTES');
-- Real-time metrics: SELECT metric_name, value FROM v$sysmetric WHERE group_id = 2;

v$osstat 给出操作系统 CPU/内存计数器;v$sysmetric 给出最近一个时间间隔的实时数据库指标(CPU、IOPS)。

PostgreSQL

SELECT backend_type, object, context, reads, writes, hits, evictions
FROM pg_stat_io
ORDER BY reads DESC;
-- Note: CPU usage is not visible from inside the DB; an OS tool (top, sar) is required.

pg_stat_io 给出读/写/缓存命中计数器;PostgreSQL 不提供 CPU 使用率,因此需要操作系统工具。

MySQL

SELECT * FROM sys.host_summary;
-- For InnoDB I/O and thread details:
SHOW ENGINE INNODB STATUS\G

sys schema 汇总视图(host_summary)给出 IO/延迟明细;SHOW ENGINE INNODB STATUS 显示缓冲池和 IO 活动。

SQL Server

SELECT object_name, counter_name, cntr_value
FROM sys.dm_os_performance_counters
WHERE counter_name LIKE '%CPU%' OR counter_name LIKE '%Page life expectancy%';
-- CPU history: sys.dm_os_ring_buffers (RING_BUFFER_SCHEDULER_MONITOR)

sys.dm_os_performance_counters 给出数据库性能计数器;dm_os_ring_buffers 给出最近约 256 分钟内 SQL/其他进程的 CPU 占比。

MongoDB

db.serverStatus().metrics
// Relevant fields: .opcounters, .network, .wiredTiger.cache, .mem, .extra_info.page_faults

serverStatus() 给出内存、网络、opcounters 和 WiredTiger 缓存指标;详细的操作系统 CPU/IO 请使用 mongostat 或操作系统工具。

Redis

INFO cpu
INFO stats
# used_cpu_sys, used_cpu_user, instantaneous_ops_per_sec, total_net_input_bytes

INFO cpu 报告 Redis 进程的 CPU 消耗,INFO stats 报告每秒操作数和网络流量。

Elasticsearch

GET _nodes/stats/os,process
// Look at the os.cpu.percent, os.mem, process.cpu.percent, fs (disk) fields

_nodes/stats/os,process 给出每个节点的 CPU 百分比、内存和进程指标;磁盘使用 fs 部分。

在 DBAtlas 中打开 →