Giter Site home page Giter Site logo

mon's Introduction

mon(1)

Super-simple monitoring program.

mon spawned from the needlessly complex frustration that tools like monit provide, with their awkward DSLs and setup. mon is written in C, uses less than 400kb of memory, and is incredibly simple to set up.

Installation

$ make install

Too lazy to clone?:

$ (mkdir /tmp/mon && cd /tmp/mon && curl -L# https://github.com/tj/mon/archive/master.tar.gz | tar zx --strip 1 && make install && rm -rf /tmp/mon)

Usage


Usage: mon [options] <command>

Options:

  -V, --version                 output program version
  -h, --help                    output help information
  -l, --log <path>              specify logfile [mon.log]
  -s, --sleep <sec>             sleep seconds before re-executing [1]
  -S, --status                  check status of --pidfile
  -p, --pidfile <path>          write pid to <path>
  -m, --mon-pidfile <path>      write mon(1) pid to <path>
  -P, --prefix <str>            add a log prefix
  -d, --daemonize               daemonize the program
  -a, --attempts <n>            retry attempts within 60 seconds [10]
  -R, --on-restart <cmd>        execute <cmd> on restarts
  -E, --on-error <cmd>          execute <cmd> on error

Example

The most simple use of mon(1) is to simply keep a command running:

$ mon ./myprogram
mon : pid 50395
mon : child 50396
mon : sh -c "./example/program.sh"
one
two
three

You may daemonize mon and disassociate from the term with -d:

$ mon ./myprogram -d
mon : pid 50413

Failure alerts

mon(1) will continue to attempt restarting your program unless the maximum number of --attempts has been exceeded within 60 seconds. Each time a restart is performed the --on-restart command is executed, and when mon(1) finally bails the --on-error command is then executed before mon itself exits and gives up.

For example the following will echo "hey" three times before mon realizes that the program is unstable, since it's exiting immediately, thus finally invoking ./email.sh, or any other script you like.

mon "echo hey" --attempts 3 --on-error ./email.sh
mon : child 48386
mon : sh -c "echo hey"
hey
mon : last restart less than one second ago
mon : 3 attempts remaining
mon : child 48387
mon : sh -c "echo hey"
hey
mon : last restart less than one second ago
mon : 2 attempts remaining
mon : child 48388
mon : sh -c "echo hey"
hey
mon : last restart less than one second ago
mon : 1 attempts remaining
mon : 3 restarts within less than one second, bailing
mon : on error `sh test.sh`
emailed failure notice to tobi@ferret-land.com
mon : bye :)

NOTE: The process id is passed as an argument to both --on-error and --on-restart scripts.

Managing several mon(1) processes

mon(1) is designed to monitor a single program only, this means a few things, firstly that a single mon(1) may crash and it will not influence other programs, secondly that the "configuration" for mon(1) is simply a shell script, no need for funky weird inflexible DSLs.

#!/usr/bin/env bash

pids="/var/run"
app="/www/example.com"

mon -d redis-server -p $pids/redis.pid
mon -d "node $app/app" -p $pids/app-0.pid
mon -d "node $app/jobs" -p $pids/jobs-0.pid
mon -d "node $app/jobs" -p $pids/jobs-1.pid
mon -d "node $app/jobs" -p $pids/jobs-2.pid
mon -d "node $app/image" -p $pids/image-0.pid
mon -d "node $app/image" -p $pids/image-1.pid
mon -d "node $app/image-broker" -p $pids/image-broker.pid

I highly recommend checking out jgallen23's mongroup(1), which provides a great interface for managing any number of mon(1) instances.

Logs

By default mon(1) logs to stdio, however when daemonized it will default to writing a log file named ./mon.log. If you have several instances you may wish to --prefix the log lines, or specify separate files.

Signals

  • SIGQUIT graceful shutdown
  • SIGTERM graceful shutdown

Links

Tools built with mon(1):

License

MIT

Build Status

Build Status

mon's People

Contributors

arturdryomov avatar deweerdt avatar flexd avatar joshmoore avatar kilianc avatar maxrabin avatar rschmukler avatar sjonnet avatar soveran avatar tcort avatar tj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mon's Issues

alerts

via arbitrary command

Ordering of -S and --pidfile

The order in which -S|--status and --pidfile are specified will determine success of command:

# ./mon --pidfile /var/run/checkd.pid -S
13858 : alive : uptime 15 seconds

# ./mon -S --pidfile /var/run/checkd.pid
Error: --pidfile required

It should not matter whether -S|--status comes before or after the --pidfile argument. I don't think it should matter at least. There is nothing seemingly to be gained from having specific ordering.

Error running node app (address in use)

When I try to kill the process kill -s SIGKILL $(cat ~/run/ks-app.pid), I get an address in use (I've tried changing the sleep time, didn't have any affect)

[jga] ~/code/app [master]: mon "node app.js" -p ~/run/ks-app.pid
mon : pid 17115
mon : write pid to /home/jga/run/ks-app.pid
mon : sh -c "node app.js"
The "sys" module is now called "util". It should have a similar interface.
info:   Server started on port 3001
mon : signal(Killed)
mon : sleep(1)
mon : pid 17140
mon : write pid to /home/jga/run/ks-app.pid
mon : sh -c "node app.js"
The "sys" module is now called "util". It should have a similar interface.
info:   Server started on port 3001

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:670:11)
    at Array.0 (net.js:771:26)
    at EventEmitter._tickCallback (node.js:192:40)
