Connect USB from Virtual Machine using Vagrant and Virtual Box

Sometimes (e.g You are developing an IoT Project), you need to connect you board to Virtual Machine via USB Port. This post will show you steps to connect USB port from Virtual Machine using Vagrant and Virtual Box.

At the first, you have to make sure that the USB device was connected to your computer with command:

The output above shows the USB Device has VendorID is 0x1a86 and ProductId is 0x7523. So we add the lines below to Vagrantfile:

Finally, starting your Virtual Machine:

In your Linux Virtual Machine, type lsusb to check the result.

Using Ngrok to publish HTTP and SSH for your Rasperberry Pi

I have a Rasperberry Pi 2, and i put it in my home in the silent.  Sometimes I need to ssh to my Pi or view a website that I deployed to my Pi. I looked for a solution in the Internet. I found Ngrok. I really fitted my case. So in this post, I will share you the way to setup Ngrok on Rasperberry Pi in step by step.


Download Ngrok

You find the correct link to download at https://ngrok.com/download. You see “Linux ARM” and get the link.

After that, you do some commands to download and decompress:

Creating Configuration File for Ngrok

We need to publish two tunnels (ssh, http). So we have to create a Ngrok configuration file to declare those services.

I create a file named ngrok.yml with content as below

web_addr: means that I can access Ngrok Webpage on my Pi via http://RASPERBERRY_PI_IP_ADDRESS:4040

I also declare two protocols and address for two tunnels – SSH and HTTP

Installing Supervisor

We need run Ngrok as a daemon (in background). So I use Supervisor – a third-party process manager. You can install Supervisor with command.

After finishing the installation, we create a Supervisor configuration file at /etc/supervisor/config.d/ngrok.conf with content as below

Running the tunnels

In this step, we just need to run the program via Supervisor by command:

Verifying your works

Now, we open the browser and access http://PI_IP_ADDRESS:4040 to get the information of tunnels and try a test.

Monitor server with CollectD, InfluxDB and Grafana

In the software development, Monitor is a big feature we need to concern. It is not only for monitoring the production. But we also need to monitor your testing environment (e.g for performance test, stress test). So in this post, I will show you how to monitor server with CollectD, InfluxDB and Grafana.

At the first, we have to install CollectD in the agent machine. In my case, the agent machine also uses Ubuntu 14.04. And we have to install CollectD version 5.5.0+. Why? Because all the versions easier 5.5.0, Plugin cpu of CollectD only use jitters metric that we can not show properly in Grafana.

Gopher and Gun T-Shirt

Gopher and Gun T-Shirt

My scenario is:

  • I have 2 servers installed Ubuntu 14.04
  • One at address And the other one is that we need to monitor
  • They can ping each others.
Collectd Grafana InfluxDB

We will monitor server with CollectD

So now, Install CollectD to Server


I recommend you install CollectD from the source code to make sure that you are using the correct version.

Before running build the packet from source code, we need to install the dependencies:

(libcurl4-gnutls-dev to enable curl and nginx plugin)

Edit /opt/collectd/etc/collectd.conf to enable CollectD collect cpu data with percentage instead of jitters:

And enable network plugin to push monitor data to InfluxDB at address, port 25826

Restart CollectD


And now, we install InfluxDB and Grafana in Server


Install with dpkg command:

InfluxDB Web run on port 8083, so you access web at address and create collectd database:

Edit /etc/influxdb/influxdb.conf to enable collectd. See the content below:

Please make note that with the configuration above we use port 25826 on UDP to receive monitor data that pushed from CollectD

And the next step,  restart InfluxDb:

For troubleshoot the issue with InfluxDB, we can view logs:


Download and install via dpkg command:

If you meet an error as below:

You can correct it by the commands:


Grafana run on port 3000. So you can access via link

To connect InfluxDb,  you follow the path: Grafana => Data Source => Add New => And Input the information as the image below:

25-11-2015 3-22-51 CH

Grafana connects to InfluxDB (default account root/root)

After that, create New Dash Board => New Panel => Graph as image below:

28-11-2015 7-31-40 CH

Grafana + CollectD CPU (percentage)

I created a new dashboard that help me monitor CPU and RAM:

25-11-2015 4-19-02 CH

