php laravel 分析 redis 各个key的内存占用情况

2023-05-16

<?php

namespace App\Console\Commands\Tools;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class RedisMemoryAnalyse extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Tools/RedisMemoryAnalyse {host} {port} {password?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'redis key 监控分析工具 - 手动执行此脚本';

    protected $redis;

    protected $host;

    protected $port;

    protected $password;

    /**
     * OrderSync constructor.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        ini_set('memory_limit', '2048M');

        try {
            $this->host = $this->argument('host');
            $this->port = $this->argument('port');
            $this->password = $this->argument('password');
            $this->redis = new \Redis();
            $this->redis->connect($this->host, $this->port);
            $this->redis->auth($this->password);

            for ($i = 0; $i < 16; $i++) {
                $this->anlayseByDb($i);
            }
        } catch (\Exception $e) {
            $this->_log($e->getFile(). " line: ". $e->getLine());
            $this->_log($e->getMessage());
        }
    }

    public function anlayseByDb($db)
    {
        $this->redis->select($db);
        $keys = $this->redis->keys("*");
        if (! empty($keys)) {
            $analy = [];
            foreach ($keys as $key) {
                $result = shell_exec("redis-cli -h {$this->host} -p {$this->port} -a {$this->password} -n {$db} memory usage '{$key}'");

                $analy[] = [
                    'key' => $key,
                    'ttl' => $this->redis->ttl($key),
                    'memory' => trim(explode('"', $result)[0])
                ];

                file_put_contents("/www/wwwroot/linsd/dh_erp_php/{$db}.csv", sprintf("%s,%s,%s\r\n", 
                    $key,
                    $this->redis->ttl($key),
                    trim(explode('"', $result)[0])
                ), FILE_APPEND);
            }

        }
    }

    /**
     * log
     */
    protected function _log($str)
    {
        print("[" . date("Y-m-d H:i:s") . "]".$str . "\n");
    }
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

php laravel 分析 redis 各个key的内存占用情况 的相关文章

随机推荐

  • 有铅焊锡丝与无铅焊锡丝的性能差异大解析

    有铅焊锡丝与无铅焊锡丝是二大类差另外产物档次 xff0c 由于其金属成份差别造成熔点也差别 xff0c 一样通常有铅焊锡丝 的熔点在183度 xff0c 而无铅焊锡丝的熔点为217 227度 含铅量越少熔点将越高 由于焊锡丝的熔点温度进步之
  • linux中的系统调用

    前言 xff1a 本文只讨论linux中的系统调用 xff0c 不考虑windows等其他操作系统 两点 xff1a 1 系统调用时 xff0c 进程调用的是操作系统的内核函数 xff0c 不是进程 2 系统调用时 xff0c 会出现上下文
  • iView 日期选择器开始时间至结束时间限制

    需要考虑以下条件 开始时间和结束时间都不能大于当前时间开始时间不能大于结束时间 html lt FormItem label 61 34 起止时间 34 gt lt DatePicker type 61 34 date 34 v model
  • 树莓派3安装笔记(1)-安装操作系统Raspbian以及安装必要软件

    拿到了树莓派3后 xff0c 经过短暂的兴奋 xff0c 终于开始实战安装OS了 以下步骤基于官方的文章https www raspberrypi org learning software guide quickstart xff0c 选
  • C中需要检验其执行是否成功的函数(检验返回值)

    一 malloc xff08 xff09 因为当内存分配完了后 xff0c 就无法再分配空间了 xff0c 所以malloc失败也是有的是 xff0c 当malloc失败时返回NULL char s 61 void malloc SIZE
  • 《Java核心技术 卷1》

    目录 第4章 对象和类 lt 1 gt 静态字段和静态方法 lt 2 gt 初始化块 lt 3 gt 定义抽象类的对象变量 lt 4 gt hashCode方法得到散列码 lt 5 gt 虚拟机中的泛型类型信息 第五章 继承 第6章 接口
  • Kalibr 之 Camera-IMU 标定 (总结)