mon : exit(1)
mon : sleep(1)
mon : pid 17147
mon : write pid to /home/jga/run/ks-app.pid
mon : sh -c "node app.js"

open(): bad address

I am having difficulty debugging this but when I run the same commands before the lastest checkin(s) everything was working.

Now I receive the following error:

"open(): bad address"

add fflush(stdout) to log method

When daemonized, the logging from mon may appear very distant from where/when it actually happens...

./mon -d -l sleep.log "echo hi; sleep 2"

will make that obvious. I have a pull request to flush stdout, making the mon log statements appear immediately

Cannot pass arguments to programs

Hi, I think I cannot pass arguments to programs.

For instance, I wrote server.js (which only starts a plain http server), and node server.js works as expected. If I add #! /usr/bin/env node to the file and chmod +x server.js, then ./server.js also works.

mon ./server.js also works as expected, but the problem is that I can't seem to get mon "node server.js" to work. I get this:

$ mon node test.js
mon : child 18797
mon : sh -c "node"
> 

Which is the nodejs prompt (node command with no argument).

Mon creates 3 processes when launched with sudo

mon "node app.js"

Creates 2 processes: mon and node.

sudo mon "node app.js"

Creates 3 processes: mon, node, and sh

I bet this is a user error on my part, but not sure the correct format to use mon + sudo and launch only 2 processes.

on_exit in release version

In 1.2.0 (installed from homebrew) if no on_error specified you'll get:

mon : last restart less than one second ago
mon : 1 attempts remaining
mon : 10 restarts within 1 second, bailing
mon : on error `(null) 50003`
sh: -c: line 0: syntax error near unexpected token `50003'
sh: -c: line 0: `(null) 50003'
mon : exit(512)
mon : bye :)

In HEAD you'll get:

mon : last restart less than one second ago
mon : 1 attempts remaining
mon : 10 restarts within 1 second, bailing
mon : bye :)

which is much more adequate. I suggest to make a release with that fix :)

Script arguments

Lets say that my email.sh receives a string as it first argument. For example the following:

$ ./email.sh "test me"

Supposing email.sh:

#! /usr/bin/bash
message=$1 
...

Is there a way to pass that string argument to the script using mon. Because like this the message variable will have the PID from the process calling the script.

defaults

add some nice defaults so it's slightly less annoying to just chuck up a few nodes

[Feature] --monpid

I'm writing a wrapper to start/stop/restart/status a group of apps. To do the stop command I need to get the pid of the mon daemon. something like mon -D --monpid pids/redis.mon.pid redis-server. thoughts?

Starting mon processes on machine startup.

Recently I've had a few problems with the VM host machine hosting my VM, which unfortunately has led to a series of restarts in the middle of the night, and my things using mon/mongroup not starting.

I was wondering if anyone of you had any tips for automatically starting things?

What do you use? What works with mon?

Would it be interesting in writing something that will start mon processes on a more global scale (like god does), or perhaps a revised version of mongroup that will do that?

Binary realeases

Given that CI is already setup with travis, could you also set it up so that it deploys the built binaries to the release?

This would make using mon in docker containers a lot easier. One would not have to build mon in the Dockerfile, but just ADD it to the container.

Cannot install mon on FreeBSD 9.1

I tried to install mon on FreeBSD 9.1 and I get this. What's wrong?

    root@eugene:/tmp/mon/mon-master # make install
    cc -D_GNU_SOURCE -std=c99 -I deps/ -c src/mon.c
    In file included from src/mon.c:21:
    deps/ms.h:34:7: warning: no newline at end of file
    cc -D_GNU_SOURCE -std=c99 -I deps/ -c deps/ms.c
    In file included from deps/ms.c:11:
    deps/ms.h:34:7: warning: no newline at end of file
    cc -D_GNU_SOURCE -std=c99 -I deps/ -c deps/commander.c
    cc  -o mon
    cc: No input files specified
    *** [mon] Error code 1

    Stop in /tmp/mon/mon-master.

Wrong pid

I call mon from a bash script and when I ask mon to store the --pidfile for the program I am starting it seems to grab/store the pid of the bash script and not the program it started.

Is that possible?

When I more the pid file I get:

more .devcomp.pid 
".devcomp.pid" may be a binary file.  See it anyway? 
24701^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

The pid that gets stored seems to be always one higher than the one of the program.

What is odd to me is that the bash script gets started before mon yet mon has a lower pid.

packages

Any chance of getting packages for debian and brew?

Mon should wait for the child process to exit before exiting

Some times I do need to restart Mon itself. In this case, I send Mon a SIGTERM. The problem is that it exits immediately without waiting for the child to exit (and possibly clearing its pidfile).

If you agree this behavior is what pretty much everyone would expect, then I'll submit a patch.

Windows equivalent

I was wondering what it would take or if there is a windows equivalent for what mon does.

I am trying to get my toolchain running cross-platform and am looking for mon for windows.

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.