cloudstack_stats 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 988f2e586d5ee736a7396e7c19d58554c8056af6
4
- data.tar.gz: 6202f3b90f92c1eaec5d09dc72903b7073e0f09f
3
+ metadata.gz: e9c84e386e53ef11f8cb75da2f779edb18f3bcff
4
+ data.tar.gz: 6650c96957ed98ab9fb0ad78d112ddfeff5aed49
5
5
  SHA512:
6
- metadata.gz: b8a5f33f6982781af2e5c0e766ff9980135d7df471845adbace4d17f498ae9c97941d6d27c7c4ca9f1eede27b4d182bdfde8ce5f598697fcdf7ee91346730d5e
7
- data.tar.gz: 9f4758a4b2485375ddf1b5c7a84a0be9262b8614d9c5608eb687a970529e46ad5fd572a0a17673a169cef466d37f86abde6e629cf52a679ff247c848d671753d
6
+ metadata.gz: 9f9e2d5611ebc92fc6637473af883842a0e4a29c396fffde8e3ec2e17c49719bdd3414a596288c46fd0b9b8029890803496a1033ae84bc6fc2d0fa642be32320
7
+ data.tar.gz: 9196ef85ab3a8349bf4f81e9d628f8d582c158fb959fad516fc4d47530ebfad6404a1d77a54705421d992ebd5f3b8880a649c62566e710076d263362f21a21dd
@@ -10,7 +10,7 @@ module CloudstackStats
10
10
  package_name "cloudstack_stats"
11
11
 
12
12
  class_option :cloudstack_url,
13
- default: "http://localhost:8080/client/",
13
+ default: "http://localhost:8080/client/api",
14
14
  aliases: '-A',
15
15
  desc: 'CloudStack API URL'
16
16
 
@@ -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].map do |stat|
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] || 0}i" }
59
- tags = CloudstackStats::CS_TAGS.map {|name| "#{name}=#{obj[name]}" }
60
- "#{type}." +
61
- obj["name"].downcase.tr(" ", "-").tr("--", "-").gsub(/[^0-9A-Za-z\-\_]/, '') +
62
- ",type=#{type}" +
63
- "," + tags.join(",") +
64
- " " + fields.join(",")
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
@@ -1,3 +1,3 @@
1
1
  module CloudstackStats
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - niwo