Now a days there are so many good and cheap OpenVZ VPS providers out there.
Just have a look at this blog and you will see what I mean. [http://www.lowendbox.com/tag/openvz/]

The way OpenVZ virtual machines offers RAM resource is quite different from XEN.
You get Dedicated Ram (guaranteed ram) and Burstable Ram.

Burstable Ram is good when your server has sporadic load spikes, such as blogs and news sites.
Ideally you should not rely on burstable ram, it depends on the Host System. if the host system starts get low on free ram, you will lose that memory and the kernel will kill your processes to recover the ram.

Best is to keep below 90% of your Dedicated ram.

So, here I have an script that will monitor your memory limits. Also check for errors on your openVZ.
it’s perfect for an hourly cron job. It will print output on warnings and errors only.
Will suppress output if your openVZ container is behaving well. :)

for example, put on /etc/cron.hourly/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
#!/usr/bin/env ruby
#
# Program to check for failed count on OpenVZ systems
#   Failed counts indicate over commit on memory. 
#   it should always be zero.
 
 
@file = `cat /proc/user_beancounters`.split("\n")
 
# Delete the first 3 lines, which are irrelevant to us.
@file.delete_at(0)
@file.delete_at(0)
@file.delete_at(0)
 
@failcnt = []
 
@file.each do |t|
  tmp = t.split
  unless tmp.last == "0"
    @failcnt << tmp
  end
end
 
# Check that 'held' is less than 'barrier' 
#   held = current count
#   barrier = soft limit
# only checking for:
#   privvmpages @file[1] 
#   oomguarpages @file[7] 
# 
# oomguarpages : 
#   The out-of-memory guarantee, in pages. 
#   Any VE process will not be killed even in case of heavy 
#   memory shortage if the current memory consumption 
#   (including both physical memory and swap) 
#   does not reach the oomguarpages barrier.
#
# privvmpages: 
#  The size of private (or potentially private) memory allocated by an application. 
#  The memory that is always shared among different applications 
#  is not included in this resource parameter.
# 
# Sources: 
#  - http://wiki.openvz.org/UBC_secondary_parameters
#  - http://wiki.vpslink.com/Meaning_of_the_/proc/user_beancounters_Values
 
privvmpages = @file[1].split
privvmpages_current = privvmpages[1].to_i
privvmpages_limit = privvmpages[3].to_i
if privvmpages_current > privvmpages_limit
  puts "WARNING: #{privvmpages[0]} has passed the limit: #{privvmpages_current}/#{privvmpages_limit}"
  puts "WARNING: Server may crash or reboot"
end
# Also check it we are getting close to 70% of usage
privvmpages_pc = ((privvmpages_current.to_f/privvmpages_limit)*100).ceil
if privvmpages_pc > 70
  puts "WARNING: #{privvmpages[0]} is high: #{privvmpages_pc}% of limit"
end
 
oomguarpages = @file[7].split
oomguarpages_current = oomguarpages[1].to_i
oomguarpages_limit = oomguarpages[3].to_i
if oomguarpages_current > oomguarpages_limit
  puts "WARNING: #{oomguarpages[0]} has passed the limit: #{oomguarpages_current}/#{oomguarpages_limit}"
  puts "WARNING: Some Processes may be killed"
end
# Also check it we are getting close to 85% of usage
oomguarpages_pc = ((oomguarpages_current.to_f/oomguarpages_limit)*100).ceil
if oomguarpages_pc > 85
  puts "WARNING: #{oomguarpages[0]} is high: #{oomguarpages_pc}% of limit"
end
 
unless @failcnt.empty?
  puts "=================================="
  puts "Found Memory problems with OpenVZ:"
  puts "=================================="
  @failcnt.each do |t|
    puts "#{t.join(' - ')}"
    puts "=================================="
  end
end
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

© 2011 Ruby, Rails, OSX and Linux fun Suffusion theme by Sayontan Sinha

Switch to our mobile site