Class: Invoracle::Infra::IostatParser
- Inherits:
-
Object
- Object
- Invoracle::Infra::IostatParser
- Defined in:
- lib/invoracle/infra/iostat_parser.rb
Instance Method Summary collapse
- #getDeviceNames ⇒ Object
- #getIostatValue(sType = nil, sField = nil, sAggregateFirst = nil, sAggregateSecond = nil) ⇒ Object
- #getItemsValue(aItems = [], sField = nil, sAggregateFirst = nil, sAggregateSecond = nil) ⇒ Object
-
#initialize ⇒ IostatParser
constructor
A new instance of IostatParser.
- #loadIostatxRaw(sIostatx = nil) ⇒ Object
Constructor Details
#initialize ⇒ IostatParser
Returns a new instance of IostatParser.
3 4 5 6 |
# File 'lib/invoracle/infra/iostat_parser.rb', line 3 def initialize() sIostatx = '' dIostatx = {} end |
Instance Method Details
#getDeviceNames ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/invoracle/infra/iostat_parser.rb', line 7 def getDeviceNames() dDeviceNames = {} if @dIostatx.has_key?('devices') @dIostatx['devices'].each do |dDevice| if dDevice.has_key?('Id') sDevice = dDevice['Id'] dDeviceNames[sDevice] = 1 end end end aDeviceNames = dDeviceNames.keys.sort return aDeviceNames end |
#getIostatValue(sType = nil, sField = nil, sAggregateFirst = nil, sAggregateSecond = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/invoracle/infra/iostat_parser.rb', line 20 def getIostatValue(sType=nil,sField=nil,sAggregateFirst=nil,sAggregateSecond=nil) if sType == 'device' aDevices = @dIostatx['devices'] return self.getItemsValue(aDevices,sField,sAggregateFirst,sAggregateSecond) elsif sType == 'cpu' aCpus = @dIostatx['cpus'] return self.getItemsValue(aCpus,sField,sAggregateFirst,sAggregateSecond) end return -1.0 end |
#getItemsValue(aItems = [], sField = nil, sAggregateFirst = nil, sAggregateSecond = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/invoracle/infra/iostat_parser.rb', line 30 def getItemsValue(aItems=[],sField=nil,sAggregateFirst=nil,sAggregateSecond=nil) dItemsData = {} aItems.each do |dItem| sItemName = dItem['Id'] dItem.each do |sKey,fVal| dItemsData[sItemName] ||= {} dItemsData[sItemName][sKey] ||= {} dKeyInfo = dItemsData[sItemName][sKey] if ! dKeyInfo.has_key?('min') || fVal < dKeyInfo['min'] dKeyInfo['min'] = fVal end if ! dKeyInfo.has_key?('max') || fVal > dKeyInfo['max'] dKeyInfo['max'] = fVal end if ! dKeyInfo.has_key?('sum') dKeyInfo['sum'] = fVal else dKeyInfo['sum'] += fVal end if ! dKeyInfo.has_key?('num') dKeyInfo['num'] = 1 else dKeyInfo['num'] += 1 end dItemsData[sItemName][sKey] = dKeyInfo end end bValReturn = false fValReturn = 0.0 if sAggregateFirst == 'max' && sAggregateSecond == 'max' dItemsData.each do |sItemName,dItemInfo| if dItemInfo.has_key?(sField) if dItemInfo[sField].has_key?('max') if dItemInfo[sField]['max'] > fValReturn fValReturn = dItemInfo[sField]['max'] end end end end elsif sAggregateFirst == 'min' && sAggregateSecond == 'min' dItemsData.each do |sItemName,dItemInfo| if dItemInfo[sField].has_key?('min') if ! bValReturn fValReturn = dItemInfo[sField]['min'] bValReturn = true elsif dItemInfo[sField]['min'] < fValReturn fValReturn = dItemInfo[sField]['min'] end end end end return fValReturn end |
#loadIostatxRaw(sIostatx = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/invoracle/infra/iostat_parser.rb', line 83 def loadIostatxRaw(sIostatx=nil) aCpus = [] aDevices = [] aIostatx = sIostatx.split("\n") sStage = '' aCols = [] iLine = 0 iCpuCount = 0 sDevName = '' aIostatx.each do |sLine| sLine.strip! next unless sLine.length>0 iLine += 1 aItems = sLine.split(" ") if sLine =~ /^avg-cpu:/ aItems.shift aCols = aItems sStage = 'cpu' iCpuCount += 1 next elsif sLine =~ /^Device:/ aItems.shift aCols = aItems sStage = 'device' next elsif sStage == '' next elsif sStage == 'cpu' if aItems.length == aCols.length dCpu = {'Id' => 'cpu' + iCpuCount.to_s} aCols.each_with_index do |sCol,iIdx| dCpu[sCol] = aItems[iIdx].to_f end aCpus.push(dCpu) else raise ArgumentError, "E_BAD_MATCH_CPU" end elsif sStage == 'device' if aItems.length == aCols.length + 1 sDevice = aItems.shift dDevice = {'Id' => sDevice} aCols.each_with_index do |sCol,iIdx| dDevice[sCol] = aItems[iIdx].to_f end aDevices.push(dDevice) sDevName = '' elsif aItems.length == 1 sDevName = aItems[0] next elsif aItems.length == aCols.length && sDevName.length > 0 dDevice = {'Id' => sDevName} aCols.each_with_index do |sCol,iIdx| dDevice[sCol] = aItems[iIdx].to_f end aDevices.push(dDevice) sDevName = '' else raise ArgumentError, "E_BAD_MATCH_DEVICE" end end end dIostatx = { 'cpus' => aCpus, 'devices' => aDevices } @dIostatx = dIostatx return dIostatx end |