one2influx 0.0.2 → 0.0.3

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: de061eb5b3f384bc94806b890ebbffbe56a8e9aa
4
- data.tar.gz: 48b8af535409c35f0125a2d210ec1d72bd1fa38e
3
+ metadata.gz: 6353b4846f2c96cbc78ea02b0a811f790eba52c5
4
+ data.tar.gz: 3f70ee245cc8f705ada540f0c9278695884e95d3
5
5
  SHA512:
6
- metadata.gz: 2197a320a2cf5c36f9817e3223c81d07977c2cd243653aabb52eae6f1d0799f56c744abbc2dfe9855b80111fe239921ca903e2a092798935ffcc3aac7deefa95
7
- data.tar.gz: 8088190af25852639289226a1d6e2ccc11896dcc73428afef171b4ed0816a9f0a64e5b366d8d0def4410aa5b24ee6d80e448e39656d15bdf6f309e4edc5aca51
6
+ metadata.gz: 92362846a7b6bbda1c22208fab6bdc80029155a84120829c1a6c48eae2095ae9cff2466268525e5b021d7cd128b47c8b260eeaa346eaa84f7381d3c348a66733
7
+ data.tar.gz: b3245161ecf2eb9d4f1c675dd2f4834f4dfac6607dc8396c1835d3b2fb31ac22b862de6df9938043930889b9811ca12f1a5bd26f4754f5891a0e37e03c770e13
data/bin/one2influx CHANGED
@@ -4,6 +4,7 @@ begin
4
4
  require 'rubygems'
5
5
  rescue Exception
6
6
  $stderr.puts 'Failed to load rubygems!'
7
+ exit 1
7
8
  end
8
9
 
9
10
  # add local dirs to load path if necessary
