Skip to content

Instantly share code, notes, and snippets.

@haraldh
Created December 9, 2015 10:54
Show Gist options
  • Save haraldh/d94864fa47aab7c5ac27 to your computer and use it in GitHub Desktop.
Save haraldh/d94864fa47aab7c5ac27 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from systemd import journal
import random
import sys
import time
import string
from syslog import syslog
class ToLog:
NONE, DEVNULL, SYSLOG, JOURNAL = range(4)
sinkname = [ "No output",
"/dev/null",
"syslog___",
"journal__" ]
printables = string.ascii_letters
random.seed()
MSG = [ (''.join(random.choice(printables) for a in range(1024*10))) for b in range(10000) ]
MSG_LEN=len(MSG[0])
def perflog(to=ToLog.NONE, maxduration=30):
c=0
maxcount=len(MSG)
n = 0
if to == ToLog.DEVNULL:
fnull = open('/dev/null', 'w')
t1 = time.time()
t2 = t1
while (time.time()-t1) < maxduration and n < maxcount:
n += 1
if to == ToLog.JOURNAL:
journal.send(ToLog.sinkname[to] + MSG[n-1])
elif to == ToLog.SYSLOG:
syslog(ToLog.sinkname[to] + MSG[n-1])
elif to == ToLog.DEVNULL:
print(ToLog.sinkname[to] + MSG[n-1], file=fnull)
fnull.flush()
elif to == ToLog.NONE:
pass
return (n * (len(ToLog.sinkname[to]) + MSG_LEN) / (time.time() - t1))
if __name__ == '__main__':
for j in range(10):
for i in range(len(ToLog.sinkname)):
throughput = perflog(i)
if throughput > (1024*1024):
print("%s: %.0fMb/s" % (ToLog.sinkname[i], throughput/1024/1024))
elif throughput > 1024:
print("%s: %.0fkb/s" % (ToLog.sinkname[i], throughput/1024))
else:
print("%s: %.0fb/s" % (ToLog.sinkname[i], throughput))
print()
# sleep, if there is a rate limit
if j != 9:
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment