fluent-plugin-node-exporter-metrics 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/linux-test.yaml +42 -0
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +6 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +202 -0
  7. data/README.md +167 -0
  8. data/Rakefile +13 -0
  9. data/docs/cpu.md +26 -0
  10. data/docs/cpufreq.md +43 -0
  11. data/docs/diskstats.md +27 -0
  12. data/docs/filefd.md +12 -0
  13. data/docs/loadavg.md +13 -0
  14. data/docs/meminfo.md +61 -0
  15. data/docs/netdev.md +26 -0
  16. data/docs/stat.md +17 -0
  17. data/docs/time.md +9 -0
  18. data/docs/uname.md +15 -0
  19. data/docs/vmstat.md +17 -0
  20. data/fluent-plugin-node-exporter-metrics.gemspec +31 -0
  21. data/lib/fluent/plugin/in_node_exporter_metrics.rb +138 -0
  22. data/lib/fluent/plugin/node_exporter/cmetrics_dataschema_parser.rb +84 -0
  23. data/lib/fluent/plugin/node_exporter/collector.rb +41 -0
  24. data/lib/fluent/plugin/node_exporter/cpu_collector.rb +130 -0
  25. data/lib/fluent/plugin/node_exporter/cpufreq_collector.rb +97 -0
  26. data/lib/fluent/plugin/node_exporter/diskstats_collector.rb +280 -0
  27. data/lib/fluent/plugin/node_exporter/filefd_collector.rb +60 -0
  28. data/lib/fluent/plugin/node_exporter/loadavg_collector.rb +64 -0
  29. data/lib/fluent/plugin/node_exporter/meminfo_collector.rb +61 -0
  30. data/lib/fluent/plugin/node_exporter/netdev_collector.rb +92 -0
  31. data/lib/fluent/plugin/node_exporter/stat_collector.rb +84 -0
  32. data/lib/fluent/plugin/node_exporter/time_collector.rb +50 -0
  33. data/lib/fluent/plugin/node_exporter/uname_collector.rb +64 -0
  34. data/lib/fluent/plugin/node_exporter/vmstat_collector.rb +56 -0
  35. data/lib/fluent/plugin/parser_node_exporter_metrics.rb +54 -0
  36. data/test/fixtures/cpu/with_thermal_throttle/proc/stat +3 -0
  37. data/test/fixtures/cpu/with_thermal_throttle/sys/devices/system/cpu/cpu0/thermal_throttle/core_throttle_count +1 -0
  38. data/test/fixtures/cpu/with_thermal_throttle/sys/devices/system/cpu/cpu0/thermal_throttle/package_throttle_count +1 -0
  39. data/test/fixtures/cpu/with_thermal_throttle/sys/devices/system/cpu/cpu0/topology/core_id +1 -0
  40. data/test/fixtures/cpu/with_thermal_throttle/sys/devices/system/cpu/cpu0/topology/physical_package_id +1 -0
  41. data/test/fixtures/cpu/with_thermal_throttle/sys/devices/system/cpu/cpu1/thermal_throttle/core_throttle_count +1 -0
  42. data/test/fixtures/cpu/with_thermal_throttle/sys/devices/system/cpu/cpu1/thermal_throttle/package_throttle_count +1 -0
  43. data/test/fixtures/cpu/with_thermal_throttle/sys/devices/system/cpu/cpu1/topology/core_id +1 -0
  44. data/test/fixtures/cpu/with_thermal_throttle/sys/devices/system/cpu/cpu1/topology/physical_package_id +1 -0
  45. data/test/fixtures/cpu/without_thermal_throttle/proc/stat +3 -0
  46. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq +1 -0
  47. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq +1 -0
  48. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq +1 -0
  49. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq +1 -0
  50. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq +1 -0
  51. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq +1 -0
  52. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq +1 -0
  53. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq +1 -0
  54. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_min_freq +1 -0
  55. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq +1 -0
  56. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq +1 -0
  57. data/test/fixtures/cpufreq/with_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq +1 -0
  58. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq +1 -0
  59. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq +1 -0
  60. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq +1 -0
  61. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq +1 -0
  62. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq +1 -0
  63. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq +1 -0
  64. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_min_freq +1 -0
  65. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq +1 -0
  66. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq +1 -0
  67. data/test/fixtures/cpufreq/without_cur_freq/sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq +1 -0
  68. data/test/helper.rb +24 -0
  69. data/test/plugin/test_cmetrics_data_schema_parser.rb +83 -0
  70. data/test/plugin/test_cpu_collector.rb +84 -0
  71. data/test/plugin/test_cpufreq_collector.rb +75 -0
  72. data/test/plugin/test_diskstats_collector.rb +200 -0
  73. data/test/plugin/test_filefd_collector.rb +39 -0
  74. data/test/plugin/test_in_node_exporter_metrics.rb +583 -0
  75. data/test/plugin/test_loadavg_collector.rb +41 -0
  76. data/test/plugin/test_meminfo_collector.rb +47 -0
  77. data/test/plugin/test_netdev_collector.rb +35 -0
  78. data/test/plugin/test_stat_collector.rb +37 -0
  79. data/test/plugin/test_time_collector.rb +15 -0
  80. data/test/plugin/test_uname_collector.rb +47 -0
  81. data/test/plugin/test_vmstat_collector.rb +53 -0
  82. metadata +273 -0
