openstack 管理三十五 - 利用 SQL 获取 tenant 当前资源情况

    xiaoxiao2026-05-12  2

    作用

    因为 openstack 命令行下, 没有办法直接获取资源使用情况 通过 sql 语句获得 tenant(project) 当前的资源使用情况 常见资源分别有 core, memory, disk, volume 这几种

    sql

    计算 cpu 与内存使用方法

    查询当前 tenants 方法

    mysql> select name from keystone.project; +----------------+ | name | +----------------+ | admin | | DEV | | DMZ1 | | DMZ2 | | DMZ3 | | DMZ4 | | DMZ5 | | DMZ6 | | MGMT | | MOBILE | | OPS | | QA | | QATOOL | | services | | unlimit_tenant | +----------------+ 15 rows in set (0.00 sec)

    直接通过 sql 语法调用, 连接 openstack 数据库 (mariadb)

    mysql> select b.name instances, count(a.vcpus) instances, sum(a.vcpus) cpus, sum( a.memory_mb ) memory_MB from nova.instances a, keystone.project b where a.deleted=0 and a.project_id = b.id and b.name in ('DEV', 'MOBILE','OPS') and a.vm_state in ( 'active', 'building', 'stopped') group by project_id; +-----------+-----------+------+-----------+ | instances | instances | cpus | memory_MB | +-----------+-----------+------+-----------+ | DEV | 2003 | 8890 | 11540480 | | MOBILE | 470 | 2830 | 4521984 | | OPS | 231 | 1037 | 1955840 | +-----------+-----------+------+-----------+ 3 rows in set (0.08 sec)

    …….. (待续)

    相关资源:python入门教程(PDF版)
    最新回复(0)