Class: Istat::Frames::MeasurementResponse

Inherits:
Response show all
Defined in:
lib/istat/frames/measurement.rb

Constant Summary

Constants inherited from Base

Base::DOCTYPE

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_s

Constructor Details

This class inherits a constructor from Istat::Frames::Base

Instance Method Details

#cpuArray<Hash>

collect cpu data (can contain history)

Examples:

Result

[
  { :id => 28388970, :user => 0, :system => 0, :nice => 0 },
  { :id => 28388971, :user => 0, :system => 0, :nice => 0 },
  { :id => 28388972, :user => 0, :system => 0, :nice => 0 },
  { :id => 28388973, :user => 0, :system => 0, :nice => 0 }
]

Returns:

  • (Array<Hash>)

    the cpu load and usage data



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/istat/frames/measurement.rb', line 89

def cpu
  if cpu?
    map(:CPU) do |element, attributes|
      { 
        :id     => attributes["id"].to_i,
        :user   => attributes["u"].to_i,
        :system => attributes["s"].to_i,
        :nice   => attributes["n"].to_i
      }
    end
  end
end

#cpu?Boolean

returns true if there is a cpu section in the frame

Returns:

  • (Boolean)


76
77
78
# File 'lib/istat/frames/measurement.rb', line 76

def cpu?
  has_node? :CPU
end

#disksArray<Hash>

collect all disk informations

Examples:

Result

[
  :label => "/", 
  :uuid => "/dev/vzfs",
  :free => 9226,
  :percent_used => 39.931
]

Returns:

  • (Array<Hash>)

    all disks of the system



262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/istat/frames/measurement.rb', line 262

def disks
  if disks?
    map(:DISKS) do |element, attributes|
      {
        :label          => attributes["n"],
        :uuid           => attributes["uuid"],
        :free           => attributes["f"].to_i,
        :percent_used   => attributes["p"].to_f
      }
    end
  end
end

#disks?Boolean

returns true if there is a disks section in the frame

Returns:

  • (Boolean)


248
249
250
# File 'lib/istat/frames/measurement.rb', line 248

def disks?
  has_node? :DISKS
end

#fansArray

collect all fan informations in order

Examples:

Result

[1999]

Returns:

  • (Array)

    containing all the fans



221
222
223
224
225
226
227
228
229
# File 'lib/istat/frames/measurement.rb', line 221

def fans
  if fans?
    fans = []
    map(:FANS) do |element, attributes|
      fans[attributes["i"].to_i] = attributes["s"].to_i
    end
    fans
  end
end

#fans?Boolean

returns true if there is a fan section in the frame

Returns:

  • (Boolean)


212
213
214
# File 'lib/istat/frames/measurement.rb', line 212

def fans?
  has_node? :FANS
end

#loadArray

parse the load informations

Examples:

Result

[0.54, 0.60, 0.67]

Returns:

  • (Array)

    the load of the system



184
185
186
187
188
189
# File 'lib/istat/frames/measurement.rb', line 184

def load
  if load?
    attributes = node(:LOAD).attributes
    [attributes["one"].to_f, attributes["fv"].to_f, attributes["ff"].to_f]
  end
end

#load?Boolean

returns true if there is a load section in the frame

Returns:

  • (Boolean)


175
176
177
# File 'lib/istat/frames/measurement.rb', line 175

def load?
  has_node? :LOAD
end

#memoryHash

parse the memory informations

Examples:

Result

{
  :wired => 25938,
  :active => 27620,
  :inactive => 11664,
  :free => 7983,
  :total => 73207,
  :swap_used => 3,
  :swap_total => 36861,
  :page_ins => 0,
  :page_outs => 0
}

Returns:

  • (Hash)

    the memory information



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/istat/frames/measurement.rb', line 157

def memory
  if memory?
    attributes = node(:MEM).attributes
    {
      :wired => attributes["w"].to_i,
      :active => attributes["a"].to_i,
      :inactive => attributes["i"].to_i,
      :free => attributes["f"].to_i,
      :total => attributes["t"].to_i,
      :swap_used => attributes["su"].to_i,
      :swap_total => attributes["st"].to_i,
      :page_ins => attributes["pi"].to_i,
      :page_outs => attributes["po"].to_i
    }
  end