Grafana, CollectD and InfluxDB


To collect interface data in bytes per second we should use:


Logrotate Nginx Custom Logs

As you know, when you create a site in nginx webserver, you will want to add custom logs for that site. So this post is a small tip to help you how to do it perfectly.

In your nginx site config (e.g /etx/nginx/site-availables/example.com), you add custom logs as below:

So now, your log files will be bigger day by day. You will have to remember to delete the log files if you do not want to your hard disk be full. What should you do now? Fortunately, Logrotate will help you compress. clean and backup it daily.

You just have to add (append) the content below to /etc/logrotate.d/nginx:

Finaly, run the command below to force the update.

It is done.

Install Cloudera Hadoop in Ubuntu 14.04

As you know,  Install Hadoop is not easy. And It require a virtual machine with high configuration.  In my post, I will give you the shortest way to have Hadoop in your machine. It is installation via Docker. I assume that you had Docker in your Ubuntu 14.04


If your dreams do not scare you. They are too small.


  • Docker
  • Ubuntu 14.04
  • Ram 4G
  • CPU 2 core


To install the docker-cloudera-quickstart from docker-hub, simply use the following command:


To start an instance in BACKGROUND (as daemon):

To start an instance in FOREGROUND:

To open more terminal instances for the running instance:

Test MapReduce with WordCount example

Refer to: http://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html

Refer to:

Change hostname without reboot Ubuntu 14.04

This is a small tutorial to help you change hostname of server without reboot the system. This will require  3 simple steps

Step 1: change hostname by command line

Step 2: edit hostname file with new hostname

Step 2: edit hosts file

Edit the line below:

It is done.

Install Scrapy Portia in Ubuntu Server 14.04

There are 2 ways to install Scrapy Portia in Ubuntu Server 14.04: Install via virtualenv/pip or Install Docker. Please see the details below

The key is not to prioritize what's on your schedule, but to schedule your priorities

The key is not to prioritize what’s on your schedule, but to schedule your priorities

Option 1: Install Portia via Virtualenv/pip

Please make sure that virtualenv and pip is ready to use in your server.

Do activate Portia environment:

Download Protia source code:


Install libraries, packets:

Check  port 9001, and run Portia:

Test Portia at link: http://localhost:9001/static/main.html

Install Portia via Docker (recommended):

Make sure that Docker was installed in your server and ready to use:

Download source code:

Build Portia Image:

And run Protia Docker container:

Install CoreOS, Vagrant in Ubuntu Server14.04

In this article, I will show you 2 steps. The first step is install Vagrant Ubuntu Server 14.04. The second one is install CoreOS in Vagrant. Actually, I run Ubuntu Server in Vmware. So to run CoreOS, I have to turn on Virtualize Intel. Please see image below:

Virtualize Intel

Install VirtualBox in Ubuntu:

Install Vagrant

Upgrade Vagrant:

Install Git if needed

Get CoreOS-Vagrant Sample

Create config file from sample config file:

Turn Vagrant Machine on:

Try to run CoreOS nodes:


How to trigger a Jenkins build from Slack

As you know, Slack is a great product for team communication. And Jenkins help you setup a automation build (Continuous Integration). In this article, I will show the way how to use Slack Commands to trigger a Jenkins build.

Golang or Gohome T-Shirt

Buy Golang or Gohome t-shirt

In your Jenkins, you install Build Authorization Token Root Plugin, as image below



In configuration job Jenkins, you check “trigger builds remotely” and add a token (you can get a random token here). See image below

29-01-2015 2-15-02 CH

So now, you can trigger a remote build by url:

For details, you can read https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin

In your Slack, you create a Slack Commands in Slack (e.g: /build_example).

Command textbox, type “/build_example”

URL textbox, add http://[jenkins_url]/buildByToken/buildWithParameters?job=[job_name]&token=[your_token]&[param=value]

Method combobox, choose GET. Finally, click “Save”

29-01-2015 2-24-25 CH

To test your work, go to Slack chat page, you type “/build_example” and check the result.

If you want to build with parameters from Slack (e.g /build [branch]). You need write a proxy script to handle the build. You can take a look to https://github.com/thanhson1085/slack-jenkins as a example