@@ -0,0 +1,83 @@
1
+ # Logfile created on 2015-05-17 16:56:57 +0200 by logger.rb/47272
2
+ I, [2015-05-17T16:56:57.070366 #7964] INFO -- : Connection with ONE verified.
3
+ I, [2015-05-17T16:56:57.084159 #7964] INFO -- : Connection to InfluxDB database 'test' with retention policy 'ten_hours' verified.
4
+ E, [2015-05-17T16:56:57.130222 #7964] ERROR -- : Unable to get metric 'HOST_MEM_ALOC'. MAX_MEM is 0.
5
+ E, [2015-05-17T16:56:57.130323 #7964] ERROR -- : Unable to get metric 'HOST_MEM_LOAD'. MAX_MEM is 0.
6
+ E, [2015-05-17T16:56:57.130367 #7964] ERROR -- : Unable to get metric 'HOST_MEM_WASTE'. HOST_MEM_ALOC is missing.
7
+ E, [2015-05-17T16:56:57.130404 #7964] ERROR -- : Unable to get metric 'HOST_CPU_ALOC'. MAX_CPU is 0.
8
+ E, [2015-05-17T16:56:57.130439 #7964] ERROR -- : Unable to get metric 'HOST_CPU_LOAD'. MAX_CPU is 0.
9
+ E, [2015-05-17T16:56:57.130474 #7964] ERROR -- : Unable to get metric 'HOST_CPU_WASTE'. HOST_CPU_ALOC is missing.
10
+ I, [2015-05-17T16:56:57.146043 #7964] INFO -- : Fetched data for 3 VMs, 2 hosts, 4 datastores and 1 clusters.
11
+ I, [2015-05-17T16:56:57.146134 #7964] INFO -- : Successfully fetched data from ONE.
12
+ I, [2015-05-17T16:56:57.320825 #7964] INFO -- : Successfully stored 75 data points.
13
+ I, [2015-05-17T16:56:57.321001 #7964] INFO -- : Successfully stored 75 data points.
14
+ E, [2015-05-17T16:57:12.370386 #7964] ERROR -- : Unable to get metric 'HOST_MEM_ALOC'. MAX_MEM is 0.
15
+ E, [2015-05-17T16:57:12.370507 #7964] ERROR -- : Unable to get metric 'HOST_MEM_LOAD'. MAX_MEM is 0.
16
+ E, [2015-05-17T16:57:12.370574 #7964] ERROR -- : Unable to get metric 'HOST_MEM_WASTE'. HOST_MEM_ALOC is missing.
17
+ E, [2015-05-17T16:57:12.370630 #7964] ERROR -- : Unable to get metric 'HOST_CPU_ALOC'. MAX_CPU is 0.
18
+ E, [2015-05-17T16:57:12.370711 #7964] ERROR -- : Unable to get metric 'HOST_CPU_LOAD'. MAX_CPU is 0.
19
+ E, [2015-05-17T16:57:12.370765 #7964] ERROR -- : Unable to get metric 'HOST_CPU_WASTE'. HOST_CPU_ALOC is missing.
20
+ I, [2015-05-17T16:57:12.385202 #7964] INFO -- : Fetched data for 3 VMs, 2 hosts, 4 datastores and 1 clusters.
21
+ I, [2015-05-17T16:57:12.385300 #7964] INFO -- : Successfully fetched data from ONE.
22
+ I, [2015-05-17T16:57:12.412689 #7964] INFO -- : Successfully stored 75 data points.
23
+ I, [2015-05-17T16:57:12.412788 #7964] INFO -- : Successfully stored 75 data points.
24
+ E, [2015-05-17T16:57:27.461425 #7964] ERROR -- : Unable to get metric 'HOST_MEM_ALOC'. MAX_MEM is 0.
25
+ E, [2015-05-17T16:57:27.461550 #7964] ERROR -- : Unable to get metric 'HOST_MEM_LOAD'. MAX_MEM is 0.
26
+ E, [2015-05-17T16:57:27.461623 #7964] ERROR -- : Unable to get metric 'HOST_MEM_WASTE'. HOST_MEM_ALOC is missing.
27
+ E, [2015-05-17T16:57:27.461684 #7964] ERROR -- : Unable to get metric 'HOST_CPU_ALOC'. MAX_CPU is 0.
28
+ E, [2015-05-17T16:57:27.461760 #7964] ERROR -- : Unable to get metric 'HOST_CPU_LOAD'. MAX_CPU is 0.
29
+ E, [2015-05-17T16:57:27.461833 #7964] ERROR -- : Unable to get metric 'HOST_CPU_WASTE'. HOST_CPU_ALOC is missing.
30
+ I, [2015-05-17T16:57:27.477837 #7964] INFO -- : Fetched data for 3 VMs, 2 hosts, 4 datastores and 1 clusters.
31
+ I, [2015-05-17T16:57:27.477929 #7964] INFO -- : Successfully fetched data from ONE.
32
+ I, [2015-05-17T16:57:27.505904 #7964] INFO -- : Successfully stored 75 data points.
33
+ I, [2015-05-17T16:57:27.506016 #7964] INFO -- : Successfully stored 75 data points.
34
+ E, [2015-05-17T16:57:43.226372 #7964] ERROR -- : Unable to get metric 'HOST_MEM_ALOC'. MAX_MEM is 0.
35
+ E, [2015-05-17T16:57:43.226558 #7964] ERROR -- : Unable to get metric 'HOST_MEM_LOAD'. MAX_MEM is 0.
36
+ E, [2015-05-17T16:57:43.226812 #7964] ERROR -- : Unable to get metric 'HOST_MEM_WASTE'. HOST_MEM_ALOC is missing.
37
+ E, [2015-05-17T16:57:43.226968 #7964] ERROR -- : Unable to get metric 'HOST_CPU_ALOC'. MAX_CPU is 0.
38
+ E, [2015-05-17T16:57:43.227776 #7964] ERROR -- : Unable to get metric 'HOST_CPU_LOAD'. MAX_CPU is 0.
39
+ E, [2015-05-17T16:57:43.228383 #7964] ERROR -- : Unable to get metric 'HOST_CPU_WASTE'. HOST_CPU_ALOC is missing.
40
+ I, [2015-05-17T16:57:43.251970 #7964] INFO -- : Fetched data for 3 VMs, 2 hosts, 4 datastores and 1 clusters.
41
+ I, [2015-05-17T16:57:43.252067 #7964] INFO -- : Successfully fetched data from ONE.
42
+ I, [2015-05-17T16:57:43.278282 #7964] INFO -- : Successfully stored 75 data points.
43
+ I, [2015-05-17T16:57:43.278375 #7964] INFO -- : Successfully stored 75 data points.
44
+ E, [2015-05-17T16:57:58.340411 #7964] ERROR -- : Unable to get metric 'HOST_MEM_ALOC'. MAX_MEM is 0.
45
+ E, [2015-05-17T16:57:58.340546 #7964] ERROR -- : Unable to get metric 'HOST_MEM_LOAD'. MAX_MEM is 0.
46
+ E, [2015-05-17T16:57:58.340606 #7964] ERROR -- : Unable to get metric 'HOST_MEM_WASTE'. HOST_MEM_ALOC is missing.
47
+ E, [2015-05-17T16:57:58.340807 #7964] ERROR -- : Unable to get metric 'HOST_CPU_ALOC'. MAX_CPU is 0.
48
+ E, [2015-05-17T16:57:58.340855 #7964] ERROR -- : Unable to get metric 'HOST_CPU_LOAD'. MAX_CPU is 0.
49
+ E, [2015-05-17T16:57:58.340899 #7964] ERROR -- : Unable to get metric 'HOST_CPU_WASTE'. HOST_CPU_ALOC is missing.
50
+ I, [2015-05-17T16:57:58.355678 #7964] INFO -- : Fetched data for 3 VMs, 2 hosts, 4 datastores and 1 clusters.
51
+ I, [2015-05-17T16:57:58.355776 #7964] INFO -- : Successfully fetched data from ONE.
52
+ I, [2015-05-17T16:57:58.377838 #7964] INFO -- : Successfully stored 75 data points.
53
+ I, [2015-05-17T16:57:58.377966 #7964] INFO -- : Successfully stored 75 data points.
54
+ E, [2015-05-17T16:58:13.453706 #7964] ERROR -- : Unable to get metric 'HOST_MEM_ALOC'. MAX_MEM is 0.
55
+ E, [2015-05-17T16:58:13.453885 #7964] ERROR -- : Unable to get metric 'HOST_MEM_LOAD'. MAX_MEM is 0.
56
+ E, [2015-05-17T16:58:13.453980 #7964] ERROR -- : Unable to get metric 'HOST_MEM_WASTE'. HOST_MEM_ALOC is missing.
57
+ E, [2015-05-17T16:58:13.454058 #7964] ERROR -- : Unable to get metric 'HOST_CPU_ALOC'. MAX_CPU is 0.
58
+ E, [2015-05-17T16:58:13.454151 #7964] ERROR -- : Unable to get metric 'HOST_CPU_LOAD'. MAX_CPU is 0.
59
+ E, [2015-05-17T16:58:13.454203 #7964] ERROR -- : Unable to get metric 'HOST_CPU_WASTE'. HOST_CPU_ALOC is missing.
60
+ I, [2015-05-17T16:58:13.474496 #7964] INFO -- : Fetched data for 3 VMs, 2 hosts, 4 datastores and 1 clusters.
61
+ I, [2015-05-17T16:58:13.474604 #7964] INFO -- : Successfully fetched data from ONE.
62
+ I, [2015-05-17T16:58:13.497888 #7964] INFO -- : Successfully stored 75 data points.
63
+ I, [2015-05-17T16:58:13.498017 #7964] INFO -- : Successfully stored 75 data points.
64
+ E, [2015-05-17T16:58:28.554575 #7964] ERROR -- : Unable to get metric 'HOST_MEM_ALOC'. MAX_MEM is 0.
65
+ E, [2015-05-17T16:58:28.554771 #7964] ERROR -- : Unable to get metric 'HOST_MEM_LOAD'. MAX_MEM is 0.
66
+ E, [2015-05-17T16:58:28.554848 #7964] ERROR -- : Unable to get metric 'HOST_MEM_WASTE'. HOST_MEM_ALOC is missing.
67
+ E, [2015-05-17T16:58:28.554898 #7964] ERROR -- : Unable to get metric 'HOST_CPU_ALOC'. MAX_CPU is 0.
68
+ E, [2015-05-17T16:58:28.555085 #7964] ERROR -- : Unable to get metric 'HOST_CPU_LOAD'. MAX_CPU is 0.
69
+ E, [2015-05-17T16:58:28.555137 #7964] ERROR -- : Unable to get metric 'HOST_CPU_WASTE'. HOST_CPU_ALOC is missing.
70
+ I, [2015-05-17T16:58:28.570603 #7964] INFO -- : Fetched data for 3 VMs, 2 hosts, 4 datastores and 1 clusters.
71
+ I, [2015-05-17T16:58:28.570708 #7964] INFO -- : Successfully fetched data from ONE.
72
+ I, [2015-05-17T16:58:28.595736 #7964] INFO -- : Successfully stored 75 data points.
73
+ I, [2015-05-17T16:58:28.595837 #7964] INFO -- : Successfully stored 75 data points.
74
+ E, [2015-05-17T16:58:43.651964 #7964] ERROR -- : Unable to get metric 'HOST_MEM_ALOC'. MAX_MEM is 0.
75
+ E, [2015-05-17T16:58:43.652090 #7964] ERROR -- : Unable to get metric 'HOST_MEM_LOAD'. MAX_MEM is 0.
76
+ E, [2015-05-17T16:58:43.652144 #7964] ERROR -- : Unable to get metric 'HOST_MEM_WASTE'. HOST_MEM_ALOC is missing.
77
+ E, [2015-05-17T16:58:43.652197 #7964] ERROR -- : Unable to get metric 'HOST_CPU_ALOC'. MAX_CPU is 0.
78
+ E, [2015-05-17T16:58:43.652238 #7964] ERROR -- : Unable to get metric 'HOST_CPU_LOAD'. MAX_CPU is 0.
79
+ E, [2015-05-17T16:58:43.652317 #7964] ERROR -- : Unable to get metric 'HOST_CPU_WASTE'. HOST_CPU_ALOC is missing.
80
+ I, [2015-05-17T16:58:43.670538 #7964] INFO -- : Fetched data for 3 VMs, 2 hosts, 4 datastores and 1 clusters.
81
+ I, [2015-05-17T16:58:43.670634 #7964] INFO -- : Successfully fetched data from ONE.
82
+ I, [2015-05-17T16:58:43.692999 #7964] INFO -- : Successfully stored 75 data points.
83
+ I, [2015-05-17T16:58:43.693108 #7964] INFO -- : Successfully stored 75 data points.
@@ -6,7 +6,7 @@ class One2Influx::Config
6
6
  ## EDIT THIS PART IF NECESSARY ##
7
7
  ##############################################################################
8
8
 
9
- # Allowed values are number of seconds, minutes, hours
9
+ # Data fetch interval. Allowed values are number of seconds, minutes, hours
10
10
  # separated by space
11
11
  @@fetch_interval = '30 seconds'
12
12
 
@@ -14,7 +14,7 @@ class One2Influx::Config
14
14
  #####################################
15
15
  @@one = {
16
16
  # Login credentials separated by semicolon
17
- credentials: 'user:password',
17
+ credentials: 'oneadmin:opennebula',
18
18
 
19
19
  # XML_RPC endpoint where OpenNebula is listening
20
20
  endpoint: 'http://localhost:2633/RPC2'
@@ -36,8 +36,6 @@ class One2Influx::Config
36
36
  database: 'test',
37
37
 
38
38
  # Retention policy for records with the smallest granularity
39
- # you have to create retention policy manually if you want to change
40
- # this one
41
39
  policy: 'ten_hours'
42
40
  }
43
41
 
@@ -47,7 +45,8 @@ class One2Influx::Config
47
45
  # Level to use. Logger::INFO, Logger::WARN, Logger::ERROR are supported
48
46
  level: Logger::INFO,
49
47
 
50
- # Path to log file
48
+ # Path to log file, when empty, one2influx.log is written into directory
49
+ # where the binary is run from
51
50
  path: ''
52
51
  }
53
52
 
@@ -62,22 +61,33 @@ class One2Influx::Config
62
61
  HOST_NAME: 'NAME',
63
62
  CLUSTER_ID: 'CLUSTER_ID',
64
63
  CLUSTER_NAME: 'CLUSTER',
64
+ #HOST_STATE: 'STATE', # [int] host state
65
+ #IM_MAD: 'IM_MAD', # [string] monitoring manager driver
66
+ #VM_MAD: 'VM_MAD', # [string] virtualization manager driver
67
+ #VN_MAD: 'VN_MAD', # [string] virtual network manager driver
65
68
  DSS_IDS: '' # [string] IDs of datastores that this host uses
66
69
  # encoded in form ,,ID_1,,ID_2...,,
67
70
  },
68
71
  metrics: [
69
72
  'MEM_USAGE', # [kB] memory requested by VMs
70
73
  'MAX_MEM', # [kB] total memory available in host
71
- 'FREE_MEM', # [kB] free memory returned by probes
72
- 'USED_MEM', # [kB] memory used by all host processes over MAX_MEM
73
- 'CPU_USAGE', # [%] usage of CPU calculated by ONE as the summatory
74
+ 'FREE_MEM', # [kB] free memory in host, MAX_MEM - USED_MEM
75
+ 'USED_MEM', # [kB] used memory in host -(buffers+cache)
76
+ 'CPU_USAGE', # [%] usage of CPU calculated by ONE as the sum of
74
77
  # CPU requested by all VMs running in the host
75
78
  'MAX_CPU', # [%] total CPU in the host (number of cores * 100)
76
79
  'FREE_CPU', # [%] free CPU as returned by the probes
77
80
  'USED_CPU' # [%] CPU used by all host processes over a total
78
81
  # of # cores * 100
79
82
  ],
80
- cust_metrics: []
83
+ cust_metrics: [
84
+ #'HOST_MEM_ALOC', # [%] MEM_USAGE / MAX_MEM
85
+ #'HOST_MEM_LOAD', # [%] USED_MEM / MAX_MEM
86
+ #'HOST_MEM_WASTE', # [] HOST_MEM_ALOC / HOST_MEM_LOAD
87
+ #'HOST_CPU_ALOC', # [%] CPU_USAGE / MAX_CPU
88
+ #'HOST_CPU_LOAD', # [%] USED_CPU / MAX_CPU
89
+ #'HOST_CPU_WASTE', # [] HOST_CPU_ALOC / HOST_CPU_LOAD
90
+ ]
81
91
  },
82
92
  # Virtual machine
83
93
  vm: {
@@ -87,10 +97,12 @@ class One2Influx::Config
87
97
  HOST_ID: 'HOST_ID',
88
98
  HOST_NAME: 'HOST_NAME',
89
99
  VM_NAME: 'NAME',
90
- UID: 'UID', # [int] user's ID
91
- GID: 'GID', # [int] group's ID
92
- UNAME: 'UNAME', # [string] user's name
93
- GNAME: 'GNAME' # [string] group's name
100
+ UID: 'UID', # [int] user's ID
101
+ GID: 'GID', # [int] group's ID
102
+ UNAME: 'UNAME', # [string] user's name
103
+ GNAME: 'GNAME', # [string] group's name
104
+ #VM_STATE: 'STATE', # [int] virtual machine state
105
+ #LCM_STATE: 'LCM_STATE' # [int] substates for ACTIVE state
94
106
  },
95
107
  metrics: [
96
108
  'MEMORY', # [kB] memory consumption
@@ -124,7 +136,9 @@ class One2Influx::Config
124
136
  'FREE_MB', # [MB] free space
125
137
  'USED_MB' # [MB] used space
126
138
  ],
127
- cust_metrics: []
139
+ cust_metrics: [
140
+ #'DS_LOAD' # [%] USED_MB / TOTAL_MB
141
+ ]
128
142
  },
129
143
  # Cluster
130
144
  cluster: {
@@ -132,22 +146,23 @@ class One2Influx::Config
132
146
  CLUSTER_NAME: 'NAME'
133
147
  },
134
148
  metrics: [
135
- 'CLUSTER_MEM_USAGE', # [kB] memory requested by all VMs in cluster
136
- 'CLUSTER_MAX_MEM', # [kB] total memory available in all hosts
137
- 'CLUSTER_FREE_MEM', # [kB] free memory of all hosts returned
138
- # by probes
139
- 'CLUSTER_USED_MEM', # [kB] memory used by all processes of all
140
- # hosts over MAX_MEM
141
- 'CLUSTER_CPU_USAGE', # [%] usage of CPU calculated by ONE as the
142
- # sum of CPU requested by all VMs running
143
- # in the cluster
144
- 'CLUSTER_MAX_CPU', # [%] total CPU in the cluster
145
- # (number of cores * 100)
146
- 'CLUSTER_FREE_CPU', # [%] free CPU as returned by the probes
147
- 'CLUSTER_USED_CPU' # [%] CPU used by all processes of all hosts
148
- # over a total of # cores * 100
149
+ 'CLUSTER_MEM_USAGE', # [kB] sum of MEM_USAGE for whole cluster
150
+ 'CLUSTER_MAX_MEM', # [kB] sum of MAX_MEM for whole cluster
151
+ 'CLUSTER_FREE_MEM', # [kB] sum of FREE_MEM for whole cluster
152
+ 'CLUSTER_USED_MEM', # [kB] sum of USED_MEM for whole cluster
153
+ 'CLUSTER_CPU_USAGE', # [%] sum of CPU_USAGE for whole cluster
154
+ 'CLUSTER_MAX_CPU', # [%] sum of MAX_CPU for whole cluster
155
+ 'CLUSTER_FREE_CPU', # [%] sum of FREE_CPU for whole cluster
156
+ 'CLUSTER_USED_CPU' # [%] sum of USED_CPU for whole cluster
149
157
  ],
150
- cust_metrics: []
158
+ cust_metrics: [
159
+ #'CLUSTER_MEM_ALOC', # [%] CLUSTER_MEM_USAGE / CLUSTER_MAX_MEM
160
+ #'CLUSTER_MEM_LOAD', # [%]CLUSTER_USED_MEM / CLUSTER_MAX_MEM
161
+ #'CLUSTER_MEM_WASTE', # [] CLUSTER_MEM_ALOC / CLUSTER_MEM_LOAD
162
+ #'CLUSTER_CPU_ALOC', # [%] CLUSTER_CPU_USAGE / CLUSTER_MAX_CPU
163
+ #'CLUSTER_CPU_LOAD', # [%] CLUSTER_USED_CPU / CLUSTER_MAX_CPU
164
+ #'CLUSTER_CPU_WASTE', # [] CLUSTER_CPU_ALOC / CLUSTER_CPU_LOAD
165
+ ]
151
166
  }
152
167
  }
153
168
 
@@ -17,8 +17,8 @@ class One2Influx::Data
17
17
  raise rc.message if OpenNebula.is_error?(rc)
18
18
 
19
19
  # Get data from all hosts in the pool
20
- hosts_xml = {} # XML of all hosts, passed to theirs cluster
21
- oo_hosts = [] # array of all instances of OneObject::Host
20
+ oo_hosts = {} # hash of all instances of OneObject::Host
21
+ # in form {ID => host}
22
22
  host_pool.each do |one_host|
23
23
  host = ::One2Influx::Host.new(one_host.to_xml, @client)
24
24
  # Get data from all VMs belonging to current host
@@ -31,8 +31,7 @@ class One2Influx::Data
31
31
  @points += vm.serialize_as_points
32
32
  counter[:vms] += 1
33
33
  end
34
- hosts_xml[host.tags[:HOST_ID]] = one_host.to_xml
35
- oo_hosts << host
34
+ oo_hosts[host.tags[:HOST_ID].to_sym] = host
36
35
  @points += host.serialize_as_points
37
36
  counter[:hosts] += 1
38
37
  end
@@ -41,10 +40,10 @@ class One2Influx::Data
41
40
  cluster_pool = OpenNebula::ClusterPool.new(@client)
42
41
  rc = cluster_pool.info
43
42
  raise rc.message if OpenNebula.is_error?(rc)
44
- #
43
+
45
44
  # Get data from all clusters in the pool
46
45
  cluster_pool.each do |one_cluster|
47
- cluster = ::One2Influx::Cluster.new(one_cluster.to_xml, @client,hosts_xml)
46
+ cluster = ::One2Influx::Cluster.new(one_cluster.to_xml, @client, oo_hosts)
48
47
  @points += cluster.serialize_as_points
49
48
  counter[:clusters] += 1
50
49
  end
@@ -58,7 +57,7 @@ class One2Influx::Data
58
57
  # It has form {DS_ID_1: [HOST_ID_1, HOST_ID_2, ...], ...}
59
58
  ds_has_hosts = {}
60
59
  if $CFG.storage[:ds][:tags].has_key? :HOSTS_IDS
61
- oo_hosts.each do |host|
60
+ oo_hosts.each do |id, host|
62
61
  host.datastores.each do |ds|
63
62
  ds_has_hosts[ds] ||= []
64
63
  ds_has_hosts[ds] << host.tags[:HOST_ID]
@@ -43,7 +43,7 @@ class One2Influx::Influx
43
43
  req.body = payload.to_json
44
44
  response = make_request(req)
45
45
 
46
- if (not response.nil?) && (response.code != '200')
46
+ if (not response.nil?) && (response.code != '204')
47
47
  raise 'Failed to store data to InfluxDB. Received HTTP code ' +
48
48
  "#{response.code}, body: #{response.body}"
49
49
  end
@@ -4,19 +4,29 @@ class One2Influx::Cluster < ::One2Influx::OneObject
4
4
  #
5
5
  # @param [string] xml representation of cluster
6
6
  # @param [OpenNebula::Client] client connection link to ONE API
7
- # @param [hash] hosts_xml xml representations of hosts in this cluster,
8
- # in hash form {HOST_ID : XML_STRING}
9
- def initialize(xml, client, hosts_xml)
7
+ # @param [hash] oo_hosts hash in form {ID => OneObject::Host} of all hosts
8
+ def initialize(xml, client, oo_hosts)
10
9
  # Load configuration
11
10
  @tag_names = $CFG.storage[:cluster][:tags]
12
11
  @metric_names = $CFG.storage[:cluster][:metrics]
13
12
  @custom_metric_names = $CFG.storage[:cluster][:cust_metrics]
14
- @hosts_xml = hosts_xml
13
+ @hosts = oo_hosts
15
14
 
16
15
  super(xml, client)
17
16
  end
18
17
 
19
- protected
18
+ private
19
+
20
+ # @param [OneObject::Host] host host to fetch metric from
21
+ # @param [string] metric metric to fetch
22
+ # @raise [Exception] fetch error
23
+ # @return metric from host
24
+ def fetch_host_metric(host, metric)
25
+ ni_element = host.doc.css(metric).first
26
+ raise if ni_element.nil?
27
+
28
+ ni_element.content.to_i
29
+ end
20
30
 
21
31
  # Overrides OneObject init_metrics because cluster itself doesn't
22
32
  # have any own metrics, so they are gathered as sum of metrics of
@@ -28,26 +38,95 @@ class One2Influx::Cluster < ::One2Influx::OneObject
28
38
 
29
39
  host_ids = @doc.xpath('//HOSTS/ID').map { |node| node.content }
30
40
  host_ids.each do |id|
31
- host_doc = Nokogiri::XML(@hosts_xml[id])
41
+ host = @hosts[id.to_sym]
42
+
32
43
  @metric_names.each do |metric|
44
+ @metrics[metric.to_sym] ||= 0
33
45
  host_metric = metric.split('CLUSTER_')[1]
34
- unless host_metric.nil?
35
- ni_element = host_doc.css(host_metric).first
46
+ next if host_metric.nil?
47
+
48
+ if host.metrics.has_key? host_metric.to_sym
49
+ @metrics[metric.to_sym] += host.metrics[host_metric.to_sym].to_i
50
+ else
51
+ ni_element = host.doc.css(host_metric).first
36
52
  if ni_element.nil?
37
- $LOG.error "Unable to get metric '#{metric}' in #{self.class}."
38
- else
39
- @metrics[metric.to_s] += ni_element.content.to_i
53
+ # Calculation of this metric would be misleading without this
54
+ # value, so I rather remove whole metric and log failure
55
+ @metric_names = @metric_names.delete(metric)
56
+ @metrics = @metrics.delete(metric.to_sym)
57
+ $LOG.error "Unable to get metric '#{metric}' in #{self.class}." +
58
+ "XML parsing error in host ID=#{id}."
59
+ next
40
60
  end
61
+
62
+ @metrics[metric.to_sym] += ni_element.content.to_i
41
63
  end
42
64
  end
43
65
  end
66
+ end
44
67
 
45
- # Get real percentage for cluster
46
- hosts_count = host_ids.length == 0 ? 1 : host_ids.length
47
- @metrics.each do |metric, value|
48
- if metric.to_s.include? 'CPU'
49
- @metrics[metric] = value / hosts_count
50
- end
68
+ # @raise [Exception] calculation error
69
+ # @return [float] CLUSTER_MEM_USAGE / CLUSTER_MAX_MEM
70
+ def get_CLUSTER_MEM_ALOC
71
+ raise 'CLUSTER_MEM_USAGE is missing.' unless @metrics.has_key? :CLUSTER_MEM_USAGE
72
+ raise 'CLUSTER_MAX_MEM is missing.' unless @metrics.has_key? :CLUSTER_MAX_MEM
73
+ raise 'CLUSTER_MAX_MEM is 0.' if @metrics[:CLUSTER_MAX_MEM] == '0'
74
+
75
+ (@metrics[:CLUSTER_MEM_USAGE].to_f / @metrics[:CLUSTER_MAX_MEM].to_f).round(4)*100
76
+ end
77
+
78
+ # @raise [Exception] calculation error
79
+ # @return [float] CLUSTER_USED_MEM / CLUSTER_MAX_MEM
80
+ def get_CLUSTER_MEM_LOAD
81
+ raise 'CLUSTER_USED_MEM is missing.' unless @metrics.has_key? :CLUSTER_USED_MEM
82
+ raise 'CLUSTER_MAX_MEM is missing.' unless @metrics.has_key? :CLUSTER_MAX_MEM
83
+ raise 'CLUSTER_MAX_MEM is 0.' if @metrics[:CLUSTER_MAX_MEM] == '0'
84
+
85
+ (@metrics[:CLUSTER_USED_MEM].to_f / @metrics[:CLUSTER_MAX_MEM].to_f).round(4)*100
86
+ end
87
+
88
+ # @raise [Exception] calculation error
89
+ # @return [float] CLUSTER_MEM_ALOC / CLUSTER_MEM_LOAD
90
+ def get_CLUSTER_MEM_WASTE
91
+ raise 'CLUSTER_MEM_ALOC is missing.' unless @metrics.has_key? :CLUSTER_MEM_ALOC
92
+ raise 'CLUSTER_MEM_LOAD is missing.' unless @metrics.has_key? :CLUSTER_MEM_LOAD
93
+
94
+ mem_load = @metrics[:CLUSTER_MEM_LOAD] == 0 ? 0.001 : @metrics[:CLUSTER_MEM_LOAD]
95
+
96
+ (@metrics[:CLUSTER_MEM_ALOC] / mem_load).round(2)
97
+ end
98
+
99
+ # @raise [Exception] calculation error
100
+ # @return [float] CLUSTER_CPU_USAGE / CLUSTER_MAX_CPU
101
+ def get_CLUSTER_CPU_ALOC
102
+ raise 'CLUSTER_CPU_USAGE is missing.' unless @metrics.has_key? :CLUSTER_CPU_USAGE
103
+ raise 'CLUSTER_MAX_CPU is missing.' unless @metrics.has_key? :CLUSTER_MAX_CPU
104
+ raise 'CLUSTER_MAX_CPU is 0.' if @metrics[:CLUSTER_MAX_CPU] == '0'
105
+
106
+ (@metrics[:CLUSTER_CPU_USAGE].to_f / @metrics[:CLUSTER_MAX_CPU].to_f).round(4)*100
107
+ end
108
+
109
+ # @raise [Exception] calculation error
110
+ # @return [float] CLUSTER_USED_CPU / CLUSTER_MAX_CPU
111
+ def get_CLUSTER_CPU_LOAD
112
+ raise 'CLUSTER_USED_CPU is missing.' unless @metrics.has_key? :CLUSTER_USED_CPU
113
+ raise 'CLUSTER_MAX_CPU is missing.' unless @metrics.has_key? :CLUSTER_MAX_CPU
114
+ raise 'CLUSTER_MAX_CPU is 0.' if @metrics[:CLUSTER_MAX_CPU] == '0'
115
+
116
+ (@metrics[:CLUSTER_USED_CPU].to_f / @metrics[:CLUSTER_MAX_CPU].to_f).round(4)*100
117
+ end
118
+
119
+ # @raise [Exception] calculation error
120
+ # @return [float] CLUSTER_CPU_ALOC / CLUSTER_CPU_LOAD
121
+ def get_CLUSTER_CPU_WASTE
122
+ raise 'CLUSTER_CPU_ALOC is missing.' unless @metrics.has_key? :CLUSTER_CPU_ALOC
123
+ raise 'CLUSTER_CPU_LOAD is missing.' unless @metrics.has_key? :CLUSTER_CPU_LOAD
124
+
125
+ cpu_load = @metrics[:CLUSTER_CPU_LOAD]
126
+ if @metrics[:CLUSTER_CPU_LOAD] == 0
127
+ cpu_load = 0.001
51
128
  end
129
+
130
+ (@metrics[:CLUSTER_CPU_ALOC] / cpu_load).round(2)
52
131
  end
53
132
  end
@@ -27,4 +27,17 @@ class One2Influx::Datastore < ::One2Influx::OneObject
27
27
  @tags[:HOSTS_IDS] = ',,' + hosts.join(',,') + ',,'
28
28
  end
29
29
  end
30
+
31
+ private
32
+
33
+ # @raise [Exception] calculation error
34
+ # @return [float] USED_MB / TOTAL_MB
35
+ def get_DS_LOAD
36
+ raise 'USED_MB is missing.' unless @metrics.has_key? :USED_MB
37
+ raise 'TOTAL_MB is missing.' unless @metrics.has_key? :TOTAL_MB
38
+ raise 'TOTAL_MB is 0.' if @metrics[:TOTAL_MB] == '0'
39
+
40
+ (@metrics[:USED_MB].to_f / @metrics[:TOTAL_MB].to_f).round(2)
41
+ end
42
+
30
43
  end
@@ -44,4 +44,69 @@ class One2Influx::Host < ::One2Influx::OneObject
44
44
  @datastores << ds.content
45
45
  end
46
46
  end
47
+
48
+ # @raise [Exception] calculation error
49
+ # @return [float] MEM_USAGE / MAX_MEM
50
+ def get_HOST_MEM_ALOC
51
+ raise 'MEM_USAGE is missing.' unless @metrics.has_key? :MEM_USAGE
52
+ raise 'MAX_MEM is missing.' unless @metrics.has_key? :MAX_MEM
53
+ raise 'MAX_MEM is 0.' if @metrics[:MAX_MEM] == '0'
54
+
55
+ (@metrics[:MEM_USAGE].to_f / @metrics[:MAX_MEM].to_f).round(4)*100
56
+ end
57
+
58
+ # @raise [Exception] calculation error
59
+ # @return [float] USED_MEM / MAX_MEM
60
+ def get_HOST_MEM_LOAD
61
+ raise 'USED_MEM is missing.' unless @metrics.has_key? :USED_MEM
62
+ raise 'MAX_MEM is missing.' unless @metrics.has_key? :MAX_MEM
63
+ raise 'MAX_MEM is 0.' if @metrics[:MAX_MEM] == '0'
64
+
65
+ (@metrics[:USED_MEM].to_f / @metrics[:MAX_MEM].to_f).round(4)*100
66
+ end
67
+
68
+ # @raise [Exception] calculation error
69
+ # @return [float] HOST_MEM_ALOC / HOST_MEM_LOAD
70
+ def get_HOST_MEM_WASTE
71
+ raise 'HOST_MEM_ALOC is missing.' unless @metrics.has_key? :HOST_MEM_ALOC
72
+ raise 'HOST_MEM_LOAD is missing.' unless @metrics.has_key? :HOST_MEM_LOAD
73
+
74
+ mem_load = @metrics[:HOST_MEM_LOAD] == 0 ? 0.001 : @metrics[:HOST_MEM_LOAD]
75
+
76
+ (@metrics[:HOST_MEM_ALOC] / mem_load).round(4)*100
77
+ end
78
+
79
+ # @raise [Exception] calculation error
80
+ # @return [float] CPU_USAGE / MAX_CPU
81
+ def get_HOST_CPU_ALOC
82
+ raise 'CPU_USAGE is missing.' unless @metrics.has_key? :CPU_USAGE
83
+ raise 'MAX_CPU is missing.' unless @metrics.has_key? :MAX_CPU
84
+ raise 'MAX_CPU is 0.' if @metrics[:MAX_CPU] == '0'
85
+
86
+ (@metrics[:CPU_USAGE].to_f / @metrics[:MAX_CPU].to_f).round(4)*100
87
+ end
88
+
89
+ # @raise [Exception] calculation error
90
+ # @return [float] USED_CPU / MAX_CPU
91
+ def get_HOST_CPU_LOAD
92
+ raise 'USED_CPU is missing.' unless @metrics.has_key? :USED_CPU
93
+ raise 'MAX_CPU is missing.' unless @metrics.has_key? :MAX_CPU
94
+ raise 'MAX_CPU is 0.' if @metrics[:MAX_CPU] == '0'
95
+
96
+ (@metrics[:USED_CPU].to_f / @metrics[:MAX_CPU].to_f).round(4)*100
97
+ end
98
+
99
+ # @raise [Exception] calculation error
100
+ # @return [float] HOST_CPU_ALOC / HOST_CPU_LOAD
101
+ def get_HOST_CPU_WASTE
102
+ raise 'HOST_CPU_ALOC is missing.' unless @metrics.has_key? :HOST_CPU_ALOC
103
+ raise 'HOST_CPU_LOAD is missing.' unless @metrics.has_key? :HOST_CPU_LOAD
104
+
105
+ cpu_load = @metrics[:HOST_CPU_LOAD]
106
+ if @metrics[:HOST_CPU_LOAD] == 0
107
+ cpu_load = 0.001
108
+ end
109
+
110
+ (@metrics[:HOST_CPU_ALOC] / cpu_load).round(2)
111
+ end
47
112
  end
@@ -47,7 +47,8 @@ class One2Influx::OneObject
47
47
  @tag_names.each do |influx_name, one_name|
48
48
  ni_element = @doc.css(one_name).first
49
49
  if ni_element.nil?
50
- $LOG.error "Unable to get tag '#{one_name}' in #{self.class}."
50
+ $LOG.error "Unable to get tag '#{one_name}' in #{self.class}." +
51
+ 'XML parsing error.'
51
52
  else
52
53
  @tags[influx_name.to_sym] = ni_element.content
53
54
  end
@@ -58,7 +59,8 @@ class One2Influx::OneObject
58
59
  @metric_names.each do |metric|
59
60
  ni_element = @doc.css(metric).first
60
61
  if ni_element.nil?
61
- $LOG.error "Unable to get metric '#{metric}' in #{self.class}."
62
+ $LOG.error "Unable to get metric '#{metric}' in #{self.class}." +
63
+ 'XML parsing error.'
62
64
  else
63
65
  @metrics[metric.to_sym] = ni_element.content
64
66
  end
@@ -67,7 +69,11 @@ class One2Influx::OneObject
67
69
 
68
70
  def init_custom_metrics
69
71
  @custom_metric_names.each do |metric|
70
- @metrics[metric.to_sym] = self.send("get_#{metric.to_s}")
72
+ begin
73
+ @metrics[metric.to_sym] = self.send("get_#{metric.to_s}")
74
+ rescue Exception => e
75
+ $LOG.error "Unable to get metric '#{metric}'. #{e.message}"
76
+ end
71
77
  end
72
78
  end
73
79
  end
@@ -19,6 +19,8 @@ class One2Influx::VirtualMachine < ::One2Influx::OneObject
19
19
  super(xml, client)
20
20
  end
21
21
 
22
+ private
23
+
22
24
  # Computes percentage usage of memory for virtual machine.
23
25
  # Values might go over 1.0 as there is an overhead
24
26
  # @return [float] current usage over max usage
@@ -35,10 +37,9 @@ class One2Influx::VirtualMachine < ::One2Influx::OneObject
35
37
 
36
38
  doc = Nokogiri::XML(template.to_xml)
37
39
  ni_element = doc.xpath('//TEMPLATE/MEMORY').first
38
- puts @metrics
40
+
39
41
  if ni_element.nil? || @metrics[:MEMORY].nil?
40
- $LOG.error "Unable to get metric 'MEMORY_PERC' in #{self.class}."
41
- return
42
+ raise 'Unable to parse VM template.'
42
43
  end
43
44
 
44
45
  # Convert //TEMPLATE/MEMORY from MB to kB as //VM/CPU is in kB
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one2influx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matej Zidek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-15 00:00:00.000000000 Z
11
+ date: 2015-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -85,10 +85,12 @@ description: One2influx is small ruby daemon for getting monitoring data from Op
85
85
  email: zidek.matej@gmail.com
86
86
  executables:
87
87
  - one2influx
88
+ - one2influx.log
88
89
  extensions: []
89
90
  extra_rdoc_files: []
90
91
  files:
91
92
  - bin/one2influx
93
+ - bin/one2influx.log
92
94
  - lib/one2influx.rb
93
95
  - lib/one2influx/config.rb
94
96
  - lib/one2influx/data.rb