My first git push :)

Standard

Finally managed my first git push. Phew!!! Although the work is not complete but still I am happy that I could present atleast something out of nothing and with not-so-much knowledge about python.
So what i did for my first open source project is that I made an application, a System-Monitor that would monitor the CPU, RAM and DISK usage and plot dynamic graphs accordingly.
Of course I used dependencies. I used psutil to extract the data, matplotlib to plot the dynamic graphs and gtk to create my own window (Currently the gtk feature is not available. I am using matplotlib window until I learn to use gtk).
So, as Kushal Das, my mentor, instructed me to create a file data.py to extract the info, I did so using psutil.
Next, there is the main.py which plots the graphs using matplotlib and displays them in a matplotlib window.
The work is not complete yet. I still need to write setup.py to make a command to run the program directly from the terminal. Will update when things are done.
This is the link to the git repository: https://github.com/desouradeep/System-Monitor
I have also included some screenshots, hope you like them. 😀
I would also like to thank Sayan Chowdhury for helping me out. 🙂

THE CODE :

1. data.py

import psutil
def cpu():
    '''This method returns the current CPU usage'''
    a=psutil.cpu_percent(interval =0.1, percpu=False)
    return "%4.2f" %a
def mem():
    '''This method returns the current RAM usage'''
    a=psutil.phymem_usage().percent
    return "%2.2f" %a
def dsk():
    '''This method returns the current DISK usage'''
    a=psutil.disk_partitions()
    b=[]
    x=0
    y=0
    for i in range (0,len(a)):
        b.append(a[i][1])
        x+=psutil.disk_usage(b[i])[0]
        y+=psutil.disk_usage(b[i])[1]
        z=float(y)/float(x)*100
    return "%2.2f" %z

2.main.py

#!/usr/bin/env python
import matplotlib.pyplot as plt
import matplotlib
import data
c=[]
m=[]
d=[]

def main():
    print 'NO.	CPU	MEMORY	DISK'
    plt.subplot(211)
    i=0
    while True:
        i+=1
        plt.ylim(0,100)
        plt.xlim(0,60)
        cc=data.cpu()
        mm=data.mem()
        dd=data.dsk()
        print i,'\t',cc,'\t',mm,'\t',dd
        c.append(cc)
        m.append(mm)
        d.append(dd)
        plt.grid(True)
        plt.xlabel('TIME')
        plt.ylabel('USAGE IN %')

        plt.title(' - - SYSTEM MONITOR - - ')
        ds='DISK ('+dd+'%)'
        ms='RAM  ('+mm+'%)'
        cs='CPU  ('+cc+'%)'
        plt.plot(d[-60:-1],'g', label=ds)
        plt.plot(m[-60:-1],'r', label=ms)
        plt.plot(c[-60:-1],'b', label=cs)
        plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.06,0,0.04), ncol=3)
        if len(c)>60:
	        del c[0]
	        del m[0]
	        del d[0]
        plt.draw()
        matplotlib.interactive(True)
        plt.show()
        plt.clf()

main()

Here are some of the screenshots:

This slideshow requires JavaScript.

Advertisements

2 thoughts on “My first git push :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s