AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1000300
Accepted
kqr
kqr
Asked: 2020-01-25 12:04:39 +0800 CST2020-01-25 12:04:39 +0800 CST 2020-01-25 12:04:39 +0800 CST

有没有类似时间序列的茎叶图?

  • 772

当想要快速查看一系列值的分布时,茎叶图是一个非常简单但功能强大的工具。教电脑画它需要几分钟,或者你可以简单地用手来做。

唯一的问题是它不保留值的顺序,其中有时包含有用的信息。我一直在尝试想一种同样简单的方法来绘制具有保留顺序的时间序列,但未能提出一些建议。

使用 X 轴上的时间和 Y 轴上的值制作常规时间序列图表的明显解决方案存在这样一个问题,即在进入实际渲染之前需要进行大量准备工作。它在概念上远没有茎叶图那么简单。

有什么东西吗?还是我要求的不可能?

哦,还有一个我差点忘记的重要要求:我希望它可以在行缓冲终端上轻松打印...


我在这里问的原因是因为我的主要用例是健康指标和来自服务器的其他样本。在排除系统故障的原因时,最好快速了解某些子系统随时间推移的行为方式。

performance monitoring metrics health statistics
  • 1 1 个回答
  • 23 Views

1 个回答

  • Voted
  1. Best Answer
    kqr
    2020-01-28T06:08:34+08:002020-01-28T06:08:34+08:00

    我不确定这完全是我想要的,因为它有点复杂,但到目前为止它已经满足了我的需求:

    我开始使用温度,这些温度都在 25-60 °C 范围内,所以我可以简单地复制一串*以创建一种它们的条形图:

    $ cat temps2.txt | perl -pe 'print "*" x $_ . " ";'
    ******************************************** 44.0
    *************************************************** 51.0
    ******************************************* 43.0
    ********************************************* 45.0
    ************************************** 38.0
    **************************************** 40.0
    *********************************** 35.0
    ************************************ 36.0
    ******************************** 32.0
    ******************************** 32.0
    ******************************* 31.0
    ******************************* 31.0
    ******************************** 32.0
    ******************************** 32.0
    ******************************* 31.0
    ************************************ 36.0
    ******************************** 32.0
    ************************************ 36.0
    ******************************* 31.0
    *********************************** 35.0
    ************************************ 36.0
    ************************************ 36.0
    ********************************* 33.0
    ******************************* 31.0
    ******************************** 32.0
    ******************************* 31.0
    ********************************* 33.0
    ******************************** 32.0
    ******************************** 32.0
    ************************************ 36.0
    

    当然,这仅适用于方便范围内的值,但当它们存在时它非常有效——当它们不存在时,只需向$_表示重复次数的变量添加一些算术操作即可。

    例如,每秒的平均处理器运行队列长度(对我来说在 0-8 范围内)可以乘以 10 以在输出中显示移位:

    $ cat runq.txt | perl -pe 'print "*" x ($_ * 10) . " ";'
     0
     0
     0
     0
    ******************** 2
    ********** 1
    ******************** 2
    **************************************** 4
    ****************************** 3
    **************************************** 4
    ****************************** 3
    ****************************** 3
    ******************** 2
    ******************** 2
    ********** 1
    ********** 1
    ********** 1
    ************************************************************ 6
    ********** 1
    ********** 1
    ********** 1
     0
     0
    

    这绝对可以满足我的需求。


    当然,作为我自己,我采取了这种方式并创建了一个大脚本,其中包括自动计算和更新坐标变换,以及系统平均和自然过程限制的流式计算:

    $ cat temps2.txt | ./limits.pl
    ----------------------------------------------------------------
    X:    51.0           [            | *         ]
    X:    43.0         [           * |            ]
    X:    45.0            [         |          ]
    X:    38.0          [      *   |          ]
    X:    40.0           [      *  |        ]
    X:    35.0           [   *    |        ]
    X:    36.0           [    *  |        ]
    X:    32.0           [ *     |       ]
    X:    32.0           [ *    |      ]
    X:    31.0           [*     |     ]
    X:    31.0           [*    |     ]
    X:    32.0           [ *   |     ]
    X:    32.0           [ *   |    ]
    X:    31.0           [*   |    ]
    X:    36.0           [    *     ]
    X:    32.0           [ *  |     ]
    X:    36.0          [     |     ]
    X:    31.0          [ *   |     ]
    X:    35.0          [    *|     ]
    X:    36.0          [     |    ]
    X:    36.0          [     *    ]
    X:    33.0          [   * |    ]
    X:    31.0          [ *   |    ]
    X:    32.0          [  * |     ]
    X:    31.0          [ *  |    ]
    X:    33.0          [   *|    ]
    X:    32.0          [  * |    ]
    X:    32.0          [  * |    ]
    X:    36.0          [    |*   ]
    UPL=42.1
    Xbar=35.2
    LPL=28.2
    

    还附有此脚本的未清理源代码。这是初稿,请原谅糟糕的代码。

    #!/usr/bin/env perl
    
    use v5.26;
    use strict;
    use warnings;
    use List::Util qw( min max );
    
    my $max_width = 52;
    
    my $n = 0;
    my $xbar = 0;
    my $mrbar = 0;
    my $lpl;
    my $upl;
    
    sub print_values {
        print "\n";
        printf "UPL=%.1f\n", $upl;
        printf "Xbar=%.1f\n", $xbar;
        printf "LPL=%.1f\n", $lpl;
    }
    
    $SIG{INT} = \&print_values;
    
    my $min_y;
    my $max_y;
    
    my $xprev;
    while (my $x = <>) {
        $n++;
        $xbar *= $n - 1;
        $xbar += $x;
        $xbar /= $n;
    
        if (defined($xprev)) {
            my $mr = abs ($x - $xprev);
            $mrbar *= $n - 2;
            $mrbar += $mr;
            $mrbar /= $n - 1;
    
            $lpl = $xbar - $mrbar * 2.66;
            $upl = $xbar + $mrbar * 2.66;
    
            my $space_changed;
    
            # If any point is about to be drawn outside of the screen space, expand
            # the space to include the currently drawn points and then some.
            if (min($lpl, $x) < $min_y or max($upl, $x) > $max_y) {
                my $min_diff = abs($min_y - min($lpl, $x));
                my $max_diff = abs($max_y - max($upl, $x));
                # Change min and max values in slightly larger steps to avoid
                # changing the space too often with a drifting process.
                $min_y -= $min_diff * 2;
                $max_y += $max_diff * 2;
                $space_changed = 1;
            }
            if ($min_y == $max_y) {
                $max_y = $min_y + 1;
            }
    
            my %screen_coords;
            $screen_coords{lpl} = $lpl;
            $screen_coords{upl} = $upl;
            $screen_coords{xbar} = $xbar;
            $screen_coords{x} = $x;
    
            # Transform the recorded values to the screen space.
            for my $coord (keys %screen_coords) {
                # Set offset to 0.
                $screen_coords{$coord} -= $min_y;
                # Divide by range to scale down to 0–1.
                $screen_coords{$coord} /= ($max_y - $min_y);
                # Scale up again to proper width.
                $screen_coords{$coord} *= ($max_width - 1);
            }
    
            # Render the recorded values into an array of characters.
            my @characters = split('', ' ' x $max_width);
            $characters[$screen_coords{xbar}] = '|';
            $characters[$screen_coords{lpl}] = '[';
            $characters[$screen_coords{upl}] = ']';
            $characters[$screen_coords{x}] = '*';
    
            # Print a separator whenever the space needs to be expanded.
            if ($space_changed) {
                printf ('-' x ($max_width + 12) . "\n");
            }
    
            printf "X: %7.1f %s\n", $x, join('', @characters);
        } else {
            $min_y = $x;
            $max_y = $x;
        }
    
        $xprev = $x;
    }
    
    print_values;
    
    • 0

相关问题

  • 基于 Microsoft 的服务器(IIS、MSSQL 等)上的病毒扫描应排除哪些内容?

  • jvm性能调优技巧/资源?

  • 加快 MSSQL 快照复制到 SQLExpress 副本的速度

  • 聚集索引与非聚集索引?

  • 使用大量 javascript 的页面上的鱿鱼速度很慢

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve