Class: One2Influx::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/one2influx/config.rb

Overview

Class for holding all configuration data, it is accessed by its only instance

in global variable $CFG

Constant Summary collapse

@@fetch_interval =

Allowed values are number of seconds, minutes, hours

separated by space
'30 seconds'
@@one =

OpenNebula connection configuration

{
    # Login credentials separated by semicolon
    credentials: 'user:password',
     # XML_RPC endpoint where OpenNebula is listening
    endpoint: 'http://localhost:2633/RPC2'
}
@@influx =

InfluxDB connection configuration

{
    # Whether to use basic authentication
    authenticate: false,
     # Login credentials separated by semicolon
    credentials: 'user:password',
     # InfluxDB HTTP API endpoint
    endpoint: 'http://localhost:8086',
     # Database name
    database: 'test',
     # Retention policy for records with the smallest granularity
    # you have to create retention policy manually if you want to change
    # this one
    policy: 'ten_hours'
}
@@log =

Logging configuration

{
    # Level to use. Logger::INFO, Logger::WARN, Logger::ERROR are supported
    level: Logger::INFO,
     # Path to log file
    path: ''
}
@@storage =

Configuration of metrics and tags to be stored to InfluxDB Comment or uncomment metrics, tags or whole object depending on what you want to store.

{
    # Host
    host: {
        tags: {
            HOST_NAME: 'NAME',
            CLUSTER_ID: 'CLUSTER_ID',
            CLUSTER_NAME: 'CLUSTER',
            DSS_IDS: ''  # [string] IDs of datastores that this host uses
                         #  encoded in form ,,ID_1,,ID_2...,,
        },
        metrics: [
            'MEM_USAGE', # [kB] memory requested by VMs
            'MAX_MEM',   # [kB] total memory available in host
            'FREE_MEM',  # [kB] free memory returned by probes
            'USED_MEM',  # [kB] memory used by all host processes over MAX_MEM
            'CPU_USAGE', # [%] usage of CPU calculated by ONE as the summatory
                         #     CPU requested by all VMs running in the host
            'MAX_CPU',   # [%] total CPU in the host (number of cores * 100)
            'FREE_CPU',  # [%] free CPU as returned by the probes
            'USED_CPU'   # [%] CPU used by all host processes over a total
                         #     of # cores * 100
        ],
        cust_metrics: []
    },
    # Virtual machine
    vm:   {
        tags: {
            CLUSTER_ID: 'CLUSTER_ID',
            CLUSTER_NAME: 'CLUSTER_NAME',
            HOST_ID: 'HOST_ID',
            HOST_NAME: 'HOST_NAME',
            VM_NAME: 'NAME',
            UID: 'UID',       # [int] user's ID
            GID: 'GID',       # [int] group's ID
            UNAME: 'UNAME',   # [string] user's name
            GNAME: 'GNAME'    # [string] group's name
        },
        metrics: [
            'MEMORY', # [kB] memory consumption
            'CPU',    # [%] 1 VCPU consumed (two fully consumed cpu is 200)
            #'NET_TX', # [B] sent to the networ
            #'NET_RX'  # [B] received from the network
        ],
        cust_metrics: [
            #'MEMORY_PERC' # Computes percentage usage of memory for VM
        ]
     },
    # Datastore
    ds:   {
        tags: {
            DS_NAME: 'NAME',
            CLUSTER_ID: 'CLUSTER_ID',
            CLUSTER_NAME: 'CLUSTER',
            TM_MAD: 'TM_MAD',  # [shared|ssh|qcow2|vmfs|ceph|lvm|fs_lvm|dev]
                               #  transfer manager
            DS_MAD: 'DS_MAD',  # [fs|vmfs|lvm|ceph|dev] datastore type
            UID: 'UID',        # [int] user's ID
            GID: 'GID',        # [int] group's ID
            UNAME: 'UNAME',    # [string] user's name
            GNAME: 'GNAME',    # [string] group's name
            HOSTS_IDS: ''      # [string] IDs of hosts that are using this
                               #  datastore encoded in form ,,ID_1,,ID_2...,,
        },
        metrics: [
            'TOTAL_MB', # [MB] total space available in datastore
            'FREE_MB',  # [MB] free space
            'USED_MB'   # [MB] used space
        ],
        cust_metrics: []
    },
    # Cluster
    cluster: {
        tags: {
            CLUSTER_NAME: 'NAME'
        },
        metrics: [
            'CLUSTER_MEM_USAGE', # [kB] memory requested by all VMs in cluster
            'CLUSTER_MAX_MEM',   # [kB] total memory available in all hosts
            'CLUSTER_FREE_MEM',  # [kB] free memory of all hosts returned
                                 #  by probes
            'CLUSTER_USED_MEM',  # [kB] memory used by all processes of all
                                 #  hosts over MAX_MEM
            'CLUSTER_CPU_USAGE', # [%] usage of CPU calculated by ONE as the
                                 #  sum of CPU requested by all VMs running
                                 #  in the cluster
            'CLUSTER_MAX_CPU',   # [%] total CPU in the cluster
                                 #  (number of cores * 100)
            'CLUSTER_FREE_CPU',  # [%] free CPU as returned by the probes
            'CLUSTER_USED_CPU'   # [%] CPU used by all processes of all hosts
                                 #  over a total of # cores * 100
        ],
        cust_metrics: []
    }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Initializes logging, converts fetch interval from human readable form,

adds tag ID to all metrics and converts VM's tags from human readable form

178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/one2influx/config.rb', line 178

def initialize
  log_path = @@log[:path] + 'one2influx.log'
  begin
    $LOG = Logger.new(log_path, 'daily', 30)
  rescue Exception => e
    raise "Unable to create log file. #{e.message}"
  end
  $LOG.level = @@log[:level]

  convert_to_sec
  prepare_storage_ids
  prepare_vm_config
end

Instance Attribute Details

#sec_intervalObject (readonly)

DO NOT EDIT BELOW THIS LINE ##


158
159
160
# File 'lib/one2influx/config.rb', line 158

def sec_interval
  @sec_interval
end

Instance Method Details

#influxObject


168
169
170
# File 'lib/one2influx/config.rb', line 168

def influx
  @@influx
end

#is_one_available?Boolean

Checks it is possible to connect to ONE with provided credentials.

Returns:

  • (Boolean)

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/one2influx/config.rb', line 193

def is_one_available?
  begin
    client = OpenNebula::Client.new(@@one[:credentials], @@one[:endpoint])
  rescue Exception => e
    $LOG.error "Unable to connect to ONE with message: #{e.message}"
    return false
  end

  version = client.get_version
  # Try to get ONE version just to check if it's possible to connect to ONE
  if version.is_a? OpenNebula::Error
    $LOG.error 'Unable to find out ONE version with message: '+version.message
    return false
  end
  $LOG.info 'Connection with ONE verified.'

  return true
end

#oneObject

Group of getter methods for configuration class variables


164
165
166
# File 'lib/one2influx/config.rb', line 164

def one
  @@one
end

#storageObject


172
173
174
# File 'lib/one2influx/config.rb', line 172

def storage
  @@storage
end