Wednesday, December 14, 2011

Cassandra OpsCenter Community features

played with the Ops several hours, here are the major feature In my option.

Monitoring the whole cluster status, like req/s, disk capacity, IO

Node tool visualization and do maintenance job just a click away. Such as, drain one node, compact, or get one node out of cluster(decommission.), rebalance cluster is only available in enterprise version sadly.

Clicking the Node, you can do a lot stuff, such as view the multi-DC replications.


Data modeling and explor( create keyspace , and view data), update column family.

Exploring data,

Monitoring again,

Actions on node, (like the node tool)


Cassandra Opscenter, connected to the cluster, But No Node information get listed

configration is pretty simple for opscenter, just change files under conf fodler, point to correct seed server, then I can query the data from Opscenter now.

How ever, the dashboard, there is no node information.
When I check the logs under opscenter , when it try to get node infrmation from the thift API, get error, that explains why, return no results.

After did a lot testing, I noticed this is because of the version mismatch, for Cassandra cluster, it runs on 1.0 version.

while the ops center version is 1.3.1, you can tell from the console on the left bottom

then I try update the Cassandra to the latest version 1.0.5, it works without any problem.

Cassandra OpsCenter,Failed to load application:

Unzip the OpsCenter file, Instal the 2.7 Python, then run the opscenter, failed get the following error.

[root@e3 opscenter]# bin/opscenter
Traceback (most recent call last):
File "/usr/lib/cassandra/opscenter-1.3.1/lib/py-redhat/2.6/shared/amd64/twisted/application/", line 631, in run
File "/usr/lib/cassandra/opscenter-1.3.1/lib/py-redhat/2.6/shared/amd64/twisted/scripts/", line 23, in runApp
File "/usr/lib/cassandra/opscenter-1.3.1/lib/py-redhat/2.6/shared/amd64/twisted/application/", line 374, in run
self.application = self.createOrGetApplication()
File "/usr/lib/cassandra/opscenter-1.3.1/lib/py-redhat/2.6/shared/amd64/twisted/application/", line 439, in createOrGetApplication
application = getApplication(self.config, passphrase)
--- <exception caught here> ---
File "/usr/lib/cassandra/opscenter-1.3.1/lib/py-redhat/2.6/shared/amd64/twisted/application/", line 450, in getApplication
application = service.loadApplication(filename, style, passphrase)
File "/usr/lib/cassandra/opscenter-1.3.1/lib/py-redhat/2.6/shared/amd64/twisted/application/", line 400, in loadApplication
application = sob.loadValueFromFile(filename, 'application', passphrase)
File "/usr/lib/cassandra/opscenter-1.3.1/lib/py-redhat/2.6/shared/amd64/twisted/persisted/", line 210, in loadValueFromFile
exec fileObj in d, d
File "bin/", line 1, in <module>
from opscenterd import opscenterd_tap
File "build/lib/python2.7/site-packages/opscenterd/", line 16, in <module>

File "build/lib/python2.7/site-packages/opscenterd/", line 392, in init_config

File "build/lib/python2.7/site-packages/opscenterd/events/plugins/", line 12, in <module>

File "build/lib/python2.7/site-packages/opscenterd/", line 17, in <module>

File "build/lib/python2.7/site-packages/opscenterd/", line 14, in <module>

File "build/lib/python2.7/site-packages/opscenterd/", line 23, in <module>

File "build/lib/python2.7/site-packages/opscenterd/", line 10, in <module>

File "/usr/lib/cassandra/opscenter-1.3.1/lib/py-redhat/2.6/5/amd64/OpenSSL/", line 11, in <module>
import rand, crypto, SSL, tsafe
exceptions.ImportError: cannot open shared object file: No such file or directory

Failed to load application: cannot open shared object file: No such file or directory

When I list the LibPython module under /usr/lib64/libpython* , It only has the 2.4 modue. So we need to install the 2.6 Module required by the opscenter.

1, first, Check my OS, it ‘s Centos 5


go to, download the epel-release-5-4.noarch.rpm 

2. Update the rpm, “rpm -Uvh epel-release*rpm”

3. yum install python26-libs


Once done, you can see the 2.6 modules under the lib folder,

Now we can run the opscenter now.

Tuesday, December 6, 2011

How to: write a key mapper or Key transformation utility in 10 minutes

Question, need a utility to map or transform the key stoke, say when you press F6, replace the contents with a Mailing address, and Press F7 for the zip code of your city.

  Answer, In C#, it’s easy and not easy. you have to wrap several Native APIs to hook the mapping point into the system, Easy one is it has one Great methods called Sendkeys.Send.

So eventually, we need one file to keep the mapping logic , here I just pickup the .config file, then the code. Code is here,you may just copy and save it as .cs file, then compile it.

using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections.Specialized;

public class KeyMapper
    private const int WH_KEYBOARD_LL = 13;
    private const int WM_KEYDOWN = 0x0100;

    private static LowLevelKeyboardProc _proc = HookCallback;
    private static IntPtr _hookID = IntPtr.Zero;
    private static NameValueCollection mappings;
    public static void Main()
        //Check to see no duplicate running
        //keep it small

        mappings = System.Configuration.ConfigurationManager.AppSettings;

        _hookID = SetHook(_proc);

    private static IntPtr SetHook(LowLevelKeyboardProc proc)
        using (Process curProcess = Process.GetCurrentProcess())
        using (ProcessModule curModule = curProcess.MainModule)
            return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
                GetModuleHandle(curModule.ModuleName), 0);

    private delegate IntPtr LowLevelKeyboardProc(
        int nCode, IntPtr wParam, IntPtr lParam);

    private static IntPtr HookCallback(
        int nCode, IntPtr wParam, IntPtr lParam)
        if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
            int vkCode = Marshal.ReadInt32(lParam);
            String key = ((Keys)vkCode).ToString();

            if (mappings[key] != null)
        return CallNextHookEx(_hookID, nCode, wParam, lParam);


    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr SetWindowsHookEx(int idHook,
        LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool UnhookWindowsHookEx(IntPtr hhk);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
        IntPtr wParam, IntPtr lParam);

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr GetModuleHandle(string lpModuleName);

Config  file, like mine,

Then we you started the console application.
wherever you enter F6, it will put a sample address there.

If you can’t compile the code , leave a comment , I will email you the compiled bits.

Locations of visitors to this page