Wednesday, 8 June 2016

Libvirt objects state

10:48 Posted by SRE Hacks No comments
Libvirt

libvirt is an open source API, daemon and management tool for managing platform virtualization. It can be used to manage KVM, Xen, VMware ESX, QEMU and other virtualization technologies. These APIs are widely used in the orchestration layer of hypervisors in the development of a cloud-based solution.

To avoid ambiguity about the terms used, here are the definitions for some of the specific concepts used in libvirt documentation:
  • a node is a single physical machine
  • an hypervisor is a layer of software allowing to virtualize a node in a set of virtual machines with possibly different configurations than the node itself
  • a domain is an instance of an operating system (or subsystem in the case of container virtualization) running on a virtualized machine provided by the hypervisor
Libvirt distinguishes between two different types of domains: transient and persistent.
  • Transient domains only exist until the domain is shutdown or when the host server is restarted.
  • Persistent domains last indefinitely.


Libvirt States

There are five states of Instance (virtual machine) in libvirt. They are as following

  • Undefined
  • Defined
  • Runing
  • Paused
  • Saved

  • Undefined - This is a baseline state. Libvirt does not know anything about domains in this state because the domain hasn't been defined or created yet.
  • Defined or Stopped - The domain has been defined, but it's not running. This state is also called stopped. Only persistent domains can be in this state. When a transient domain is stopped or shut down, it ceases to exist.
  • Running - The domain has been created and started either as transient or persistent domain. Either domain in this state is being actively executed on the node's hypervisor.
  • Paused - The domain execution on hypervisor has been suspended. Its state has been temporarily stored until it is resumed. The domain does not have any knowledge whether it was paused or not. If you are familiar with processes in operating systems, this is the similar.
  • Saved - Similar to the paused state, but the domain state is stored to persistent storage. Again, the domain in this state can be restored and it does not notice that any time has passed.

Thursday, 2 June 2016

Libvirt and event based vm states

Now a days virtualization is one of the most common and fastest growing field in computer science. Basically now world move from physical and costly hardware to software based. Like if we need new machine we go to market and buy the new one, but virtualization made it easy, now we only spawn new machine with just few clicks.

So their is need for some tool to manage virtualization, Libvirt is an opensource daemon used for managing virtualization. It can manage many virtualization technologies like KVM, XEN, VMWARE ESX, QEMU.

Livirt has many use cases. I worked on a use case to detect change in vm states on event bases.
Open stack on back end use libvirt for virtualization. What if we want to detect any change in virtual machine states??? First method is you continuously check your vm by using ssh and polling, but it's bad approach. Libvirt allows you to detect vm current state. Libvirt developers writes a python plugin that detect any change in vm state and show it to you, without polling and any other over head on server. You can get agent from here. It is opensource, so you can modify it as you can.

Libvirt has 5 states for any vm


  • Undefined
  • Defined
  • Runing
  • Paused
  • Saved

The agent get state from libvirt whenever any of these event occurred and show details. Agent register itself in libvirt and get state on every event change. The agent show many details some of them are
  • Name of instance (openstack name, created by openstack)
  • UUID of instance
  • Event name
    • Defined,
    • Undefined
    • Started
    • Suspended
    • Resumed
    • Stopped
    • Shutdown

  • Event Detail (Detail of event to clarify action)
    • Added
    • Updated
    • Removed
    • Booted
    • Migrated
    • Restored
    • Snapshot
    • Wakeup
    • Paused
    • Migrated
    • IOError
    • Watchdog
    • Restored
    • Snapshot
    • Unpaused
    • Migrated
    • Snapshot
    • Shutdown
    • Destroyed
    • Crashed
    • Migrated
    • Saved
    • Failed
    • Snapshot
    • Finished

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.