Write Naemon Log
We can write to naemon.log file by issue command
OMD[monitor@501264b41d2d]:~/var/naemon$ pwd /omd/sites/monitor/var/naemon OMD[monitor@501264b41d2d]:~/var/naemon$ echo "[$(date +%s)] User Activity msg TEST log" >> naemon.log
Linux command date +%s will print time in current time since Epoch 1970
In C program, we can implement this function with bash shell via system( bash cmd )
int writeLogFile( char *msg ) { char str_msg[1024]; sprintf( str_msg, "echo \"[%d] User Activity %s \" >> /omd/sites/monitor/var/naemon/naemon.log",(int)time(NULL), msg); printf(str_msg); system(str_msg); return 0; }
logrotate
we can config naemon.log to rotate as following
OMD[monitor@906094f86a76]:~/etc/logrotate.d$ more /omd/sites/monitor/etc/logrotate.d/naemon /omd/sites/monitor/var/naemon/naemon.log { daily rotate 7 nocompress olddir /omd/sites/monitor/var/naemon/archive dateext dateformat -%Y%m%d missingok notifempty postrotate [ -f /omd/sites/monitor/tmp/lock/naemon.lock ] && kill -s USR1 `cat /omd/sites/monitor/tmp/lock/naemon.lock` endscript create 0664 monitor monitor } /omd/sites/monitor/var/naemon/livestatus.log { missingok rotate 0 compress delaycompress notifempty create 640 monitor monitor }
A file thruk.log was an activity user log. We can logrotate as following
OMD[monitor@906094f86a76]:~/etc/logrotate.d$ more /omd/sites/monitor/etc/logrotate.d/thruk /omd/sites/monitor/var/log/thruk.log { daily rotate 3 nocompress olddir /omd/sites/monitor/var/log/archive dateext dateformat -%Y%m%d missingok notifempty create 660 monitor monitor } /omd/sites/monitor/var/thruk/cron.log { missingok rotate 0 compress delaycompress notifempty create 660 monitor monitor }
Log viewer
Ref here
We use this java v8 to run as web server on port 8111 and browse the log file and show on web page.
File can be download from the web or in attach file with in this page
[krit@mini log-viewer-1.0.1]$ ./logviewer.sh
Convert epoch time to human on Log file
ref here
Example: file.log
1522693524403 entity1,sometext 1522693541466 entity2,sometext 1522693547273 entity1,sometext
Just use
$ awk '{$1 = strftime("%F %T", substr($1,1,10))} 1' file.log 2018-04-02 21:25:24 entity1,sometext 2018-04-02 21:25:41 entity2,sometext 2018-04-02 21:25:47 entity1,sometext
With milliseconds
$ awk '{$1 = strftime("%F %T", substr($1,1,10)) "." substr($1,11)} 1' file.log 2018-04-02 21:25:24.403 entity1,sometext 2018-04-02 21:25:41.466 entity2,sometext 2018-04-02 21:25:47.273 entity1,sometext
Last modified 2 years ago
Last modified on 06/07/22 00:42:15
Attachments (2)
- log-viewer-1.0.1.zip (12.2 MB) - added by 3 years ago.
- log-viewer-1.0.1.tar.gz (1.2 MB) - added by 3 years ago.
Download all attachments as: .zip