Information Technology, Linux, Tips and Tricks

Linux: Monitor CPU / Disk with iostat , mountstats, nfstats

iostat – Report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions

>iostat 5
avg-cpu: %user %nice %system %iowait %steal %idle
 5.78 0.00 1.88 0.31 0.00 92.03

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sdb 1.26 68.00 32.90 105270469 50926556
sda 1.39 43.58 12.47 67460402 19299785
dm-0 1.94 40.91 7.21 63322457 11161776
dm-1 1.98 2.67 5.25 4128376 8121048
dm-2 2.22 68.00 32.90 105268573 50926556

 

mountstats – Displays various NFS client per-mount statistics

> mountstats iostat /mount_point 5

NFS:/location mounted on /mount_point:

ops/s rpc bklog
 13.615 0.000

read: ops/s kB/s kB/op retrans avg RTT (ms) avg exe (ms)
 5.474 45.247 8.266 11701 (0.1%) 11.996 14.131
write: ops/s kB/s kB/op retrans avg RTT (ms) avg exe (ms)
 4.505 39.113 8.682 460703 (6.6%) 201.364 5441.623

 

nfstats – list NFS statistics

> nfsstat
Server rpc stats:
calls badcalls badclnt badauth xdrcall
0 0 0 0 0

Client rpc stats:
calls retrans authrefrsh
24265079 347644 24265126

Client nfs v3:
null getattr setattr lookup access readlink
0 0% 133828 0% 1204 0% 2083 0% 24992 0% 4 0%
read write create mkdir symlink mknod
8474389 34% 6977161 28% 1203 0% 18 0% 0 0% 0 0%
remove rmdir rename link readdir readdirplus
447 0% 0 0% 3 0% 0 0% 29 0% 1254 0%
fsstat fsinfo pathconf commit
8648025 35% 10 0% 5 0% 424 0%
Advertisements
Interview Questions, Tips and Tricks, Tutorial

Singleton in Java

What is Singleton?

