Tuesday, 31 May 2016

Real time data without polling (Remove polling)

Now a days it's become a good , useful and necessary technique to view live data. It's look cool when you see any change in your system on front end with in no time. The first technique comes in mind to solve this problem is  Polling.

Polling is basically a simple technique to get real time data. In polling you simply call your server or system continuously after a fixed interval of time. Through polling we get real time data with out installing any agent in system, but their is some cons about polling. One of the biggest problem with polling is that it increase over head on server. Due to which it assume that polling is not a good technique to resolve real time data problem. And if there is no change on server or data our program still continuously make request on server.

Some thing we want is to get real time data from server without requesting server. Nothing is impossible in programming. Every problem has a solution in this field. So, their is some more techniques to use to get real time data without polling.

There are 3 solutions to remove polling

  • Long polling
  • Server sent events
  • Web sockets

To overcome deficiency in polling techniques, developers move to long polling. In long polling client send request to server and server holds the request until their is any change on server about what client requested, in this way we resolve one issue that client not request again and again if their is no change on server. But still it is the same as polling that increase overhead on server.

So the next and one of the best available techniques in server sent events, In SSE server notify the client side that "Hi! there is some change on me". So no need for client to continuously check or call server. But client and server check a keep alive call to check if they connected or not. So it is a better solution to get real time data without polling.

But wait What if need to send some data from client to server like in chat applications? SSE in unidirectional. But their is another solution called Web sockets. Web sockets are bidirectional. They work similar to SSE but also allow client to send data to server. So information send to client from server when their is any change. Web sockets are mainly use in chat applications because their we need bidirectional traffic.

Friday, 27 May 2016

Collectd Python Plugin (Complete guide)

16:03 Posted by SRE Hacks , No comments
Collectd is a UNIX daemon that collects system metrics. In newer version of Collectd python custom plugin support is added. Now you can write your own custom python plugin.

First you change your collectd.conf file in ubuntu located at /etc/collectd/collectd.conf
uncomment these lines

<LoadPlugin python>
        Globals true
</LoadPlugin>

Next uncomment these lines


<Plugin python>
        ModulePath "path to module"
        Import "file name"
        <Module file name>
                Test "This"
        </Module>
</Plugin>


Then add your python plugin file path to path to module and give your file name in import.
Then just write your python plugin
 There are some main function you have to call in your python file to work with Collectd.
Example of python code:

import collectd

def configer(confObj):
    collectd.info('config called')


def init_fun():
    collectd.info('my py module init called')


def reader(input_data=None):
    collectd.info('reader called')
 
collectd.register_config(configer)
collectd.register_init(init_fun)
collectd.register_read(reader)

You see what ever string you give in collectd.info() in logs of Collectd

If you want to write data in rrd format you have to use Collectd built in functions

Here is an example how to write data in rrd format

def reader(input_data=None):
    metric = collectd.Values()
    metric.plugin = "Plugin Name"
    metric.host = "localhost"
    metric.interval = 10    //Time interval after which data saved
     metric.type = "Type of data"   //folder generate in rrd/hostname folder get this name
    metric.values = [value]    //value to write in rrd file
    metric.dispatch()    //in last use this method to dispatch and write you current entry in rrd file

Tuesday, 24 May 2016

Cloud Computing??

23:02 Posted by SRE Hacks 1 comment
Cloud computing is based on pay as you go model. Means you pay what you use. Before cloud computing you buy a server with some specs but if you need to increase any resource of server you do a lot of work (buy resource, integrate in environment etc), but cloud computing do a miracle now you only send an email to cloud providing company or make a call to increase your resources and you will only pay, all the other headache is for cloud providing company. Cloud computing is listed top computer filed in 2015.

In simple cloud computing is "all the processing work is done on remote server rather then on local machine". So, you can focus on project more then the infrastructure and other resources. It has many services. Some of them are listed bellow
IaaS (Infrastructure as a service)
PaaS (Platform as a service)
SaaS (Software as a service) mostly used by almost all types of people. e.g gmail
DaaS (Database as a service)
NaaS (Network as a service)
and many many more

Most commonly we use SaaS i.e email services we use is an example of SaaS. Email service is a software running on remote server.