{"id":13804082,"url":"https://github.com/tj/mon","last_synced_at":"2025-05-16T13:06:58.630Z","repository":{"id":2982903,"uuid":"3998822","full_name":"tj/mon","owner":"tj","description":"mon(1) - Simple single-process process monitoring program written in C","archived":false,"fork":false,"pushed_at":"2016-09-07T15:22:47.000Z","size":105,"stargazers_count":1076,"open_issues_count":15,"forks_count":94,"subscribers_count":50,"default_branch":"master","last_synced_at":"2024-10-29T21:03:16.666Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tj.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-04-11T22:01:06.000Z","updated_at":"2024-10-27T02:14:01.000Z","dependencies_parsed_at":"2022-08-30T23:01:30.610Z","dependency_job_id":null,"html_url":"https://github.com/tj/mon","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fmon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fmon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fmon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fmon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tj","download_url":"https://codeload.github.com/tj/mon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248545502,"owners_count":21122153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:00:41.423Z","updated_at":"2025-04-12T09:27:27.398Z","avatar_url":"https://github.com/tj.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# mon(1)\n\n  Super-simple monitoring program.\n\n  `mon` spawned from the needlessly complex\n  frustration that tools like [monit](http://mmonit.com/monit/)\n  provide, with their awkward DSLs and setup. `mon` is written\n  in C, uses less than 400kb of memory, and is incredibly simple\n  to set up.\n\n## Installation\n\n```\n$ make install\n```\n\n Too lazy to clone?:\n\n```\n$ (mkdir /tmp/mon \u0026\u0026 cd /tmp/mon \u0026\u0026 curl -L# https://github.com/tj/mon/archive/master.tar.gz | tar zx --strip 1 \u0026\u0026 make install \u0026\u0026 rm -rf /tmp/mon)\n```\n\n## Usage\n\n```\n\nUsage: mon [options] \u003ccommand\u003e\n\nOptions:\n\n  -V, --version                 output program version\n  -h, --help                    output help information\n  -l, --log \u003cpath\u003e              specify logfile [mon.log]\n  -s, --sleep \u003csec\u003e             sleep seconds before re-executing [1]\n  -S, --status                  check status of --pidfile\n  -p, --pidfile \u003cpath\u003e          write pid to \u003cpath\u003e\n  -m, --mon-pidfile \u003cpath\u003e      write mon(1) pid to \u003cpath\u003e\n  -P, --prefix \u003cstr\u003e            add a log prefix\n  -d, --daemonize               daemonize the program\n  -a, --attempts \u003cn\u003e            retry attempts within 60 seconds [10]\n  -R, --on-restart \u003ccmd\u003e        execute \u003ccmd\u003e on restarts\n  -E, --on-error \u003ccmd\u003e          execute \u003ccmd\u003e on error\n\n```\n\n## Example\n\n  The most simple use of `mon(1)` is to simply keep a command running:\n\n```js\n$ mon ./myprogram\nmon : pid 50395\nmon : child 50396\nmon : sh -c \"./example/program.sh\"\none\ntwo\nthree\n```\n\n  You may daemonize mon and disassociate from the term with `-d`:\n\n```js\n$ mon ./myprogram -d\nmon : pid 50413\n```\n\n## Failure alerts\n\n `mon(1)` will continue to attempt restarting your program unless the maximum number\n of `--attempts` has been exceeded within 60 seconds. Each time a restart is performed\n the `--on-restart` command is executed, and when `mon(1)` finally bails the `--on-error`\n command is then executed before mon itself exits and gives up.\n\n  For example the following will echo \"hey\" three times before mon realizes that\n  the program is unstable, since it's exiting immediately, thus finally invoking\n  `./email.sh`, or any other script you like.\n\n```js\nmon \"echo hey\" --attempts 3 --on-error ./email.sh\nmon : child 48386\nmon : sh -c \"echo hey\"\nhey\nmon : last restart less than one second ago\nmon : 3 attempts remaining\nmon : child 48387\nmon : sh -c \"echo hey\"\nhey\nmon : last restart less than one second ago\nmon : 2 attempts remaining\nmon : child 48388\nmon : sh -c \"echo hey\"\nhey\nmon : last restart less than one second ago\nmon : 1 attempts remaining\nmon : 3 restarts within less than one second, bailing\nmon : on error `sh test.sh`\nemailed failure notice to tobi@ferret-land.com\nmon : bye :)\n```\n\n  __NOTE__: The process id is passed as an argument to both `--on-error` and `--on-restart` scripts.\n\n## Managing several mon(1) processes\n\n  `mon(1)` is designed to monitor a single program only, this means a few things,\n  firstly that a single `mon(1)` may crash and it will not influence other programs,\n  secondly that the \"configuration\" for `mon(1)` is simply a shell script,\n  no need for funky weird inflexible DSLs.\n\n```bash\n#!/usr/bin/env bash\n\npids=\"/var/run\"\napp=\"/www/example.com\"\n\nmon -d redis-server -p $pids/redis.pid\nmon -d \"node $app/app\" -p $pids/app-0.pid\nmon -d \"node $app/jobs\" -p $pids/jobs-0.pid\nmon -d \"node $app/jobs\" -p $pids/jobs-1.pid\nmon -d \"node $app/jobs\" -p $pids/jobs-2.pid\nmon -d \"node $app/image\" -p $pids/image-0.pid\nmon -d \"node $app/image\" -p $pids/image-1.pid\nmon -d \"node $app/image-broker\" -p $pids/image-broker.pid\n```\n\n  I highly recommend checking out jgallen23's [mongroup(1)](https://github.com/jgallen23/mongroup),\n  which provides a great interface for managing any number of `mon(1)` instances.\n\n## Logs\n\n  By default `mon(1)` logs to stdio, however when daemonized it will default\n  to writing a log file named `./mon.log`. If you have several instances you may\n  wish to `--prefix` the log lines, or specify separate files.\n\n## Signals\n\n  - __SIGQUIT__ graceful shutdown\n  - __SIGTERM__ graceful shutdown\n\n## Links\n\n  Tools built with `mon(1)`:\n\n  - [mongroup(1)](https://github.com/jgallen23/mongroup) - monitor a group of processes (shell script)\n  - [node-mongroup](https://github.com/visionmedia/node-mongroup) - node implementation of mongroup(1)\n\n# License\n\n  MIT\n\n# Build Status\n\n  [![Build Status](https://travis-ci.org/visionmedia/mon.png)](http://travis-ci.org/visionmedia/mon)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fmon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftj%2Fmon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fmon/lists"}