Top Level Namespace
Defined Under Namespace
Modules: Fluent, HKeyPerfDataReader, WinFFI
Instance Method Summary
collapse
Instance Method Details
#get_data_from_prometheus_windows_exporter(uri = "http://localhost:9182/metrics") ⇒ Object
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
|
# File 'lib/fluent/plugin/test_hpd_reader.rb', line 21
def get_data_from_prometheus_windows_exporter(uri = "http://localhost:9182/metrics")
response = Net::HTTP.get_response(URI(uri))
return nil, false unless response.code == "200"
lines = response.body.split("\n")
.map { |line| line.strip}
.select { |line| !line.empty? && !line.start_with?("#") }
prometheous_records = []
lines.each do |line|
record = {
"name" => "",
"value" => 0.0,
"labels" => {},
}
i = line.index("{")
no_label_data = i.nil?
if no_label_data
i = line.index(" ")
record["name"] = line[0..i-1]
record["value"] = line[i+1..].to_f
else
record["name"] = line[0..i-1]
end_label_i = line.index("}")
record["value"] = line[end_label_i+1..].to_f
label = line[i+1..end_label_i-1]
while true
i = label.index("=\"")
break if i.nil?
key = label[0..i-1]
end_val_i = label.index("\"", i+2)
val = label[i+2..end_val_i-1]
record["labels"][key] = val
label = label[end_val_i+2..]
break if label.to_s.empty?
end
end
prometheous_records.append(record)
end
return prometheous_records, true
end
|
#is_same_hash?(h1, h2) ⇒ Boolean
67
68
69
|
# File 'lib/fluent/plugin/test_hpd_reader.rb', line 67
def is_same_hash?(h1, h2)
h1.to_a.map { |k, v| [k.to_s, v] } == h2.to_a.map { |k, v| [k.to_s, v] }
end
|