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 =

Data 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: 'oneadmin:opennebula',
     # 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
    policy: 'ten_hours'
}
@@log =

Logging configuration

{
    # Level to use. Logger::INFO, Logger::WARN, Logger::ERROR are supported
    level: Logger::INFO,
     # Path to log file, when empty, one2influx.log is written into directory
    # where the binary is run from
    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',
            #HOST_STATE: 'STATE', # [int] host state
            #IM_MAD: 'IM_MAD',    # [string] monitoring manager driver
            #VM_MAD: 'VM_MAD',    # [string] virtualization manager driver
            #VN_MAD: 'VN_MAD',    # [string] virtual network manager driver
            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 in host, MAX_MEM - USED_MEM
            'USED_MEM',  # [kB] used memory in host -(buffers+cache)
            'CPU_USAGE', # [%] usage of CPU calculated by ONE as the sum of
                         #     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: [
            #'HOST_MEM_ALOC',  # [%] MEM_USAGE / MAX_MEM
            #'HOST_MEM_LOAD',  # [%] USED_MEM / MAX_MEM
            #'HOST_MEM_WASTE', # [] HOST_MEM_ALOC / HOST_MEM_LOAD
            #'HOST_CPU_ALOC',  # [%] CPU_USAGE / MAX_CPU
            #'HOST_CPU_LOAD',  # [%] USED_CPU / MAX_CPU
            #'HOST_CPU_WASTE', # [] HOST_CPU_ALOC / HOST_CPU_LOAD
        ]
    },
    # 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
            #VM_STATE: 'STATE',     # [int] virtual machine state
            #LCM_STATE: 'LCM_STATE' # [int] substates for ACTIVE state
        },
        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: [
            #'DS_LOAD'   # [%] USED_MB / TOTAL_MB
        ]
    },
    # Cluster
    cluster: {
        tags: {
            CLUSTER_NAME: 'NAME'
        },
        metrics: [
            'CLUSTER_MEM_USAGE', # [kB] sum of MEM_USAGE for whole cluster
            'CLUSTER_MAX_MEM',   # [kB] sum of MAX_MEM for whole cluster
            'CLUSTER_FREE_MEM',  # [kB] sum of FREE_MEM for whole cluster
            'CLUSTER_USED_MEM',  # [kB] sum of USED_MEM for whole cluster
            'CLUSTER_CPU_USAGE', # [%] sum of CPU_USAGE for whole cluster
            'CLUSTER_MAX_CPU',   # [%] sum of MAX_CPU for whole cluster
            'CLUSTER_FREE_CPU',  # [%] sum of FREE_CPU for whole cluster
            'CLUSTER_USED_CPU'   # [%] sum of USED_CPU for whole cluster
        ],
        cust_metrics: [
            #'CLUSTER_MEM_ALOC',  # [%] CLUSTER_MEM_USAGE / CLUSTER_MAX_MEM
            #'CLUSTER_MEM_LOAD',  # [%]CLUSTER_USED_MEM / CLUSTER_MAX_MEM
            #'CLUSTER_MEM_WASTE', # [] CLUSTER_MEM_ALOC / CLUSTER_MEM_LOAD
            #'CLUSTER_CPU_ALOC',  # [%] CLUSTER_CPU_USAGE / CLUSTER_MAX_CPU
            #'CLUSTER_CPU_LOAD',  # [%] CLUSTER_USED_CPU / CLUSTER_MAX_CPU
            #'CLUSTER_CPU_WASTE', # [] CLUSTER_CPU_ALOC / CLUSTER_CPU_LOAD
        ]
    }
}

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


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

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 ##



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

def sec_interval
  @sec_interval
end

Instance Method Details

#influxObject



183
184
185
# File 'lib/one2influx/config.rb', line 183

def influx
  @@influx
end

#is_one_available?Boolean

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

Returns:

  • (Boolean)


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/one2influx/config.rb', line 208

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



179
180
181
# File 'lib/one2influx/config.rb', line 179

def one
  @@one
end

#storageObject



187
188
189
# File 'lib/one2influx/config.rb', line 187

def storage
  @@storage
end