@@ -0,0 +1,200 @@
1
+ require "helper"
2
+ require "fluent/plugin/in_node_exporter_metrics"
3
+ require "fluent/plugin/node_exporter/diskstats_collector"
4
+
5
+ class DiskstatsColectorTest < Test::Unit::TestCase
6
+
7
+ DUMMY_DISKSTATS = <<EOS
8
+ 1000 0 nvme0n1 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000
9
+ EOS
10
+
11
+ def parse(input)
12
+ stub(File).readlines { input.split("\n") }
13
+ collector = Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector.new
14
+ collector.run
15
+ yield collector
16
+ end
17
+
18
+ sub_test_case "diskstats" do
19
+
20
+ def test_ignore_devices
21
+ omit "/proc/diskstats is only available on *nix" unless Fluent.linux?
22
+
23
+ proc_diskstats = <<EOS
24
+ 1000 0 ram0 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
25
+ 1000 0 loop1 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
26
+ 1000 0 fd2 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
27
+ 1000 0 hda3 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
28
+ 1000 0 sda4 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
29
+ 1000 0 vda5 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
30
+ 1000 0 xvda6 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
31
+ 1000 0 nvme7p1 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
32
+ EOS
33
+ stub(Etc).uname { {release: "2.4.20-1-amd64"} }
34
+ parse(proc_diskstats) do |collector|
35
+ # all listed devices are ignored
36
+ assert_true(%w(ram0 loop1 fd2 hda3 sda4 vda5 xvda6 nmve7p1).all? { |v|
37
+ collector.cmetrics.keys.all? do |key|
38
+ collector.cmetrics[key].val([v]) == nil
39
+ end
40
+ })
41
+ end
42
+ end
43
+
44
+ def test_target_devices
45
+ omit "/proc/diskstats is only available on *nix" unless Fluent.linux?
46
+
47
+ proc_diskstats = <<EOS
48
+ 1000 0 ram0
49
+ 1000 0 loop1
50
+ 1000 0 fd2
51
+ 1000 0 hda3
52
+ 1000 0 sda4
53
+ 1000 0 vda5
54
+ 1000 0 xvda6
55
+ 1000 0 nvme7n1
56
+ 1000 0 nvme8n1p1
57
+ 1000 0 sda
58
+ 1000 0 vda
59
+ EOS
60
+ stub(Etc).uname { {release: "2.4.20-1-amd64"} }
61
+ parse(proc_diskstats) do |collector|
62
+ assert_equal(["nvme7n1", "sda", "vda"], collector.target_devices)
63
+ end
64
+ end
65
+
66
+ def test_minimum_metrics
67
+ omit "/proc/diskstats is only available on *nix" unless Fluent.linux?
68
+
69
+ # specify lower version to exclude discard and flush metrics explicitly
70
+ stub(Etc).uname { {release: "2.4.20-1-amd64"} }
71
+ parse(DUMMY_DISKSTATS) do |collector|
72
+ expected = (Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::METRIC_NAMES -
73
+ Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::DISCARD_METRIC_NAMES -
74
+ Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::FLUSH_METRIC_NAMES).collect { |v| v.intern }
75
+ assert_equal(expected, collector.cmetrics.keys)
76
+ end
77
+ end
78
+
79
+ def test_minimum_values
80
+ omit "/proc/diskstats is only available on *nix" unless Fluent.linux?
81
+
82
+ # specify lower version to exclude discard and flush metrics explicitly
83
+ stub(Etc).uname { {release: "2.4.20-1-amd64"} }
84
+ parse(DUMMY_DISKSTATS) do |collector|
85
+ assert_equal([4000.0, 5000.0, 6000 * 512, 7.0,
86
+ 8000.0, 9000.0, 10000 * 512, 11.0,
87
+ 12000.0, 13.0, 14.0],
88
+ [collector.cmetrics[:reads_completed_total].val(["nvme0n1"]),
89
+ collector.cmetrics[:reads_merged_total].val(["nvme0n1"]),
90
+ collector.cmetrics[:read_bytes_total].val(["nvme0n1"]),
91
+ collector.cmetrics[:read_time_seconds_total].val(["nvme0n1"]),
92
+ collector.cmetrics[:writes_completed_total].val(["nvme0n1"]),
93
+ collector.cmetrics[:writes_merged_total].val(["nvme0n1"]),
94
+ collector.cmetrics[:written_bytes_total].val(["nvme0n1"]),
95
+ collector.cmetrics[:write_time_seconds_total].val(["nvme0n1"]),
96
+ collector.cmetrics[:io_now].val(["nvme0n1"]),
97
+ collector.cmetrics[:io_time_seconds_total].val(["nvme0n1"]),
98
+ collector.cmetrics[:io_time_weighted_seconds_total].val(["nvme0n1"])
99
+ ])
100
+ end
101
+ end
102
+
103
+ def test_extra_fields
104
+ omit "/proc/diskstats is only available on *nix" unless Fluent.linux?
105
+
106
+ # non supported extra fields are silently ignored
107
+ proc_diskstats = <<EOS
108
+ 1000 0 nvme0n1 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000
109
+ EOS
110
+ parse(proc_diskstats) do |collector|
111
+ names = if collector.kernel_version_over4_18? and collector.kernel_version_over5_5?
112
+ Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::METRIC_NAMES.collect { |v| v.intern }
113
+ elsif collector.kernel_version_over4_18?
114
+ [Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::METRIC_NAMES -
115
+ Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::FLUSH_METRIC_NAMES].flatten.collect { |v| v.intern }
116
+ else
117
+ [Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::METRIC_NAMES -
118
+ Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::FLUSH_METRIC_NAMES -
119
+ Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::DISCARD_METRIC_NAMES].flatten.collect { |v| v.intern }
120
+ end
121
+ assert_equal(names, collector.cmetrics.keys)
122
+ end
123
+ end
124
+ end
125
+
126
+ sub_test_case "discards metrics" do
127
+ def test_with_discards
128
+ omit "/proc/diskstats is only available on *nix" unless Fluent.linux?
129
+
130
+ # over 4.18 contains discard metrics
131
+ stub(Etc).uname { {release: "4.18.0-1-amd64"} }
132
+ parse(DUMMY_DISKSTATS) do |collector|
133
+ metric_exists = Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::DISCARD_METRIC_NAMES.all? do |v|
134
+ collector.cmetrics.keys.include?(v.intern)
135
+ end
136
+ assert_true(metric_exists)
137
+ end
138
+ end
139
+
140
+ def test_without_discards
141
+ omit "/proc/diskstats is only available on *nix" unless Fluent.linux?
142
+
143
+ # lower than 4.18 do not contain it
144
+ stub(Etc).uname { {release: "2.4.20-1-amd64"} }
145
+ parse(DUMMY_DISKSTATS) do |collector|
146
+ no_metric = Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::DISCARD_METRIC_NAMES.none? do |v|
147
+ collector.cmetrics.keys.include?(v.intern)
148
+ end
149
+ assert_true(no_metric)
150
+ end
151
+ end
152
+
153
+ def test_discard_values
154
+ omit "/proc/diskstats is only available on *nix" unless Fluent.linux?
155
+
156
+ stub(Etc).uname { {release: "4.18.0-1-amd64"} }
157
+ parse(DUMMY_DISKSTATS) do |collector|
158
+ assert_equal([15000.0, 16000.0, 17000.0, 18.0],
159
+ [collector.cmetrics[:discards_completed_total].val(["nvme0n1"]),
160
+ collector.cmetrics[:discards_merged_total].val(["nvme0n1"]),
161
+ collector.cmetrics[:discarded_sectors_total].val(["nvme0n1"]),
162
+ collector.cmetrics[:discard_time_seconds_total].val(["nvme0n1"])])
163
+ end
164
+ end
165
+ end
166
+
167
+ sub_test_case "flush metrics" do
168
+ def test_with_flush
169
+ # over 5.5 contains flush metrics
170
+ stub(Etc).uname { {release: "5.5.0-0-amd64"} }
171
+ parse(DUMMY_DISKSTATS) do |collector|
172
+ metric = Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::FLUSH_METRIC_NAMES.all? do |v|
173
+ collector.cmetrics.keys.include?(v.intern)
174
+ end
175
+ assert_true(metric)
176
+ end
177
+ end
178
+
179
+ def test_without_flush
180
+ # lower than 5.5 do not contain flush metrics
181
+ stub(Etc).uname { {release: "5.4.0-8-amd64"} }
182
+ parse(DUMMY_DISKSTATS) do |collector|
183
+ no_metric = Fluent::Plugin::NodeExporter::DiskstatsMetricsCollector::FLUSH_METRIC_NAMES.none? do |v|
184
+ collector.cmetrics.keys.include?(v.intern)
185
+ end
186
+ assert_true(no_metric)
187
+ end
188
+ end
189
+
190
+ def test_flush_values
191
+ stub(Etc).uname { {release: "5.5.0-1-amd64"} }
192
+ parse(DUMMY_DISKSTATS) do |collector|
193
+ assert_equal([19000.0, 20.0],
194
+ [collector.cmetrics[:flush_requests_total].val(["nvme0n1"]),
195
+ collector.cmetrics[:flush_requests_time_seconds_total].val(["nvme0n1"])])
196
+ end
197
+ end
198
+
199
+ end
200
+ end
@@ -0,0 +1,39 @@
1
+ require "helper"
2
+ require "fluent/plugin/in_node_exporter_metrics"
3
+ require "fluent/plugin/node_exporter/filefd_collector"
4
+
5
+ class FilefdColectorTest < Test::Unit::TestCase
6
+ sub_test_case "filefd" do
7
+
8
+ def parse(input)
9
+ stub(File).read { input }
10
+ collector = Fluent::Plugin::NodeExporter::FilefdMetricsCollector.new
11
+ collector.run
12
+ yield collector
13
+ end
14
+
15
+ def test_invalid_fields
16
+ proc_filefd = <<EOS
17
+ 100 0 10000 1
18
+ EOS
19
+ parse(proc_filefd) do |collector|
20
+ allocated = collector.cmetrics[:filefd_allocated]
21
+ maximum = collector.cmetrics[:filefd_maximum]
22
+ assert_equal([0.0, 0.0],
23
+ [allocated.val, maximum.val])
24
+ end
25
+ end
26
+
27
+ def test_valid_fields
28
+ proc_filefd = <<EOS
29
+ 100 0 10000
30
+ EOS
31
+ parse(proc_filefd) do |collector|
32
+ allocated = collector.cmetrics[:filefd_allocated]
33
+ maximum = collector.cmetrics[:filefd_maximum]
34
+ assert_equal([100.0, 10000.0],
35
+ [allocated.val, maximum.val])
36
+ end
37
+ end
38
+ end
39
+ end