Total Pageviews

Sunday, 22 February 2015

Elasticsearch Official Twitter Page Analytics With Kibana4




Lots of things happening at ELK stack these days and finally we got one of the most awaiting release from elasticsearch.. Yes i am talking about Kibana 4.

I have been using Kibana for more than a year, and thought to give a try to the new kibana and trust me, Rashid Khan has baked it with so many ingredients, It will take you to a whole new world. ;)

There is no pain anymore to run kibana in any web server, It now ships with its own webserver and uses Node.js on the backend—installation binaries are provided for Linux, Windows, and Mac OS.

There are so many unbelievable feature which you can take a look at here: What's New in Kibana 4

Just to let you know kibana 4 works only with elasticsearch latest version i.e. 1.4.4 and not below of that. So be ready to upgrade your cluster. :D :D

I thought to do a unique kind of analytics with Kibana 4 and what could be more unique than doing analytics of elasticsearch twitter account. I downloaded the latest version of elasticsearch (Elasticsearch 1.4.4) and kibana 4  and then wrote few line of Java code using Twitter4J to fetch all the tweets of @elasticsearch Twitter Page and then started exploring Kibana 4 features and graphs to build some awesome dashboards. I hope these graphs gonna bring some smile on the face of elasticsearch people. :)

So the first analysis i did is :
Finding how many tweets have been done on Elasticsearch Page? 
Finding how many tweets Elasticsearch have Retweeted out of the total tweets on it's page? 
Finding how many replies elasticsearch have done so far?

The result was bit surprising.. And here is what i got..


The next things i was curious to find out tweet trends per month in last 5 years on elasticsearch page and it definitely shows the efforts elasticsearch is making through its twitter account:




















Now below visualisation gonna blow your mind :D It is an area chart with following description:




So, on top of this chart i created a visualization to find out top 10 Hashtags used at elasticsearch page and here goes my findings: (Please note that since i have not applied analyzer on the field, the Hashtags "Elasticsearch" and "elasticsearch" has been aggregated in different buckets)















Using the same Area chart, i created one more visualization to show the tweet density per month on elasticsearch page in last 5 years:














The next graph is even more interesting which shows the top 10 mentioned handles at the elasticsearch page along with their count on the Y-Axis and it goes like this:
1. @elasticsearch 2. @lhawthorn 3. @kimchy 4. @dadoonet 5. @clintongormley
6. @spinscale 7. @jordansissel 8. @bleskes 9. @LivFroe and 10. @ZacharyTong
































Here goes one more finding on a different kind of graph using the nested aggregation feature on kibana 4.
Yearly Retweets By Elasticsearch Page and the Top 5 Hashtags mentioned in Those Tweets





































And the last one shows the screen names of top 10 people to whom @elasticsearch have replied at most, you can find those lucky names in below graph (A donut one ^_^)






































This was just a preview.
Kibana 4 and elasticsearch version 1.4.4 has brought so much for you. Get it a try while they are hot and start exploring it. :):)

So this was my little effort to give some analytics back to the most powerful search engine of the world on it's own data. I hope the @elasticsearch will increase it's interaction on it's social media channels even more. :)

Comments are welcome. And if you like it then share it through your favourite social media channel..!!




Friday, 3 May 2013

Maintaining Session in Swing Applications

One of the main reason behind writing this post is to help others because i found that lots of people have same query but they don't get the solution. So, i hope this post will be useful for those people.

If you are working with the web applications, then its easy to maintain sessions and accordingly authenticate the users for the contents they can access in the application.

But achieving the same result is different from the web applications. I needed the same thing in the current project i am working on. Like after login to the system, based on username i had to give different rights for the user to access the contents.

For example if the username is "Admin" then he can have all the rights like adding, deleting, modifying and so on.., but if the username is "Bharvi" then he can only view the particular contents.

For achieving the desired result, one has to know about System class in java. The System class can't be instantiated but it provides several useful static methods.

Now coming straight to the code snippet i have implemented.

public class Login_Controller implements ActionListener {

    Login_Frame frame;
    Login_Bean bean;

    public Login_Controller(Login_Frame frame, Login_Bean bean)
    {
        this.frame= frame;
        this.bean = bean;
    }
    @Override
    public void actionPerformed(ActionEvent event) {

        if(event.getSource()==frame.btnSubmit)
        {  
            boolean result = false;
            bean = new Login_Bean();
            String username= frame.textfield_username.getText().toString();
            String password= frame.passwordField_Password.getText().toString();
            bean.setUsername(username);
            bean.setPassword(password);
            System.setProperty("id", username);//This is only thing i needed for my purpose. :)
            Login_DAO dao = new Login_DAO();//Class where all the database related things are kept

             result = dao.authenticate(bean); //the authenticate method calls the query for login authentication
            if(result)
            {  
               //Set the action you want to perform such as opening home interface
            }
            else{
                JOptionPane.showMessageDialog(frame.frame, "Invalid Username or Password");
            }
        }
    }
}


The setProperty method of the system calss takes a key-value pair as its parameter.
in the above example the key is "id" which is the name we are setting as the system property.
Once this property is set we can access it from anywhere in the application using System.getProperty(key) method.

For example if username is "Admin" the only i want to give the user access to delete a record in application. Then i can achieve it as:

 public void actionPerformed(ActionEvent e)
{
      if(e.getSource==anyframe.button_delete_record)
      {
         if(System.getProperty("id").equals("Admin"))
         {
              //perform the deletion task
         }
        else{
                  JOptionPane.showMessageDialog(anyframe.frame,"You don't have permission to delete records");
      }
      }
}

Another option is to store it (i.e. Username) in a hash map or value object and setting that object in the same way as above.