Category Archives: NoSQL

Redis: print to STDOUT from a LUA script

When you want to print to STDOUT from a LUA script executed by “redis-cli –raw –eval”, it doesn’t print to STDOUT but in Syslog. You will need to use “return” instead.

Let’s help yourself with a “logit” function, like this:

local log = {}
local function logit(msg)
  log[#log+1] = msg

-- Some code

    -- Log my string

-- Some more code

-- print log to STDOUT
return log

That’s awesome till you don’t know how to pass arguments to your Redis LUA script ! :-)

Redis: passing args to a LUA script

How did it came in their brain that the arguments where not stored in the ARG[] array but in the KEYS[] one ?

So if you want to call your Redis LUA script this way:

redis-cli --raw --eval myscript.lua arg1 arg2 ...

You have to access your args this way in the LUA script:

local arg1=KEYS[1]
local arg2=KEYS[2]

That’s awesome till you don’t know how to STDOUT print some results :-)

Building MongoDB for Debian Jessie

Today Debian Jessie doesn’t have a recent version of MongoDb. They provide 2.4.10 when I (and you if you arrived here) need something newer like 3.0.6. On MongoDB website, you can download Debian packages but only for the already old Wheezy…

So you will need to download the MongoDB 3.0.6 tgz source file here and try to build the .deb on your own. That’s how I did it:

First, I’ve Installed this list of debian packages:

apt-get install debtools devscripts gcc libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libgoogle-perftools-dev libpcap-dev libpcre3-dev libreadline-dev libsnappy-dev libstemmer-dev libssl-dev libv8-dev python-pymongo scons dh-systemd

Once you’ve untar the archive, go to the debian/ directory and add thoses links:

ln -s mongodb-org-unstable.control control
ln -s mongodb-org-unstable.rules rules

In the control file change the first line from “Source: mongodb-org-unstable” to “Source: mongodb”.

In the rules files, uncomment each commented scons command, especially in the build-stamp part. I’ve changed it to “scons -j12 all” to build it with 12 parallel gcc process (depends how many cores your CPUs have).

Still in the debian/ directory, In the changelog file add thoses lines at the beginning:

mongodb (3.0.6) unstable; urgency=low

  * Rebuild debian package for Jessie

 -- Aurelien Beaujean <> Thu, 08 Oct 2015 12:02:36 +0200

Then you are ready to build MongoDB by running the command “dpkg-buildpackage -rfakeroot” in the mongodb-src-r3.0.6 directory. It takes a while, for me it took about 15 minutes. And if everything gone good, you shoud get .deb files in the upper directory to give to install to dpkg.

Feel free to comment on this article if you solved some issues I didn’t had while building.

Happy new year from Logstash & syslog

Once you’re running syslog-ng | logstash | elasticsearch for to archive all the syslogs from your servers, there is probably something you didn’t noticed: syslog don’t care about year.

So when 2015 coming, Logstash don’t know about it and push into elasticsearch the year of it’s last starts. So your January 2015 syslogs coming to January 2014 ones…

How I fixed it ? I’ve restarted logstash when I understood the problem, but it was somehow too late.

Some solution is explained here: but you need some more code to handle the year move and using @timestamp don’t allow you to replay piece of logs when you need…

Elasticsearch is in red status ?

Your elasticsearch don’t want to accept connexions or queries anymore after a restart or a “Java heap” memory problem ?

# curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
"cluster_name" : "elasticsearch",
"status" : "red",

You will need to check if one the of indexes is “red” status by requesting the indices list. The command is:

# curl 'localhost:9200/_cat/indices?v'
health status index                pri rep docs.count docs.deleted store.size
red    open   my_index-2014.07.21   3   1   10107061            0      1.7gb          1.7gb
yellow open   my_index-2014.07.22   3   1    6728769            0      1.1gb          1.1gb

What is not said in Elasticsearch documentation is that you will need to delete the datas of the index that is in “red” status to be able to restart elasticsearch. I didn’t find any tool to repair indexes… So datas are losts. You was putting them in the cloud, they gone to space…

That experience made me want to move to another noSQL database… To Be Continued :)