> For the complete documentation index, see [llms.txt](https://joyous-x.gitbook.io/mbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://joyous-x.gitbook.io/mbook/part-devops/linux-mem-grows.md).

# Linux 内存缓慢增长问题

在遇到 内存、cpu 等系统资源 缓慢增长问题时，可以使用类似的脚本进行数据采样，然后通过对格式化数据分析找到 具体的服务(进程)。

## 监控脚本

```
    #!/bin/bash

    # */1 * * * * bash /data/data_tmp/monitor.sh

    now=`date +%Y%m%d`
    /usr/bin/top -c -b -n 1 | sort -nr -k10 | head -n 20 | tee >>/data/data_tmp/top_$now.txt

    tow_days_ago=`date +%Y%m%d -d "5 day ago"`
    if [ -f /data/data_tmp/top_${tow_days_ago}.txt ];then
    rm -f /data/data_tmp/top_${tow_days_ago}.txt
    fi
```

## 分析数据

```
    # 按进程名分组写入不同的文件
    cat tmp.txt | grep -v % | grep -v KiB | grep -v Tasks | sort -r -k12 -k11 | awk '{print $0 >> $12".rlog"}'
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://joyous-x.gitbook.io/mbook/part-devops/linux-mem-grows.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
