cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob d5b7a4690495e0bfa3eedc469a947690c2cca1ed 2000 bytes (raw)
$ git show HEAD:test/iostat-mock.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
#!/usr/bin/env ruby
# -*- encoding: binary -*-
# Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
usage = "Usage: #$0 PIDFILE (fast|slow)"
$stdout.binmode
$stdout.sync = $stderr.sync = true
$-w = true
require 'stringio'

output = <<EOF
Linux 6.6.6 (faster) 	01/01/1970 	_x86_64_	(666 CPU)

Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.02    71.67    1.05    5.94    31.95   630.78    94.85     0.82  116.28   0.65   0.45
sdb               0.18    11.17    0.30    0.34    76.56    92.09   263.80     0.03   40.68   3.14   0.20
sdc               0.19     0.28    0.32    0.27   125.83    34.07   275.40     0.06  108.49  35.36   2.05
sdd               0.26     0.01    0.42    0.10     5.44    24.15    56.47     0.72 1373.24   1.88   0.10
sde               0.61    13.63    1.14    0.38   213.65   112.08   214.80     0.06   42.54   3.28   0.50

EOF

pidfile = ARGV.shift or abort usage
File.open(pidfile, "wb") { |fp| fp.write("#$$\n") }
n = 666666
begin
  case ARGV.shift
  when "fast"
    n.times { $stdout.write(output * 2) }
  when "slow"
    n.times do
      io = StringIO.new(output)
      while buf = io.read(rand(25) + 1)
        $stdout.write(buf)
        sleep 0.01
      end
      sleep 0.1
    end
  when "bursty1"
    n.times do
      io = StringIO.new(output.dup)
      add =  io.gets
      add << io.gets
      $stdout.write(output + add)
      sleep 2
      while buf = io.read(rand(666) + 1)
        $stdout.write(buf)
      end
    end
  when "bursty2"
    n.times do
      io = StringIO.new(output.dup)
      add = io.read(rand(66) + 6)
      $stdout.write(output + add)
      sleep 2
      while buf = io.read(rand(666) + 1)
        $stdout.write(buf)
        sleep 0.01
      end
      sleep 1
    end
  else
    abort usage
  end
rescue Errno::EPIPE
  exit 0
rescue => e
  abort("#{e.message} (#{e.class})")
end

git clone https://yhbt.net/cmogstored.git