visionary-sdk 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c70c741e8ee81fe468ae6f03e1a6884055d55b5d5f9499f28f78e4d021b1815
4
- data.tar.gz: 0feb3516ddbe733ec03e9705a7d85ca4a5ea4661e157970f91d5005348cff9e6
3
+ metadata.gz: 9dc24002c7339143242fa7b3faabdbf0d83ba14173243d4ab09f7d7c95c0a74f
4
+ data.tar.gz: b2e5d5e60bc16c897db25fbe29df6303b10824447dafc922944ec6bd02c6423b
5
5
  SHA512:
6
- metadata.gz: 135547e95a2987867d8064a16b810745a55021f0081aaebb2bdc0d7db04509a2f8040f03dd3a3ca1d00739b4767a3eb87d2aead0079fe2e680717569bf87cad5
7
- data.tar.gz: 5faef98cb51c0ccc47c094bf708cb568dc9c6f22f4c3145b7f1870bae1adaf530950a0b840fc06f4d847a311f6546910333a96f6605abf586d2ebb3d0f8ec89a
6
+ metadata.gz: 7c848ed5422eae3c19f50569040d73c738ebec0d030320bfc3ed703cdd5a65b2d5a9fb51318e9fa92f0b97e17b8871512fbca4af2f39b718c4ec1bd7423d91c8
7
+ data.tar.gz: c21bd7b5745b7c94cb2fad53934a0f3684babef695b87eaea8630fbdf6b050db559b6f74a67c0cccfae556e0f16dd46b7276c29bb884d8b9d9c15254a74d9bf8
@@ -101,7 +101,11 @@ CREATE TABLE IF NOT EXISTS system_metrics (
101
101
  container_minor_faults_ps DOUBLE,
102
102
  container_major_faults_ps DOUBLE,
103
103
  container_mem_high_events BIGINT,
104
- container_mem_max_events BIGINT
104
+ container_mem_max_events BIGINT,
105
+ container_pids BIGINT,
106
+ container_pids_max BIGINT,
107
+ container_read_kbps DOUBLE,
108
+ container_write_kbps DOUBLE
105
109
  ) CHARACTER SET utf8mb4;
106
110
  CREATE INDEX idx_system_metrics_created_at ON system_metrics (created_at);
107
111
  CREATE INDEX idx_system_metrics_instance_created ON system_metrics (instance, created_at);
@@ -101,7 +101,11 @@ CREATE TABLE IF NOT EXISTS system_metrics (
101
101
  container_minor_faults_ps DOUBLE PRECISION,
102
102
  container_major_faults_ps DOUBLE PRECISION,
103
103
  container_mem_high_events BIGINT,
104
- container_mem_max_events BIGINT
104
+ container_mem_max_events BIGINT,
105
+ container_pids BIGINT,
106
+ container_pids_max BIGINT,
107
+ container_read_kbps DOUBLE PRECISION,
108
+ container_write_kbps DOUBLE PRECISION
105
109
  );
106
110
  CREATE INDEX IF NOT EXISTS idx_system_metrics_created_at ON system_metrics (created_at);
107
111
  CREATE INDEX IF NOT EXISTS idx_system_metrics_instance_created ON system_metrics (instance, created_at);
@@ -101,7 +101,11 @@ CREATE TABLE IF NOT EXISTS system_metrics (
101
101
  container_minor_faults_ps REAL,
102
102
  container_major_faults_ps REAL,
103
103
  container_mem_high_events INTEGER,
104
- container_mem_max_events INTEGER
104
+ container_mem_max_events INTEGER,
105
+ container_pids INTEGER,
106
+ container_pids_max INTEGER,
107
+ container_read_kbps REAL,
108
+ container_write_kbps REAL
105
109
  );
106
110
  CREATE INDEX IF NOT EXISTS idx_system_metrics_created_at ON system_metrics (created_at);
107
111
  CREATE INDEX IF NOT EXISTS idx_system_metrics_instance_created ON system_metrics (instance, created_at);
@@ -60,7 +60,9 @@ module Visionary
60
60
  %w[mem_dirty_mb real], %w[mem_writeback_mb real], %w[mem_slab_mb real],
61
61
  %w[mem_shmem_mb real], %w[mem_committed_mb real], %w[mem_commit_limit_mb real],
62
62
  %w[container_minor_faults_ps real], %w[container_major_faults_ps real],
63
- %w[container_mem_high_events int], %w[container_mem_max_events int]
63
+ %w[container_mem_high_events int], %w[container_mem_max_events int],
64
+ %w[container_pids int], %w[container_pids_max int],
65
+ %w[container_read_kbps real], %w[container_write_kbps real]
64
66
  ].freeze
65
67
 