end

#memory?Boolean

returns true if there is a memory section in the frame

Returns:

  • (Boolean)


138
139
140
# File 'lib/istat/frames/measurement.rb', line 138

def memory?
  has_node? :MEM
end

#networkHash<Array<Hash>>

TODO:

supports only one interface at the moment

collects all network information over the interfaces (can contain history). Send and received values are byte numbers.

Examples:

Result

{
  1 => [
    { :id => 28388970, :received => 4177773, :send => 232278672, :time => <#Time ...> },
    { :id => 28388971, :received => 4177773, :send => 232278672, :time => <#Time ...> },
    { :id => 28388972, :received => 4177773, :send => 232278672, :time => <#Time ...> },
    { :id => 28388973, :received => 4177773, :send => 232278672, :time => <#Time ...> }
  ]
}

Returns:

  • (Hash<Array<Hash>>)

    the network data for the interfaces



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/istat/frames/measurement.rb', line 121

def network
  if network?
    interface_name = node(:NET).attributes["if"].to_i
    interfaces = { interface_name => [] }
    map(:NET) do |element, attributes|
      interfaces[interface_name] << {
        :id => attributes["id"].to_i,
        :received => attributes["d"].to_i,
        :send => attributes["u"].to_i,
        :time  => Time.at(attributes["t"].to_f)
      }
    end
    interfaces
  end
end

#network?Boolean

returns true if there is a network section in the frame

Returns:

  • (Boolean)


103
104
105
# File 'lib/istat/frames/measurement.rb', line 103

def network?
  has_node? :NET
end

#ridInteger

parse the isr header request id

Returns:

  • (Integer)

    the request id



53
54
55
# File 'lib/istat/frames/measurement.rb', line 53

def rid
  @root.attributes["rid"].to_i
end

#sid_diskInteger

parse the isr header disk id

Returns:

  • (Integer)

    the disk sid



59
60
61
# File 'lib/istat/frames/measurement.rb', line 59

def sid_disk
  @root.attributes["ds"].to_i
end

#sid_fansInteger

parse the isr header fans sid

Returns:

  • (Integer)

    the fans sid



71
72
73
# File 'lib/istat/frames/measurement.rb', line 71

def sid_fans
  @root.attributes["fs"].to_i
end

#sid_tempInteger

parse the isr header temp sid

Returns:

  • (Integer)

    the temp sid



65
66
67
# File 'lib/istat/frames/measurement.rb', line 65

def sid_temp
  @root.attributes["ts"].to_i
end

#tempsArray

collect all temperature informations in order

Examples:

[30, 52, 29, 50, 30, 64, 61]

Returns:

  • (Array)

    the temps that are returned using the sensor modules



201
202
203
204
205
206
207
208
209
# File 'lib/istat/frames/measurement.rb', line 201

def temps
  if temps?
    temps = []
    map(:TEMPS) do |element, attributes|
      temps[attributes["i"].to_i] = attributes["t"].to_i
    end
    temps
  end
end

#temps?Boolean

returns true if there is a temps section in the frame

Returns:

  • (Boolean)


192
193
194
# File 'lib/istat/frames/measurement.rb', line 192

def temps?
  has_node? :TEMPS
end

#uptimeTime

calculate the system uptime

Examples:

Result

"Sat Apr 30 09:46:45 +0200 2011"

Returns:

  • (Time)

    the uptime orf the system



241
242
243
244
245
# File 'lib/istat/frames/measurement.rb', line 241

def uptime
  if uptime?
    Time.now - node(:UPT).attributes["u"].to_i
  end
end

#uptime?Boolean

returns true if there is a uptime section in the frame

Returns:

  • (Boolean)


232
233
234
# File 'lib/istat/frames/measurement.rb', line 232

def uptime?
  has_node? :UPT
end