Skip to content

Commit

Permalink
Update prometheus.py
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxarun authored May 25, 2022
1 parent 4ba3cd4 commit d269937
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion prometheus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import os,stat
from time import sleep

service = service = os.uname()[1]
Expand Down Expand Up @@ -108,6 +108,9 @@ def gather_metrics():


def tail_log_file():
if not os.path.exists(log_file):
open(log_file, 'w').close()
os.chmod(log_file, 0o777)
current = open(log_file, "r")
curino = os.fstat(current.fileno()).st_ino
current.seek(0, os.SEEK_END)
Expand All @@ -116,13 +119,20 @@ def tail_log_file():
if not line:
sleep(0.1)
try:
if oct(os.stat(log_file).st_mode)[-3:] != '777':
os.chmod(log_file, 0o777)
if os.stat(log_file).st_ino != curino:
new = open(log_file, "r")
current.close()
current = new
curino = os.fstat(current.fileno()).st_ino
continue
except IOError:
if not os.path.exists(log_file):
open(log_file, 'w').close()
os.chmod(log_file, 0o777)
current = open(log_file, "r")
curino = os.fstat(current.fileno()).st_ino
pass
else:
line.replace('\n','')
Expand Down

0 comments on commit d269937

Please sign in to comment.