chronos

0.1.0 • Public • Published

chronos

Install

After you got nodejs (which includes npm now), you can just:

`npm install -g chronos`

After this you may need to link node and chronos in your /bin or /usr/bin directory. Otherwise your cronjob may not be able to find them. To check, just create a cron like which node and look into your mailbox.

Configuration

chronos should be compatible with every service that supports AMQP. You can configure chronos by placing a JSON file in /etc/chronos.json or /usr/local/etc/chronos.json. Example:

{
	"mode" : "amqp",
	"amqp" : {
		"host" : "10.0.13.1",
		"port" : 5672,
		"login" : "guest",
		"password" : "guest",
		"vhost" : "/",
		"key" : "somekey"
	},
	"stage" : "production"
}

If you don't set one of those, the defaults apply. They mean that chronos will communicate with graylog2 directly, using a GELF service running locally on port 12201 (which is the default for a fresh install of graylog2).

{
	"mode" : "graylog2",
	"graylog2" : {
		"host" : "127.0.0.1",
		"port" : 12201
	},
	"amqp" : {
		"host" : "127.0.0.1",
		"port" : 5672,
		"login" : "guest",
		"password" : "guest",
		"vhost" : "/",
		"key" : "logging"
	},
	"stage" : false
}

Usage

Let's say your current crontab looks something like this:

0 * * * * date >> /var/log/cronjobs/myjob.log && php /var/www/myapp/cli/index.php --some=bar

If you just replace this by:

0 * * * * chronos -s mystage -j myjob 'php /var/www/myapp/cli/index.php --some=bar'

From now on chronos will log the results of your cronjobs to graylog2.

Options

The cli options of chronos are:

  • jobname: (-j, required) Name of the cronjob, any string will do.
  • stage: (-s) Define a stage, if none is given the one in /etc/chronos.json is added
  • stdout: (-o) Add stdout output to log
  • stderr: (-e) Add stderr output to log
  • env: (-v) Add all environment variables to the log

Examples

chronos -oj job1 'printf "This output will be added to the log"'

chronos -j job2 'printf "This will trigger an Error-level message"; exit 1;'

Package Sidebar

Install

npm i chronos

Weekly Downloads

8

Version

0.1.0

License

none

Last publish

Collaborators

  • valorkin
  • jkrems