    Overview 欢迎访问 持续更新 xff1a https cgabc xyz posts db22c2e6 ethz asl kalibr is a toolbox that solves the following calibrati
  • VMware Workstations Pro 14 建立的虚拟机目录无法删除

    起因 通过VMware新建的RedHat虚拟机 xff0c 无意间的强制关机 xff0c 导致该虚拟机开机黑屏无法正常开启 xff0c 而且也关不掉 尝试删除自己创建的虚拟机目录文件 xff0c 提示文件被占用 通过任务管理器想要结束相关进
  • 矩形目标检测

    身份证 名片 书籍 考试试卷 答题卡这些检测目标都属于矩形目标检测 一 xff0c 现有技术 传统检测方法思路 xff1a 第一步 xff0c 采用滑动窗口 xff0c 设置不同的大小 xff0c 遍历图像 xff0c 得到一些目标的候选框
  • 几种常用通信协议

    通信可以形象的比喻成两个人讲话 xff1a 1 你说的别人得能听懂 xff1a 双方约定信号的协议 2 你的语速别人得能接受 xff1a 双方满足时序要求 一 IIC协议 xff1a 2C串行总线一般有两根信号线 xff0c 一根是双向的数
  • 基础篇——树莓派远程连接工具VNC不显示视频或摄像头画面解决方式

    背景故事 在树莓派上打开摄像头 xff0c 发现HDMI输出的桌面有画面 xff0c 但VNC这边没有画面 xff1b 之前有一次使用播放器播放视频也出现这个问题 xff0c 现记录解决方式 原因分析 VNC远程桌面并不是使用画面传输的方式
  • 穿越机(无人机航模)电池组装教程-电线接口

    对于动手能力强 xff0c 或者穷逼来说 xff0c 购买品牌电池玩穿越机 xff0c 或者其他航模 是非常浪费钱的 本着能自己干就不需要厂商辛苦的原则 电池组装 xff0c 我们可以自己做 非航模圈的电池 xff0c 一般都需要自带平衡电
  • UITextView

    闪退问题 scrollViewDidScroll 改为 scrollViewWillBeginDragging 禁止编辑 text setEditable NO 光标位置输入 64 param emoji 要输入的内容emoji和字符 vo
  • iView 滚动条样式

    滚动条样式 webkit scrollbar width 6px height 6px webkit scrollbar thumb background ccc webkit scrollbar track background e1e1
  • 英特尔 RealSense D415 + OpenCV 4.0 + VS2017 配置方法

    首先是Opencv 4 0 43 VS2017的配置过程 xff0c 网上已经有很多类似教程 xff0c 这里不再累赘 xff1a https www cnblogs com xinxue p 5766756 html 接下来开始配置D41
  • Android 系统调用实现函数功能--SVC指令的实现与检测

    0x0 简述 xff1a arm android中通过一些反编译的工具分析ELF文件时 xff0c 根据一些导入的系统函数可以很轻松的找到一些功能代码的实现 xff1a 查看libc中分析这些函数的实现 xff1a arm中通过SVC指令实
  • Docker学习笔记(九):Docker +Jenkins +Github持续集成

    本次配置时 xff0c jenkins需要配置在外网可访问的服务器上 xff0c 因为在git push内容到github时 xff0c 触发Webhooks并推送到jenkins服务器上 1 配置Github xff08 通过秘钥登录 x
  • opencv-python 常用函数介绍

    目录 imread xff1a 读取图片 imshow xff1a 展示图片 resize xff1a 图片等比例缩放 split xff1a 获取所有像素的颜色值 merge xff1a 根据颜色值合成图片 VideoCapture xf
  • redis 内存占用分析

    在Redis命令行中 xff0c 执行MEMORY STATS命令查询内存使用详情 Redis实例的内存开销主要由两部分组成 xff1a 业务数据的内存开销 xff0c 该部分一般作为重点分析对象 非业务数据的内存开销 xff0c 例如主备
  • php laravel 分析 redis 各个key的内存占用情况

    lt php namespace App Console Commands Tools use Illuminate Console Command use Illuminate Support Facades DB class Redis