Programming Posts

A Simple Thousand Separator using Java

Trying to create a quick and simple solution for formatting an Integer into a formatted string with thousand separator,

	class Main
	{
		public static void main (String[] args) throws java.lang.Exception
		{
			String s = (String.format("%,d", 10000000)).replace(",",".");
			System.out.println(s);
		}
	}

The output will be, 10.000.000. (H)

Google+

Simulating Slow Response on Mule ESB

Below is the code im using for simulating a 2minutes reply using MuleESB.

		<expression-component doc:name="Expression"><![CDATA[
			Thread.sleep(120000);
		]]></expression-component>

Thank you

Google+

Changing Couchbase Data Directory Location

Usually Couchbase put its data on default location (/opt/couchbase/var/lib/couchbase/data). But because my disk’s space is full, i have to move Couchbase data to other location. In my case, /data folder which is mounted to an empty 100GB SSD disk. Below is how i change it,

First, i have to change the content of below file,

vi /opt/couchbase/etc/couchdb/default.d/capi.ini 

Changing database_dir and view_index_dir on below Couchbase configuration file, to my new location folder

[couchdb]
max_dbs_open = 10000
database_dir = /data
view_index_dir = /data

[httpd]
db_frontend = capi_frontend
ip4_bind_address = 0.0.0.0
ip6_bind_address = ::
port = 8092

Next is move the content of old folder (/opt/couchbase/var/lib/couchbase/data), to our new folder (/data). And restart our Couchbase service to implement our changes.

  sudo service couchbase-server stop
  sudo service couchbase-server start

We can see the result on our Couchbase web console, hopefully it helps (H)

ps. My Couchbase version is “Enterprise Edition 6.0.0 build 1693”.

Google+

[Python] Fixing Fatal Error when Installing Mysqlclient with Pip

On my current project, im using Python, Django and Pip. But there is some issue when installing libraries needed for running the app,

pip install -r requirements.txt

Below is the error generated when running it,

_mysql.c:29:10: fatal error: 'my_config.h' file not found
   #include "my_config.h"
            ^~~~~~~~~~~~~
   1 error generated.
   error: command 'clang' failed with exit status 1
----------------------------------------
 Rolling back uninstall of mysqlclient

Looks like error happen when trying to install below library,

mysqlclient==1.3.7

Below is Python and Pip version that im using,

 
$ python --version
Python 3.4.3
$ pip -V
pip 18.1 from /Users/m/.pyenv/versions/3.4.3/envs/logistic_backend/lib/python3.4/site-packages/pip (python 3.4)

The main culprit is corresponding library is not supported by Python 3.4.3, changing it into below lib fix the error

pymysql==0.9.2
Google+

Go and DataDog Part 1 : Simple Go HTTP Monitoring with DataDog

Today im trying to share a simple GoLang HTTP monitoring using DataDog APM. On this example im using trial version of DataDog for testing purpose, but on production im using enterprise version. Shouldnt be so much difference between those two.

Okay, after we register on DataDog website, we can start with installing DataDog agent on our server.

https://app.datadoghq.com/account/settings#agent

Im using Ubuntu Server, so my installation command is like below,

DD_API_KEY=<your datadog api key> bash -c "$(curl -L https://raw.githubusercontent.com/DataDog/datadog-agent/master/cmd/agent/install_script.sh)"

After our installation runs well, we need to configure APM first

vi /etc/datadog-agent/datadog.yaml

with below configuration,

apm_config:
   enabled: true

we can start our Datadog-agent using below command,

sudo datadog-agent start

and check its status using

sudo datadog-agent status

Next is writing our code, im using Go’s simple htttp package

package main

import (
    "fmt"
    "log"
    "net/http"
    "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
    httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http" // In order to instrument the http library
)

func main() {
     tracer.Start(tracer.WithDebugMode(true))
     defer tracer.Stop()
     mux := httptrace.NewServeMux() // init the http tracer
     mux.HandleFunc("/", handle) // use the tracer to handle the urls     
     log.Println("Listening on port 8099")	 
     log.Fatal(http.ListenAndServe(":8099", mux)) // use the tracer to start the http server
}

func handle(w http.ResponseWriter, r *http.Request) {     
     fmt.Fprint(w, "Hello world!")
}

we can simulate http request to our server with a simple command,

curl -v http://127.0.0.1:8099/

We can see the result on our Datadog dashboard below,

and the detailed view for each url,

Hopefully it helps :-D

Google+