Guest User

Untitled

a guest
Aug 31st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. require 'rubygems'
  2. require 'sequel'
  3.  
  4.  
  5. sql = 'show full processlist'
  6.  
  7. db = Sequel.connect(:adapter=>'mysql', :host=>'localhost', :user=>'root', :password=>'yes')
  8. db_clients = Hash.new {|h,v| h[v] = Hash.new(0)}
  9. db_commands = []
  10.  
  11. db.fetch(sql) do |p|
  12. client, port, command = p[:Host].split(':') << p[:Command]
  13. if client =~ /^192\./
  14. db_clients[client][command] += 1
  15. db_clients[client]['total'] += 1
  16. db_commands << command
  17. end
  18. end
  19.  
  20. db_commands.uniq!
Add Comment
Please, Sign In to add comment