Singleton is a class that cannot have more than one instance.
(Source: https://en.wikipedia.org/wiki/Singleton_pattern)

In Java, there are many way to create singleton class, one of the example is:

class SingletonClass {

    private static volatile SingletonClass INSTANCE = null;

    private SingletonClass() {   }

    public SingletonClass getInstance() {
         if (INSTANCE == null) {
            synchronized (SingletonClass.class) {
                 if (INSTANCE == null) {
                    INSTANCE = new SingletonClass();
                 }
            }
         }
         return INSTANCE;
    } 
}

When to use singleton?

Singleton is used when you need system wide “global value” that need to be accessed by many part of systems. Example: Session Value, Logger, Cache, etc

Information Technology, Tips and Tricks

Change JSESSIONID in URL parameter

Having problem with JSESSIONID in URL ?

Well, this is not a bug. When the server received a request from client, it is not sure whether the client support cookie or not. So, it generate both of them in the URL. When it comes back for second time, and the server detects the cookie is present, it will drop JSESSIONID from URL automatically. However, when the cookie is not present, the server will continue to use it.

Having JSESSIONID in URL actually is not bad at all, however it has a few drawbacks:

  • Security Risk

By exposing SESSIONID in the URL, it allows attacker to attack victim and steal some information store in the session

  • SEO

Because SESSIONID is unique, search engine both may not recognise different pages that having unique SESSIONID.

How to solve this?

There are few ways to avoid JSESSIONID in URL

  1. Implementing Servlet Filter which will disable/skip URL based on SESSION ID generation.
  2. Since Servlet 3.0, we can use SessionTrackingMode Enumeration to specify how SessionTracking should be.
    So, in web.xml we just need to add the following:
<session-config>
    <tracking-mode>COOKIE</tracking-mode>
<session-config>

 

So, who said it is difficult and complicated? Happy coding 🙂

Articles, News Around The World

Facebook, Twitter, YouTube and Microsoft agree to remove hate speech across the EU — TechCrunch

Facebook, Twitter, Google’s YouTube, Microsoft as well as the European Commission unveiled a new code of conduct to remove hate speech in less than 24 hours across these social media platforms. The EU has ramped up efforts leading to this code of conduct following the recent terrorist attacks in Brussels and Paris. Read More

via Facebook, Twitter, YouTube and Microsoft agree to remove hate speech across the EU — TechCrunch

Information Technology, Tutorial

Testing an API

Some consideration in defining testing scope for an API:

  1. Output value based on input parameter
  2. Output value based on incorrect/missing parameter
  3. API behaviour when there is no output or expected to return nothing
  4. Whether API trigger another event/process
  5. Whether API modifying certain resources 

Scenario 1: Output Value based on Input Parameter

This test scenario will test API functionalities based on API Specifications. Example: function add(int x, int y). We can test that API by passing any int value, then validate the return value.

Scenario 2: Output Value based on Incorrect/Missing Parameter

This test scenario will test API functionalities by passing incorrect/missing parameters against API Specifications. Example function add(int x, int y). We can test that API by passing x value only, or passing x value as double, then validate the behaviour of an API (eg: will it return an error message?)

Scenario 3: API behaviour when there is no output or expected to return nothing

This test scenario will test API functionalities boundary. One of the boundary need to consider is no output expected. Example, function search(String keyword). We can test that function with non-existence keyword, then observe API return value (eg: return empty result, etc).

Scenario 4: Whether API trigger another event/process

This test scenario will test API functionalities that will trigger another event/process. Example: function backup() to execute backup shell script on server. We can test that API, and then validate whether backup script are executed after API call.

Scenario 5: Whether API modifying certain resources

This test scenario will test API functionalities that modifying certain resources (eg: creating new file, deleting file, updating file. Example: function export(Date startDate, Date endDate) will export data for certain period in CSV.  We can test that API and validate if intended resource modification (eg: CSV file is produced) successfully executed.

Beside these 5 factors, there are many other factor that’s good to be consider:

  1. API performance
    • To check API performance during high load to the API Server.
  2. Output / Response
    • To check how application behaviour when the output/response from API does not according the specifications (unstructured data), etc

 

 

Apps Reviews, My Comments

MessageMe App: The Good and Bad

MessageMe is a new mobile free messaging app. It comes with a lot of visual features and personalization. Through MessageMe app, people are able to send SMS text messages and make voice calls to their friends for free using WiFi and the phone’s data plan.

Sounds good, isn’t it? But wait … there are a lot of rumor going around that say when you receive an SMS from MessageMe, and you click the link, the same SMS will be sent out to ALL your contacts stored in your mobile phone.

WOW ….. what does it means?

Imagine if you have over 1000 contacts in your mobile phone …. it means over 1000 SMS will be sent from your mobile phone to all your contact … at the end you may incurred HUGE phone bill to pay those SMS … so be careful before clicking to any link

Also, a lot of people complaining that they are receiving a call from +375602605281, +37127913091 or any number starting with a +375, or +371 number. So please, don’t answer or call back, or you will be charged of International call, which most likely will be very costly.

A lot of rumor over the internet said that, if you call back, they will be able to steal your information store in your phone, but I believe this is an HOAX (See this: http://www.hoax-slayer.com/missed-375-calls.shtml)

Finally, it is up to you to decide … you also can review other people comment on iTunes here: https://itunes.apple.com/sg/app/messageme/id562075622?mt=8

Big Data, Information Technology, Tips and Tricks

Install MongoDB on CentOS 6.4

MongoDB can be easily to be installed on CentOS 6.4 (64 bits) with with the following 2 steps:

  1. Add/Create 10 gen repo into the system#> vi /etc/yum.repos.d/10gen.repo

    [10gen]
    name=10gen Repository
    baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
    gpgcheck=0
    enabled=1

  2. Install Packages#> yum install mongo-10gen mongo-10gen-server

Note: You may need to be root to do the installation.

Once the download complete, your MongoDB is ready to be used. You can start/stop MongoDB instance with the following command:

# >  service mongod start
# >  service mongod stop

and, to restart

# > service mongod start

You may want to let the MongoDB auto start when the system up, with the following command:

#> chkconfig mongod on

Now, your MongoDB is installed and ready to use. You can start to using MongoDB shell, with the following command:

# > mongo

Happy trying and using with it.