cloudstack_stats 0.3.0 → 0.4.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 +4 -4
- data/lib/cloudstack_stats/cli.rb +1 -1
- data/lib/cloudstack_stats/feed.rb +28 -9
- data/lib/cloudstack_stats/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9c84e386e53ef11f8cb75da2f779edb18f3bcff
|
4
|
+
data.tar.gz: 6650c96957ed98ab9fb0ad78d112ddfeff5aed49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f9e2d5611ebc92fc6637473af883842a0e4a29c396fffde8e3ec2e17c49719bdd3414a596288c46fd0b9b8029890803496a1033ae84bc6fc2d0fa642be32320
|
7
|
+
data.tar.gz: 9196ef85ab3a8349bf4f81e9d628f8d582c158fb959fad516fc4d47530ebfad6404a1d77a54705421d992ebd5f3b8880a649c62566e710076d263362f21a21dd
|
data/lib/cloudstack_stats/cli.rb
CHANGED
@@ -21,9 +21,10 @@ module CloudstackStats
|
|
21
21
|
@user = opts[:influx_user]
|
22
22
|
@password = opts[:influx_password]
|
23
23
|
@debug = opts[:debug]
|
24
|
+
@total = {type: "total", stats: [{"name" => "_total_"}]}
|
24
25
|
end
|
25
26
|
|
26
|
-
def write(stats)
|
27
|
+
def write(stats, total = true)
|
27
28
|
uri = URI.parse(
|
28
29
|
URI.join(
|
29
30
|
@url,
|
@@ -43,25 +44,43 @@ module CloudstackStats
|
|
43
44
|
|
44
45
|
|
45
46
|
type = stats[:type]
|
46
|
-
stats[:stats].
|
47
|
+
stats[:stats].each do |stat|
|
48
|
+
add_to_total(stat) if total
|
47
49
|
request.body = line = stat_to_line(stat, type)
|
48
50
|
puts line if @debug
|
49
51
|
response = http.request(request)
|
50
52
|
yield(stat, response) if block_given?
|
51
53
|
end
|
54
|
+
if total
|
55
|
+
write(@total, total = false) {|stat, response| yield(stat, response)}
|
56
|
+
end
|
52
57
|
end
|
53
58
|
|
54
59
|
private
|
55
60
|
|
56
61
|
# builds influxdb line protocol strings
|
57
62
|
def stat_to_line(obj, type)
|
58
|
-
fields = CloudstackStats::CS_STATS.map {|name| "#{name}=#{obj[name]
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
fields = CloudstackStats::CS_STATS.map {|name| "#{name}=#{obj[name].to_i}i" }
|
64
|
+
unless type == "total"
|
65
|
+
tags = CloudstackStats::CS_TAGS.map {|name| "#{name}=#{obj[name]}" }
|
66
|
+
end
|
67
|
+
line = "#{type}.#{normalize_name(obj["name"])},type=#{type}"
|
68
|
+
line += "," + tags.join(",") if tags
|
69
|
+
line += " " + fields.join(",")
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_to_total(obj)
|
73
|
+
CloudstackStats::CS_STATS.each do |stat|
|
74
|
+
if @total[:stats][0].key? stat
|
75
|
+
@total[:stats][0][stat] += obj[stat].to_i
|
76
|
+
else
|
77
|
+
@total[:stats][0][stat] = obj[stat].to_i
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def normalize_name(name)
|
83
|
+
name.downcase.tr(" ", "-").tr("--", "-").gsub(/[^0-9A-Za-z\-\_]/, '')
|
65
84
|
end
|
66
85
|
|
67
86
|
end # class
|