# Memory usage in OPS source

**URL:** <https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783>\
**Category:** MemSQL Ops\
**Tags:** ops\
**Created:** [July 22, 2022, 9:44am UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783 "2022-07-22T09:44:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ira](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/i/9fc348/32.png) [@ira](https://www.singlestore.com/forum/u/ira)\
**Post date:** [July 22, 2022, 9:44am UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783/1 "2022-07-22T09:44:26Z")

</div>

I want receive allerts when memory or other resources usage is close to limit (e.g., 85% from total).  
See Dashboard Cluster Usage panel contains TOTAL MEMORY USAGE.  
There 3 values:  
Used  
Reserved  
Total - just as I receive with INFORMATION\_SCHEMA.LMV\_SYSINFO\_DISK

But both Used values from this view are not equal to value from a dashboard panel and there is not reserved value. Can I ask what is source of it ?

Thanks!

 ![memory_usagepg](https://forum-prod-assets20231213123829991800000001.s3.dualstack.us-east-1.amazonaws.com/original/2X/f/fed0a4ab38200c088c79b2ef149832ca8b60a6f9.jpeg)

---

<div class="post-metadata">

**Author:** ![hanson](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/hanson/32/196_2.png) [@hanson](https://www.singlestore.com/forum/u/hanson)\
**Post date:** [July 22, 2022, 11:44pm UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783/2 "2022-07-22T23:44:27Z")

</div>

Are you talking about our cloud portal or Studio? Can you post a screen shot?

---

<div class="post-metadata">

**Author:** ![ira](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/i/9fc348/32.png) [@ira](https://www.singlestore.com/forum/u/ira)\
**Post date:** [July 23, 2022, 7:07am UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783/3 "2022-07-23T07:07:38Z")

</div>

Hi @hanson, I talk about Studio, see screenshot and thank you

---

<div class="post-metadata">

**Author:** ![hanson](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/hanson/32/196_2.png) [@hanson](https://www.singlestore.com/forum/u/hanson)\
**Post date:** [July 25, 2022, 11:48pm UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783/4 "2022-07-25T23:48:25Z")

</div>

Let me check with the developers and see if we can get you the query behind that.

If you are highly motivated and what to see what SQL Studio is emitting for various things, you can look in mv\_activites\_extended and mv\_queries, and use some “like” filters on query text.

---

<div class="post-metadata">

**Author:** ![ira](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/i/9fc348/32.png) [@ira](https://www.singlestore.com/forum/u/ira)\
**Post date:** [July 26, 2022, 7:04am UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783/5 "2022-07-26T07:04:08Z")

</div>

Hi @hanson, thanks, a good idea, I will check

---

<div class="post-metadata">

**Author:** ![ira](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/i/9fc348/32.png) [@ira](https://www.singlestore.com/forum/u/ira)\
**Post date:** [July 26, 2022, 12:31pm UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783/6 "2022-07-26T12:31:36Z")

</div>

@hanson, I not was able to catch Mem Used & Reserved formula - and CPU usage, too - to receive the same values as in Studio for cluster and for nodes.  
About Mem at least HOST\_USED\_B from INFORMATION\_SCHEMA.LMV\_SYSINFO\_MEM gives SUM of Used and Reserved without splitting . It’s OK for my needs.  
So, now my goal is CPU usage formula.  
Thank you again

---

<div class="post-metadata">

**Author:** ![david](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.singlestore.com/forum/u/david)\
**Post date:** [July 26, 2022, 2:24pm UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783/7 "2022-07-26T14:24:46Z")

</div>

Hello @ira ,

The query that Studio uses are the following:

Memory Usage:

```auto
    SELECT
        IFNULL(SUM(mv.VARIABLE_VALUE - mv2.VARIABLE_VALUE), 0) * 1024 * 1024 AS memoryUsageB
    FROM
        INFORMATION_SCHEMA.MV_GLOBAL_STATUS mv
    INNER JOIN
        INFORMATION_SCHEMA.MV_GLOBAL_STATUS mv2
    ON
        mv.NODE_ID = mv2.NODE_ID
    WHERE
        mv.VARIABLE_NAME = 'Total_server_memory' AND
        mv2.VARIABLE_NAME = 'Buffer_manager_cached_memory' AND
        mv.NODE_TYPE = 'LEAF';

```

Available Memory (Total - Used = Reserved):

```auto
    SELECT
        SUM(MAX_MEMORY_MB) * 1024 * 1024 AS availableMemoryB
    FROM (
        SELECT
            MAX(MAX_MEMORY_MB) AS MAX_MEMORY_MB
        FROM
            INFORMATION_SCHEMA.MV_NODES
        WHERE
            TYPE='LEAF'
        GROUP BY
            IP_ADDR
    );

```

And for total:

```auto
    SELECT
        SUM(totalMemoryB) AS totalMemoryB
    FROM (
        SELECT
            MAX(
                IF(
                    CGROUP_TOTAL_B > POW(2, 62) OR CGROUP_TOTAL_B = -1,
                    HOST_TOTAL_B,
                    CGROUP_TOTAL_B
                )
            ) AS totalMemoryB
        FROM
            INFORMATION_SCHEMA.MV_SYSINFO_MEM
        WHERE
            TYPE='LEAF'
        GROUP BY
            IP_ADDR
    );

```

For disk usage, we just use:

Usage:

```auto
    WITH
        mv_query AS (
            SELECT
                MAX(MOUNT_USED_B) AS diskUsageB
            FROM
                INFORMATION_SCHEMA.MV_SYSINFO_DISK
            WHERE
                TYPE = 'LEAF'
            GROUP BY
                IP_ADDR
        )
    SELECT
        SUM(diskUsageB) AS diskUsageB
    FROM
        mv_query;

```

Total:

```auto
    WITH
        mv_query AS (
            SELECT
                MAX(MOUNT_TOTAL_B) AS diskTotalB
            FROM
                INFORMATION_SCHEMA.MV_SYSINFO_DISK
            WHERE
                TYPE = 'LEAF'
            GROUP BY
                IP_ADDR
        )
    SELECT
        SUM(diskTotalB) AS diskTotalB
    FROM
        mv_query;

```

---

<div class="post-metadata">

**Author:** ![ira](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/i/9fc348/32.png) [@ira](https://www.singlestore.com/forum/u/ira)\
**Post date:** [July 26, 2022, 2:30pm UTC](https://www.singlestore.com/forum/t/memory-usage-in-ops-source/4783/8 "2022-07-26T14:30:34Z")

</div>

Hi @david , thanks!  
What about cpu usage?
