GithubHelp home page GithubHelp logo

rc_mon's Introduction

RcMon

RcMon is a simple process monitoring helper. It helps to ensure processes stay up and that they are behaving properly. It's simple, straight forward, and best of all lightweight.

Overview

The RcMon cookbook provides a simple LWRP to configure process monitoring. A simple resource would look something like:

rc_mon_service 'memory_consumer' do
  memory_limit '200M'
  cookbook 'my_cookbook'
end

By default, RcMon uses runit, which means we'll need to provide templates for the sv-run and sv-log-run files. We'll keep them simple:

# sv-memory_consumer-log-run.erb
#!/bin/sh
exec svlogd -tt ./main
# sv-memory_consumer-run.erb
#!/bin/sh
exec 2>&1
exec chpst /opt/memory_consumer

And some content for the memory consumer script so it actually does something that needs monitoring:

file '/opt/memory_consumer' do
  content "#!#{node[:languages][:ruby][:ruby_bin]}
$a = ['this string was made for clonin']
while(true) do
  $a += $a * 5
  sleep(5)
end
"
  mode 0755
end

Now you can watch the process consume memory on the node, and once it has reached the 200M threshold be killed and auto restarted.

$ watch -n 0.5 'ps -AH ux | grep [m]emory_consumer'

Under the hood

RcMon uses two tools under the hood. Runit is used to keep the process running and cgroups are used to keep system resources under control. The rc_mon_service LWRP is simply creating a new control grouping, using runit to start the process (and keep it running), and a helper to properly move new processes into the appropriate grouping. It's really just a shortcut for something that can be accomplished directly in a recipe covering only memory restriction and cpu shares.

Notifications

The rc_mon resource will apply any provided actions to the runit resource directly. It does not however provide information about the runit resource in use (the updated_by_last_action? does not reflect the state of the runit resource). This is due to the fact that the actions taken on the runit resource are not handled during the execution of the rc_mon_service, rather they are appended to the end of the run. This does mean that resources can subscribe directly to the runit resource.

Existing Runit Resources

If you already have a runit_service resource defined, you can add rc_mon support into it:

runit_service 'my_service' do
  ...
end

rc_mon 'my_service' do
  memory_limit '100M'
end

Important changes

  • cgroup restrictions are no longer UID based
  • Runit is no longer optional

Infos

rc_mon's People

Contributors

chrisroberts avatar tas50 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.