Module: Cloudcost::VolumeInfluxdbOutput

Included in:
VolumeList
Defined in:
lib/cloudcost/commands/volume/volume_influxdb_output.rb

Overview

InfluxDB output methods for the ServerList class

Instance Method Summary collapse

Instance Method Details

#totals_influx_line_protocolObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cloudcost/commands/volume/volume_influxdb_output.rb', line 6

def totals_influx_line_protocol
  lines = []
  tag_set = [
    "profile=#{@options[:profile] || "?"}",
    "state=#{volumes_attached_state}"
  ]
  metrics = calculate_totals
  [
    { field: "ssd_gb", key: :size_ssd, unit: "i" },
    { field: "bulk_gb", key: :size_bulk, unit: "i" },
    { field: "chf_per_day", key: :size, unit: "" }
  ].each do |field|
    lines << %(
      cloudscaleVolumeCosts,#{tag_set.join(",")}
      #{field[:field]}=#{metrics[field[:key]]}#{field[:unit]}
    ).gsub(/\s+/, " ").strip
  end
  lines.join("\n")
end

#volumes_attached_stateObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/cloudcost/commands/volume/volume_influxdb_output.rb', line 26

def volumes_attached_state
  case @options[:attached]
  when true
    "attached"
  when false
    "unattached"
  else
    "all"
  end
end