How to monitor bandwidth on Ubuntu Server

I wanted to monitor the bandwidth usage on my Ubuntu server without a full blown graphic monitoring system but something that I could just check once in a while just to see how things are running. I found an really simple tool called vnstat. It’s good because it’s simple, fast and easy to use and that doesn’t require a PhD in networking to get going. It also nicely presents the data with good summaries.

Here is how I setup network traffic monitoring using vmstat:

1 – Install vnstat – note there is another program called vmstat – so be careful what you type.

sudo apt-get install vnstat

2 – Configure the network adapter to monitor. Vnstat automatically configures the network adapters however it’s worth checking that they are correct and having a quick peek through the configuration file.

sudo nano /etc/vnstat.conf

If you do have made any change then don’t forget to restart the service.

sudo service vnstat restart

3 – Get you first report – You will have to wait a few minutes to get your first report. This how a typical report looks like:

#vnstat

outputs:


Database updated: Sun Nov  9 20:11:55 2014

   eth0 since 07/22/14

          rx:  4.56 GiB      tx:  109.97 GiB      total:  114.53 GiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       Oct '14      1.24 GiB |   38.39 GiB |   39.63 GiB |  124.13 kbit/s
       Nov '14    361.70 MiB |    9.56 GiB |    9.91 GiB |  108.84 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated      1.20 GiB |   32.43 GiB |   33.62 GiB |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     yesterday     37.62 MiB |  805.67 MiB |  843.29 MiB |   79.96 kbit/s
         today     29.32 MiB |  176.40 MiB |  205.73 MiB |   23.18 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        34 MiB |     209 MiB |     243 MiB |

Hope this is useful to someone. Let’s me know if you have any improvements to this post or can recommend other tools that readers of this blog might be interested in.

How to stop .ds_store files being created in Apple OSX

I use source control while developing software. Apple’s OSX creates .DS_Stores files in any folder that you browse with Finder. These are normally hidden but they obviously aren’t ignored by version control which is designed track everything including hidden files. I could add them to the .ignore files in both Mercurial or Git – but this is time consuming and annoying.

Therefore, I installed asepsis which an lightweight opensource tool. This forces Mac to store all the .DS_store files in another location. It was quite straight forward to get going.

1. Download the software
2. Install it
3. Restart the computer
4. Migrate all the existing DS_store files using the command:

asepsisctl migratein 

Hope this is helpful.

Firefox Spell Checker Doesn’t Work In Apple Mac OSX – How to fix…

I’ve moved from Ubuntu to Apple Mac OSX and like to use Firefox.  However, rather annoyingly the Firefox spell checker doesn’t appear to work on Apple by default.  Bizarrely, it doesn’t highlight any incorrect spellings.  I found that the only way to fix it was to add another dictionary to Firefox.  Here is how I did it.

Step 1 – Find a dialogue box or text box and right click.  You should see a menu like so.  You could click Language -> Add Dictionaries

how_to_make_firefox_spell_check_work_osx

Step 2 – You will be taken to the Firefox Dictionary and Language Pack Page .  You should select and install the right dictionary for your locale.

firefox_spell_check_broken_apple_mac_osx

Step 3 – I installed English (United Kingdom) dictionary and immediately the spell checker  immediately started working.  Hope this helps someone else.

p.s. if anyone from the Firefox team are reading this – why doesn’t Firefox work with native Apple spell check / dictionary?

sudo: can’t open /etc/sudoers: permission denied

The sudo command checks the permission of the /etc/sudoers file and also the contents of /etc/sudoers.d/ before allowing you to use the sudo command.

For example you might be warned:

sudo: /etc/sudoers is mode 0777, but should be 0440

or perhaps:

sudo: can't open /etc/sudoers: permission denied.
sudo: no valid sudoers sources foundm quitting

Therefore, if you don’t have root login (which is generally good security practise) then you might not be able to change the permission back without dropping into recovery mode.