66
68
  SPAN_COLUMNS = %w[
@@ -23,7 +23,7 @@ module Visionary
23
23
  c.cpu_dir || c.mem_dir ? c : nil
24
24
  end
25
25
 
26
- attr_reader :cpu_dir, :mem_dir
26
+ attr_reader :cpu_dir, :mem_dir, :pids_dir, :io_dir
27
27
 
28
28
  def v2? = @v2
29
29
 
@@ -33,7 +33,7 @@ module Visionary
33
33
  @root = root
34
34
  @in_ctr = container?(text, env)
35
35
  @v2 = false
36
- @cpu_dir = @cpu_acct = @mem_dir = nil
36
+ @cpu_dir = @cpu_acct = @mem_dir = @pids_dir = @io_dir = nil
37
37
  text.strip.each_line do |line|
38
38
  id, ctrls, path = line.chomp.split(":", 3)
39
39
  next if path.nil?
@@ -42,11 +42,15 @@ module Visionary
42
42
  dir = dir_for("sys/fs/cgroup", path)
43
43
  if File.exist?(File.join(dir, "cpu.stat"))
44
44
  @v2 = true
45
- @cpu_dir = @mem_dir = dir
45
+ @cpu_dir = @mem_dir = @pids_dir = @io_dir = dir
46
46
  break
47
47
  end
48
48
  elsif list.include?("memory")
49
49
  @mem_dir = dir_for("sys/fs/cgroup/memory", path)
50
+ elsif list.include?("pids")
51
+ @pids_dir = dir_for("sys/fs/cgroup/pids", path)
52
+ elsif list.include?("blkio")
53
+ @io_dir = dir_for("sys/fs/cgroup/#{ctrls}", path)
50
54
  elsif list.include?("cpu") || list.include?("cpuacct")
51
55
  dir = dir_for("sys/fs/cgroup/#{ctrls}", path)
52
56
  @cpu_dir = dir if list.include?("cpu")
@@ -60,6 +64,7 @@ module Visionary
60
64
  def prime
61
65
  @usage, @periods, @throttled, @ooms = counters
62
66
  @mem = read_mem
67
+ @io = read_io
63
68
  @last = mono
64
69
  @primed = true
65
70
  end
@@ -80,7 +85,13 @@ module Visionary
80
85
  end
81
86
  v["container_oom_kills"] = ooms - @ooms if ooms && @ooms && ooms >= @ooms
82
87
  sample_mem(v, secs)
88
+ io = read_io
89
+ if io && @io && io[0] >= @io[0] && io[1] >= @io[1]
90
+ v["container_read_kbps"] = ((io[0] - @io[0]) / 1024.0 / secs).round(1)
91
+ v["container_write_kbps"] = ((io[1] - @io[1]) / 1024.0 / secs).round(1)
92
+ end
83
93
  end
94
+ @io = read_io
84
95
  @usage, @periods, @throttled, @ooms = usage, periods, throttled, ooms
85
96
  @last = now
86
97
  @primed = true
@@ -89,6 +100,13 @@ module Visionary
89
100
  v["container_mem_used_mb"] = (used / MB).round(1)
90
101
  end
91
102
  v["container_mem_limit_mb"] = (mem_limit / MB).round(1) if mem_limit.positive?
103
+ return unless @pids_dir
104
+ if (n = read_int(File.join(@pids_dir, "pids.current")))
105
+ v["container_pids"] = n
106
+ end
107
+ if (n = read_int(File.join(@pids_dir, "pids.max"))) # "max" is not a number
108
+ v["container_pids_max"] = n
109
+ end
92
110
  end
93
111
 
94
112
  private
@@ -115,6 +133,12 @@ module Visionary
115
133
  m
116
134
  end
117
135
 
136
+ # Bytes read from and written to block devices: [read, write], or nil
137
+ def read_io
138
+ return nil unless @io_dir
139
+ HostStats.parse_cgroup_io(Sources.read(File.join(@io_dir, @v2 ? "io.stat" : "blkio.throttle.io_service_bytes")))
140
+ end
141
+
118
142
  def sample_mem(v, secs)
119
143
  now = read_mem
120
144
  prev = @mem || {}
@@ -87,6 +87,30 @@ module Visionary
87
87
  ev.size == 2 ? [ev["high"], ev["max"]] : nil
88
88
  end
89
89
 
90
+ # Bytes read and written, summed over a cgroup's devices: v2 io.stat
91
+ # ("8:0 rbytes=1 wbytes=2 ...") or v1 blkio.throttle.io_service_bytes
92
+ # ("8:0 Read 1", "8:0 Write 2"); nil when neither is there
93
+ def self.parse_cgroup_io(text)
94
+ read = write = 0
95
+ ok = false
96
+ text.to_s.each_line do |line|
97
+ f = line.split
98
+ if f.size == 3 && %w[Read Write].include?(f[1])
99
+ next unless f[2].match?(/\A\d+\z/)
100
+ f[1] == "Read" ? read += f[2].to_i : write += f[2].to_i
101
+ ok = true
102
+ next
103
+ end
104
+ f.drop(1).each do |kv|
105
+ k, n = kv.split("=", 2)
106
+ next unless %w[rbytes wbytes].include?(k) && n&.match?(/\A\d+\z/)
107
+ k == "rbytes" ? read += n.to_i : write += n.to_i
108
+ ok = true
109
+ end
110
+ end
111
+ ok ? [read, write] : nil
112
+ end
113
+
90
114
  # "key<sep> value [unit]" lines with an unsigned value
91
115
  def self.each_kv(text, sep)
92
116
  text.to_s.each_line do |line|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Visionary
4
- VERSION = "1.2.2"
4
+ VERSION = "1.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visionary-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - styropyr0
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-31 00:00:00.000000000 Z
11
+ date: 2026-11-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  The Ruby collector for Visionary. A Rack middleware (with a Railtie for Rails)