Identify Swap Usage on Linux

2017-01-13 17:51:51 +0000

This small script can be used to identify what is using up swap on any Linux system. An alternative is to use top , press O p [Enter]. Below are a few lines which will give you a breakdown of swap usage. Some processes will have multiple rows if they have multiple memory regions swapped out.

#!/bin/bash
printf "%-25s %-25s %-25s\n" "PID" "Swap (kB)" "Process"
printf "==============================================================================================\n"
for x in $(grep Swap /proc/[1-9]*/smaps 2>/dev/null | grep -v '\W0 kB' | tr -s ' ' | cut -d' ' -f-2 | sort -t' ' -k2 -n | tr -d ' ' | tail -20); do
printf "%-25s %-25s %-25s\n" $(echo $x | cut -d/ -f3) $(echo $x | cut -d: -f3) $(ps -p $(echo $x | cut -d/ -f3) -o comm=)
done

EVE Mattress - Is it Really Worth £700?

2017-01-10 08:32:23 +0000

I decided to use my good old friend, the Credit Card for this one. It’s a lot of money, and considering my last king-size memory foam mattress only cost £180, it took me a while to make the jump.

###I just want to point out that their advertised ‘100 night trial’ is misleading. Normally, you do not pay for a trial until the time has expired, however, in this situation (as I already had concluded at time of purchase), they take the money up front. It’s more accurately a 100-day returns policy. That’s marketing for you. Stretching the truth.

Having said that, the stats do not lie. Here is a before using the new mattress from my Fitbit:

Before the new mattress

..and now after:

After getting the new mattress

As you can see, my sleep has improved since swapping mattresses. There was a couple of changes I needed to make - a weeks worth of adjustment for your back, the smell, and most importantly, the pillows!

I found that I was waking up with backache every morning. I always had two pillows to compensate for the dent that was in my old memory foam mattress. So, a few nights back, I threw one of the pillows across the room and have never looked back.

So, I am almost a month into my trial. My conclusion so far?

I still look at it and think it is too soft, and I worry its going to do what my old mattress did. In reality, its not too soft, it’s just right, now that I have one pillow and my weight is balanced better. Dent-wise, there is a 7 year guarantee on the mattress, so if it does happen again, it’s a fault with the mattress. I’m not that heavy.

The cost: I can still back out and get my money back. Its a hell of a lot of money, but like I said before, the stats do not lie. I’m getting a better nights sleep, and perhaps it is worth the money after all.

All in, I’m happy and I am recommending the mattress to everyone - I am surprised at the number of people who have had a mattress over 10 years but complain of the state it’s in. They too are considering replacing them now, and taking my recommendation seriously.

Preventing DNS amplification attacks

2017-01-03 19:50:17 +0000

As you may be aware, I run my own DNS resolver(s), and I am constantly plagued by some German governmental body waffling on about DNS Amplification Attacks.After a bit of toking and fro-ing, I decided to investigate further. The official answer is ‘don’t run a public resolver’, however, the following IPTables snippet will prevent people from hammering the DNS by causing packets to be rejected. The numbers may need to be fiddled around with, but it seems to work, and with the added logging, PSAD can then pick up the offenders and go down the ban hammer route.

iptables -N DNSDROP iptables -A DNSDROP -m limit --limit 2/min -j LOG --log-prefix "DNS-Dropped: " --log-level 4 iptables -A DNSDROP -j DROP iptables -A INPUT -p udp --dport 53 -m recent --set --name dnsdos iptables -A INPUT -p udp --dport 53 -m recent --rcheck --seconds 1 --name dnsdos --hitcount 5 -j DNSDROP

 

 

Hits per minute stats from an Apache Access Log

2017-01-03 18:40:07 +0000

If you need to get the number of hits per minute from your Apache access log, you can do the following:

cat access.log | cut -d [ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c

If you wish to filter it down by a specific vhost, or file, you can replace the cat with a grep, like so:

grep myfile.zip  access.log | cut -d [ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c

More Drawing

2016-12-17 19:25:25 +0000