1 – Reboot the machine

2 – Select boot from recovery more

3 – fsck the disk which will then mount the disks as read/write

4 – Drop to root shell

5 – chmod 0400 /etc/sudoers

6 – reboot the machine and you are fixed

Apache 2.4 Failed To Start AH00016: Configuration Failed

One of our Apache 2.4 web servers strangely stopped working and didn’t want to come back up. I tried to start it but it came back with a vague error message:

$ sudo service apache2 start
Starting web server
apache2 Action 'start' failed.
The Apache error log may have more information.

A quick look in /var/log/apache2/error.log just showed nothing useful:

$ tail var/log/apache2/error.log
AH00016: Configuration Failed, exiting

So, I ran the Apache configuration check tool on the configuration files but the syntax was okay.

$ sudo apache2ctl configtest
Syntax OK

This means that there isn’t anything wrong with the syntax of the Apache config and I generally find that this means either an SSL certificate isn’t installed incorrectly or there is something wrong with a more general configuration file. To find which host had configuration file problems – I used the strace command. This is really good because it shows all of Apache’s interactions with the file system. Therefore you can see the last file Apache opened before failing.

sudo apt-get update
sudo apt-get install strace
sudo strace -f apache2ctl start

The output from strace is quite large but you can clearly see where Apache failed.

.....
[pid  6068] munmap(0x7f45c6c38000, 4096) = 0
[pid  6068] write(11, "[Sun Oct 05 07:35:44.207805 2014"..., 189) = 189
[pid  6068] write(2, "AH00016: Configuration Failed\n", 30) = 30
[pid  6068] select(0, NULL, NULL, NULL, {0, 10000}) = 0 (Timeout)
.....

and just before this was this…

[pid  6068] munmap(0x7f45c6c38000, 4096) = 0
[pid  6068] open("/etc/ssl/private/a_website_ssl.key", O_RDONLY) = 45
[pid  6068] fstat(45, {st_mode=S_IFREG|0644, st_size=1704, ...}) = 0
[pid  6068] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f45c6c38000
[pid  6068] read(45, "-----BEGIN PRIVATE KEY-----\nMIIE"..., 4096) = 1704
[pid  6068] close(45) 

This enabled me to quickly idenfity which ssl certicate was causing the problems and disable the site which was using that key.

sudo a2dissite a_weebsite.conf

I hope that someone finds this useful.

how much does it cost to distribute ghostscript commercially?

I’ve been working on a commercial project where we would have liked to use Ghostscript. To use ghostscript in a commercial settings (i.e. to distribute it alongside binary code) you need to have a license.   At the time of writing (September 2014) – the costs for this are rather prohibitive:

There is a minimum $8000 per quarter and a $5000 set-up fee. This fee can increase depending your business usage.

Wow. That’s too rich for me. Time to find another pdf lib.

How To Recover / Get Your Music From Your IPod / IPad / IPhone

It’s a classic mistake. You buy an ipod, import all your music into itunes, sync it onto the ipod… then at some point loose the computer. Suddenly, your ipod has all of your music on it and you can’t get it off. Don’t panic… there is hope but it does cost you $35. Yes, there are other solutions to this problem but this is something anyone can go.

Install itunes on a new computer
You will need the drivers for your ipod and therefore you need to download and install itunes.

Stop itunes automatically syncing
Once you have installed itunes, you need to make sure that it doesn’t automatically override the music on your ipod by automatically syncing nothing over the top. To this go to:

Edit -> Preference -> Devices and check ‘Prevent Ipods… from automatically syncing’.

Buy a copy of iExplore
Iexplore is the program which makes this really easy to do. The only draw back is that it costs $35. Personally, I think this is completely reasonable given that it saved over 2,000 songs for me. Buy a copy of the software, download and install it.

Plug in your device
with a usb cable.

Open Iexplore
Browse to device -> music -> select all the tracks and then you can transfer either to itunes or a folder.

Job done.