# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
