Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gets logs from nginx-ingress container and generate GoAccess dashboard for each of the services + all combined (Blog: https://mustak.im/server-side-kubernetes-nginx-ingress-log-analysis-using-goaccess/)
#!/usr/bin/python
import os
import subprocess
def process_log_for_svc(svc,out):
print('Processing ' + svc)
os.system("rm -f /storage/goaccess/imported-logs/imported-log.log")
os.system('find /var/log/containers/ | grep nginx-ingress | xargs sudo cat | grep ' + svc + ' >> /storage/goaccess/imported-logs/imported-log.log')
print("Parsing...")
os.system('goaccess -f /storage/goaccess/imported-logs/imported-log.log --real-os --log-format="%^ %^ [%h] - - [%d:%t] %~ %~ %m %U %^ %s %b %R %u %^ %^ %^ %^ %^ %T %^" --date-format="%d/%b/%Y" --time-format="%H:%M:%S +0000" > /storage/goaccess/out/' + out + '.html')
print("Cleaning...")
os.system("rm /storage/goaccess/imported-logs/imported-log.log")
print('Getting all services')
all_svc=os.popen('kubectl get svc | tail -n +2 | awk \'{print $1}\'').read()
all_svc_arr = all_svc.split('\n')
print('Creating index.html')
index_html=''
for svc in all_svc_arr:
index_html += '<a href=\"' + svc + '.html\">' + svc + '</a><br/>'
index_html = '<a href=\"all.html\">-ALL-</a><br/>' + index_html
text_file = open("/storage/goaccess/out/index.html", "w")
text_file.write(index_html)
text_file.close()
print('Processing All Logs')
process_log_for_svc('Mozilla','all')
for svc in all_svc_arr:
process_log_for_svc(svc,svc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.