Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.
/ gcron Public archive

A command executer with centralized logging

License

Notifications You must be signed in to change notification settings

mbrostami/gcron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Go Report Card Download

gcron [In Development]

Features

  • Skip a command's execution if the previous run is not completed yet
  • Delay a command's execution
  • Log a command's output plus stats (systime, usrtime, status, duration, ...)
  • Override command status by using regex pattern
  • Skip a command's execution if the previous run IN OTHER SERVER is not completed yet (gcrond)
  • Centalize all logs in gcrond server (gcrond)
  • GUI server interface (gcrond)
  • Duration graph in command page (gcrond)

gcron IS NOT

  • Cron job manager
  • Job scheduler

Workflow

Install

Download one of the packages in release assets
Install gcron (agent)
dpkg -i gcron_*_Tux_64-bit.deb

[Optional]
If you want to use GUI or centralized logging server
Install gcrond (server)
dpkg -i gcrond_*_Tux_64-bit.deb

Configuration can be found in /etc/gcron/gcron.yml and /etc/gcron/gcrond.yml

Usage

gcron usage (agent)

gcron --help  

  --c                        (string) Command to execute
  
  --delay int                (int)    Delay running command in seconds
  
  --lock.enable              (bool)   Enable mutex lock
  --lock.name                (string) Custom mutex name
  --lock.remote              (bool)   Use rpc mutex lock
  --lock.timeout             (int)    Mutex timeout (default 60)
  
  --log.enable               (bool)   Enable log
  --log.level                (string) Log level (default "warning")
  
  --out.hide.duration        (bool)   Hide duration tag
  --out.hide.systime         (bool)   Hide system time tag
  --out.hide.uid             (bool)   Hide uid tag
  --out.hide.usertime        (bool)   Hide user time tag
  --out.tags                 (bool)   Output tags
  
  --override                 (string) Regex pattern to override command status (match in command output)
  
  --server.rpc.enable        (bool)   Enable using gcrond
  --server.rpc.host          (string) gcrond host
  --server.rpc.port          (string) gcrond port

gcrond usage (server)

gcrond --help  

  --log.enable               (bool)   Enable log
  --log.level                (string) Log level (default "warning")
  --log.path                 (string) Log file location
  
  --server.rpc.host          (string) RPC Server host
  --server.rpc.port          (string) RPC Server port

  --server.web.host          (string) Web server host
  --server.web.port          (string) Web server port

Examples

Delay running command

gcron -c="echo HelloWorld" --delay=5

Delay running command but avoid duplicate running

gcron -c="echo HelloWorld" --delay=10 --lock.enable

Mutex lock to prevent overlap same command

gcron -c="sleep 61 && echo HelloWorld" --lock.enable

Enable logging and log level

gcron -c="echo HelloWorld" --log.enable --log.level=trace

Display tags (systime, usertime, duration, etc)

gcron -c="echo HelloWorld" --log.level=info --out.tags

Override command status which is stored in tags.status [case sensitive]

gcron -c="echo HelloWorld" --log.level=info --out.tags --override=".*World$"
gcron -c="echo HelloWorld" --log.level=info --out.tags --override=".*Worl$" 

Remote mutex lock to prevent overlap same command in multiple servers

Server

gcrond --log.level=trace  

Client

gcron -c="echo Server1HelloWorld" --server.rpc.enable --lock.enable --lock.remote

Using gcron as cron

* * * * * gcron -c="echo Delay5seconds" --delay=5
* * * * * gcron -c="echo Delay5seconds" --delay=10
* * * * * gcron -c="echo Delay5seconds" --delay=15


* * * * * gcron -c="echo LocalLock" --lock.enable


* * * * * gcron -c="echo ServerLock" --server.rpc.enable --lock.enable --lock.remote

Screenshots

Main Page

Main page

Task Duration Graph

Task duration

Task Details

Task info

TODO

gcron (agent)

  • Cleaner code!!
  • Clean code
  • Test
  • Support different log formats for write/stream purpose
  • Ignore errors (Run command even if connection is not established)
  • Run cron after given seconds
  • Implement gRPC
  • Send output to remote server (tcp/udp/unix)
  • Configurable tags (mem usage, cpu usage, systime, usertime, ...) (flag/config)
  • Trackable id for logs
  • Optional Regex status (Accept regex to change status of the cron to false or true)
    • By default exitCode of the cron command will be used to detect if command was successful or failed
  • Stream logs over rpc
  • Remote mutex lock
  • Local mutex
  • Remote lock based on command
  • Remote lock timeout
  • Log rotation

gcrond (server)

  • Cleaner code!
  • Write tests
  • Implement shared lock for clients
  • Migrate mutex from file locking to use db
  • Mutex client timeout
  • Pick high performance database to store all logs (search optimised, hash O(1) read support)
  • GUI
    • Authentication
    • Use FE framework (uikit, npm, webpack)
    • Search logs (tag, hostname, uid, command, guid, output)
    • Bundle JS with webpack
    • Bundle CSS with webpack
    • Command page duration graph
  • Log stream proxy... (remote third party log server, REST Api, tcp/udp)
  • TLS enabled over RPC
  • Client authentication + (caching system)
  • Async write (Get stream logs and write in database async)
  • Handle connection timeouts
  • Customized taging clientside
  • Support different clients (syslog, ...)
  • Fix casts int32 to int or int64 to int32
  • Live reloading config file
  • Log rotation / expire time

FIXME

  • Delete local lock file

Development

go run cmd/gcron/* -c="git status" --log.level=debug

go run cmd/gcrond/* -log.level=trace