Skip to content

Commit 156b5dd

Browse files
author
Felix Barbalet
committed
fix 100% cpu usage, remove log_level to get all logs, reduce verbosity of SHIPPED messages
1 parent 18fa34d commit 156b5dd

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ sudo -u pyjdbq pip install google-api-python-client pytz tzlocal -t /opt/pyjdbq/
2121
```
2222

2323
Download pyjdbq and move it into /opt/pyjdbq
24+
Put your JSON Google Big Query service account credentials.json file into the same directory
2425

2526
```bash
2627

2728
curl -LOk https://github.com/xlfe/pyjdbq/archive/master.zip
2829
unzip master.zip
2930
sudo cp pyjdbq-master/* /opt/pyjdbq
30-
31-
# Put your JSON Google Big Query service account credentials file into the same directory
3231
sudo mv credentials.json /opt/pyjdbq
33-
3432
sudo chown -R pyjdbq: /opt/pyjdbq
3533
```
3634

@@ -59,7 +57,7 @@ optional arguments:
5957
--debug Extra verbose
6058
```
6159

62-
Install the systemd unit file and check your journald logs to make sure there's no errors!
60+
Install the systemd unit file and check your journald logs to make sure there's no errors
6361

6462
```bash
6563

journal_reader.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import json
1414
import pytz
1515
from tzlocal import get_localzone
16+
import time
1617

1718
# get local timezone
1819
local_tz = get_localzone()
@@ -61,8 +62,8 @@ def __init__(self, writer, log, args):
6162

6263
self.writer = writer
6364
j = journal.Reader()
64-
j.log_level(journal.LOG_DEBUG)
6565
self.log = log
66+
self.total_shipped = 0
6667
self.CURSOR_FILE = args.cursor
6768
self.COUNT_THRESHOLD = args.count
6869
self.SECOND_THRESHOLD = args.timeout
@@ -102,7 +103,7 @@ def check_bucket(self):
102103
Do we need to ship the log entries yet?
103104
"""
104105

105-
if not self.bucket:
106+
if not self.bucket or len(self.bucket) == 1:
106107
self.log.debug('Nothing in bucket')
107108
return False
108109

@@ -119,14 +120,13 @@ def check_bucket(self):
119120

120121

121122
def run(self):
122-
"""
123-
124-
"""
125123

126124
while True:
125+
time.sleep(1)
127126

128127
#get all entries currently available
129128
for entry in self.journal:
129+
#print transform_entry(entry)
130130
self.bucket.append(transform_entry(entry))
131131
self.cursor = entry['__CURSOR']
132132

@@ -142,11 +142,6 @@ def run(self):
142142
else:
143143
self.poll.poll(max_delay*1000)
144144

145-
if self.journal.process() != journal.APPEND:
146-
#Ignore NOP and INVALIDATE entries
147-
self.log.debug('NOP or INVALIDATE')
148-
continue
149-
150145

151146
def ship_logs(self):
152147
"""
@@ -156,7 +151,11 @@ def ship_logs(self):
156151
self.writer.put(self.bucket)
157152
self.last_ship = datetime.datetime.now()
158153
self.save_cursor()
159-
self.log.info('SHIPPED count={}'.format(count))
154+
self.log.debug('SHIPPED count={}'.format(count))
155+
self.total_shipped += count
156+
if self.total_shipped > 500:
157+
self.log.info('SHIPPED count={}'.format(self.total_shipped))
158+
self.total_shipped = 0
160159
self.bucket = []
161160

162161

schema.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
priority:integer,
1+
__realtime_timestamp:timestamp,
2+
_source_realtime_timestamp:timestamp,
23
message,
4+
priority:integer,
35
errno:integer,
46
syslog_facility:integer,
57
syslog_identifier,
@@ -15,7 +17,7 @@ _cap_effective,
1517
_audit_session:integer,
1618
_audit_loginuid:integer,
1719
_systemd_cgroup,
18-
_systemd_session,
20+
_systemd_session:integer,
1921
_systemd_unit,
2022
_systemd_user_unit,
2123
_systemd_owner_uid:integer,
@@ -33,6 +35,4 @@ _udev_devlink,
3335
code_file,
3436
code_line:integer,
3537
code_function,
36-
__realtime_timestamp:timestamp,
37-
_source_realtime_timestamp:timestamp,
3838
extra:string

0 commit comments

Comments
 (0)