Understanding output of free in Ubuntu 16.04

This post explains output of free command in Ubuntu 16.04 paying special attention to information missing in documentation.

Understanding output

Let’s look at free output in humanreadable, wide mode:

free -hw

        total   used   free   shared   buffers   cache   available
Mem:     2.0G   566M   860M      14M       41M    531M        1.2G
Swap:    4.0G     0B   4.0G

Demystifying ifconfig and network interfaces in Linux

This post explains ifconfig output of common developer’s box, paying special attention to parameters poorly explained in official documentation. It also slightly touches Linux network interfaces.

ifconfig

ifconfig is a command line tool for UNIX-like systems that allows for diagnosing and configuring network interfaces. At boot time, it sets up network interfaces such as Loopback and Ethernet. Most of the time, however, ifconfig is used for network diagnostics.

Before diving into details of its output, let’s first make clear what is an interface.

Polishing Your Curl Expertise

Previous post covers bare minimum of curl you need to know for testing RESTful microservices. Read it first if you need basics. This writing focuses on corner cases and advanced options, making curl experience more enjoyable.

Using Curl For Ad Hoc Testing Of RESTful Microservices

There are plenty of tools available for testing RESTful microservices today. Most of them, e.g. SoapUI, are comprehensive solutions and best fit for creating testing suites. Using such a tool to check a single faulty endpoint would be an overkill.

So what should you choose for ad hoc testing instead? There are simplified GUI tools, e.g. Postman, and many developers are happy with them. But if you are after ultimate performance and love command line, there is a better option - curl. In this post I’ll show how to check RESTful endpoints using curl with a lot of examples.

How To Create Health Check For RESTful Microservice In Golang

Imagine you’ve recently released and deployed to production a cool RESTful microservice you worked on for a while. You heaved a sigh of relief just to hear from Ops team that your service is unstable. You are damn sure that the service should be fine, but you get a feeling that there could be something wrong with services it depends on. What should you do?

Health check will come to your rescue. It is an endpoint in your service returning status of your application including statuses of connections to all external services your service directly depends on. In this post I’ll show how to create a health check for a microservice running on multiple nodes, storing its state in MongoDB and calling Elasticsearch.

Unit Testing Golang Code Calling Elasticsearch

There is an amazing Elasticsearch client for Go and in Working With Elasticsearch I demonstrated with example how to index and search for documents using it. However, if you want to ensure your code will continue working correctly and will not be inadvertently broken during refactoring, you have to cover the code with tests.

In this post I’ll show how to unit test Go code interoperating with Elasticsearch. Keep in mind, however, that the same approach is applicable to unit testing almost any code calling external RESTful API.

How To Correctly Serialize JSON String In Golang

json is one of the most wildly used Go packages. It is simple and, what is more important, very intuitive. So what could be easier than marshalling a string with JSON and unmarshalling it to struct? If you believe (as I did) that the issue is trivial and json.Marshal does the job, read on.

What’s wrong with json.Marshal?

It’s easier to demonstrate on example. Let’s write a simple program which serializes JSON string to bytes and deserializes the bytes into matching struct:

Collecting Logs In Elasticsearch With Filebeat and Logstash

You are lucky if you’ve never been involved into confrontation between devops and developers in your career on any side. In this post I’ll show a solution to an issue which is often under dispute - access to application logs in production.

The issue at hand

Imagine you are a devops responsible for running company applications in production. Applications are supported by developers who obviously don’t have access to production environment and, therefore, to production logs.

Imagine that each server runs multiple applications, and applications store logs in /var/log/apps. A server with two running applications will have log layout:

$ tree /var/log/apps
/var/log/apps
├── alice.log
└── bob.log

The problem: How to let developers access their production logs efficiently?

Working With Elasticsearch in Go

Elasticsearch is one of the most popular highly scalable full-text search engines on the market. It is based on Lucene engine and allows you to store, search, and analyze big volumes of data quickly and in near real time. It has rich REST API and clients for most popular programming languages including Go. In this post I’ll demonstrate on example how to index and search for application logs using Go.

Installing Elasticsearch

If you haven’t set it up already, installation of Elasticsearch is as easy as downloading it (from here) and running the executable file. I installed it on localhost and will use it in my examples.

When installation is over, let’s test that Elasticsearch is up and running:

curl http://localhost:9200

The response should be similar to:

{
  "name" : "Specialist",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.3.4",
    "build_hash" : "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f",
    "build_timestamp" : "2016-06-30T11:24:31Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}

Example Of Using Templates In Golang

Almost every programming language has a library implementing templating. In epoch of server side MVC dominance, templating was so important that it could determine language success or failure. Nowadays, however, when single page applications get momentum, templates are used only occasionally.

The niche where templates are still absolutely indispensable is email content generation. In this post I will demonstrate on an example how to use Golang template package to generate email content based on a template defined in a file. I’ll keep example as simple as possible, but beefy enough to show most commonly used features of the package.