Skip to content

Instantly share code, notes, and snippets.

@wshihadeh
wshihadeh / docker-compose.yml
Created January 19, 2020 09:19
LDAP Docker compose file
version: '3.7'
services:
ldap_server:
image: wshihadeh/openldap:withdata
environment:
LDAP_ADMIN_PASSWORD: test1234
LDAP_BASE_DN: dc=shihadeh,dc=intern
ports:
- 389:389
volumes:
@wshihadeh
wshihadeh / busy.log
Created January 19, 2020 16:13
Sample logs
2020-01-19 16:12:33.UTC b072799d-3f09-5f2d-ad6f-95778dddc696 OS=Linux AR=_x86_64_ CPU=(4) USR=4.65 NICE=0.00 SYS=3.58 IOWAIT=0.21 IRQ=0.00 SOFT=0.20 STEAL=0.00 GUEST=0.00 IDLE=91.36
2020-01-19 16:12:34.UTC 41f42f48-518b-a636-b649-e7eb8bc6ae59 OS=Linux AR=_x86_64_ CPU=(4) USR=4.65 NICE=0.00 SYS=3.58 IOWAIT=0.21 IRQ=0.00 SOFT=0.20 STEAL=0.00 GUEST=0.00 IDLE=91.36
2020-01-19 16:12:35.UTC 2f34e698-ce7e-92e6-b4bd-8b57de38a44a OS=Linux AR=_x86_64_ CPU=(4) USR=4.65 NICE=0.00 SYS=3.58 IOWAIT=0.21 IRQ=0.00 SOFT=0.20 STEAL=0.00 GUEST=0.00 IDLE=91.36
2020-01-19 16:12:35.UTC 4c827890-b0c4-9c59-4c04-2a55b55ba0c1 OS=Linux AR=_x86_64_ CPU=(4) USR=4.65 NICE=0.00 SYS=3.58 IOWAIT=0.21 IRQ=0.00 SOFT=0.20 STEAL=0.00 GUEST=0.00 IDLE=91.36
@wshihadeh
wshihadeh / docker-entrypoint.sh
Created January 19, 2020 16:15
Busy Log Box
#!/bin/sh -e
while true
do
DATE=$(echo `date +%Y-%m-%d\ %T.%Z`)
ID=$(od -x /dev/urandom | head -1 | awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}')
SYSTEM_DATA=$(mpstat)
SYSTEM_INFO=$(echo $SYSTEM_DATA | awk '{OFS=" "; print "OS="$1" AR="$5" CPU="$6") USR="$21" NICE="$22" SYS="$23\
" IOWAIT="$24" IRQ="$25" SOFT="$26" STEAL="$27" GUEST="$28" IDLE="$29}')
@wshihadeh
wshihadeh / fluentd.rb
Created January 19, 2020 18:26
FluentD Parse configs
<match row.busylogbox.**>
@type record_reformer
tag busylogbox.${tag_suffix[2]}
renew_record false
enable_ruby true
<record>
request_time ${record['log'].scan(/(?<param>^[^ ]+ [^ ]+)/).flatten.compact[0]}
request_id ${record['log'].scan(/(?<param>[^ ]+) OS/).flatten.compact[0]}
os ${record['log'].scan(/OS=(?<param>[^ ]+)/).flatten.compact[0]}
architecture ${record['log'].scan(/AR=(?<param>[^ ]+)/).flatten.compact[0]}
@wshihadeh
wshihadeh / docker-stack.yml
Created January 19, 2020 19:18
FluentD Swarm Stack
version: '3.7'
networks:
logging:
name: logging
driver: overlay
attachable: true
services:
@wshihadeh
wshihadeh / config.rb
Created January 22, 2020 19:24
Extract Rails attributes
<match multiline.**>
@type record_reformer
tag parsed.${tag_suffix[2]}
renew_record false
enable_ruby true
<record>
request_start_time ${record['message'].scan(/\[(?<param>[^ ]+) \#\d+\] [^ ]+ -- : (\[[^ ]+\] )+Started/).flatten.compact[0]}
log_level ${record['message'].scan(/^(I|F|D|W|E), \[[^ ]+ \#\d+\]( )+(?<param>[^ ]+) -- :/).flatten.compact.sort.first}
request_id ${record['message'].scan(/\[[^ ]+ \#\d+\] [^ ]+ -- : \[(?<param>[^ ]+)\] (\[[^ ]+\] )*Started/).flatten.compact[0]}
request_method ${record['message'].scan(/\[[^ ]+ \#\d+\] [^ ]+ -- : (\[[^ ]+\] )+Started (?<param>[^ ]+) [^ ]+ for/).flatten.compact[0]}
@wshihadeh
wshihadeh / docker-compose.yml
Created January 22, 2020 19:54
RubyGems Server
version: '3.7'
services:
rubygems:
container_name: "ruby-gems"
image: wshihadeh/rubygems:latest
volumes:
- gem_data:/application/data
ports:
@wshihadeh
wshihadeh / lograge.rb
Last active February 8, 2020 15:08
Lograge Initializers
Rails.application.configure do
config.lograge.enabled = Rails.configuration.x.feature.lograge
#config.lograge.formatter = Lograge::Formatters::Json.new
config.lograge.base_controller_class = ['ActionController::API', 'ActionController::Base']
config.lograge.custom_options = lambda do |event|
exceptions = %w[controller action format id]
{
request_time: Time.now,
application: Rails.application.class.parent_name,
@wshihadeh
wshihadeh / app.Dockerfile
Last active February 10, 2020 22:16
Precompile on the host
FROM wshihadeh/rails-base-image-ruby:2.6.5-mysql
LABEL maintainer="Al-waleed Shihadeh <[email protected]>"
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
USER rails
WORKDIR /application
@wshihadeh
wshihadeh / docker-compose.yml
Created February 10, 2020 21:32
Precompile at runtime
version: '3.7'
services:
mysql:
image: mysql:5.7
command: mysqld --general-log=1 --general-log-file=/var/log/mysql/general-log.log
volumes:
- db_data:/var/lib/mysql
restart: always