<commit_before>#!/usr/bin/python

import time
import subprocess
import pickle
import sys,os
#==============================================================================
# Variables
#==============================================================================

# Some descriptive variables
# This will eventually be passed to the setup function, but we already need them
# for doing some other stuff so we have to declare them here.
#name                = "vmplacementandscaling"
#version             = "0.1"
#long_description    = """vmplacementandscaling is a set of API's/tools written to create virtual machines for cloud users efficiently."""
#url                 = "https://github.com/dineshappavoo/VMPlacementAndScaling"
#license             = ""

#==============================================================================

def slicingIP(data, key):
        dataLen = len(data)
        for x in range(dataLen):
                #print 'data:' +data[x]+' key:'+key
                if data[x]==key:
                        lengthCut=x
                        data=data[:lengthCut]
        return data

def slicingUsage(data, key):
        dataLen = len(data) -1
        for x in range(dataLen):
                #print 'data:' +data[x]+' key:'+key
                if data[x]==key:
                        lengthCut=x
                        data=data[:lengthCut]
        return data

def getCpuUsage(vmIp):

        #check type of return
        cmd='ssh -q -o StrictHostKeyChecking=no root@'+vmIp+' uptime | awk \'{print $4}\''
        check=subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)

        #cmd='uptime | grep -ohe \'load average[s:][: ].*\' | awk \'{ print $3 }\''
        cmd = 'ssh -q -o StrictHostKeyChecking=no root@' +vmIp+ ' cat /proc/loadavg | awk \'{print $1}\''
        cpuUsage = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)
        cpuUsage = slicingUsage(cpuUsage, ',')

        return cpuUsage.strip()


def getOSMemUsage(vmIp):
        cmd='ssh -q -o StrictHostKeyChecking=no root@' +vmIp+ ' free -m | grep \'+\' | awk \'{print $3}\''
        memUsage = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)
        #memUsage = slicingUsage(memUsage , '\n') #not working. future work
        #memlen = len(memUsage )
        #memUsage = memUsage[:memlen-1]

        return memUsage.strip()

def getTaskMemUsage(vmIp):
	cmd = 'ssh -q -o StrictHostKeyChecking=no root@' +vmIp+\
	" cat /proc/`cat /root/memory.pid`/status | grep VmSize | awk '{print $2}'"
	memUsage = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)
	
	return memUsage if memUsage.strip() != '' else 0

def getIoUsage(vmIp):

	cmd='ssh -q -o StrictHostKeyChecking=no root@' +vmIp+ ' iostat -d -x 1 2 | grep [a-z]da | tail -1 | awk \'{print $(NF)}\''
	#cmd='ssh root@' +vmIp+ ' free -m | grep \'+\' | awk \'{print $3}\''
	ioUsage = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)
	#memUsage = slicingUsage(ioUsage , '\n') #not working. future work
	#iolen = len(ioUsage )
	#ioUsage = ioUsage[:iolen - 1]

	return ioUsage.strip()<commit_msg>Update VM_Monitor_Utility.py<commit_after>#!/usr/bin/python

import time
import subprocess
import pickle
import sys,os
#==============================================================================
# Variables
#==============================================================================

# Some descriptive variables
# This will eventually be passed to the setup function, but we already need them
# for doing some other stuff so we have to declare them here.
#name                = "vmplacementandscaling"
#version             = "0.1"
#long_description    = """vmplacementandscaling is a set of API's/tools written to create virtual machines for cloud users efficiently."""
#url                 = "https://github.com/dineshappavoo/VMPlacementAndScaling"
#license             = ""

#==============================================================================

def slicingIP(data, key):
        dataLen = len(data)
        for x in range(dataLen):
                #print 'data:' +data[x]+' key:'+key
                if data[x]==key:
                        lengthCut=x
                        data=data[:lengthCut]
        return data

#def slicingUsage(data, key):
#        dataLen = len(data) -1
#        for x in range(dataLen):
#                #print 'data:' +data[x]+' key:'+key
#                if data[x]==key:
#                        lengthCut=x
#                        data=data[:lengthCut]
#        return data

def getCpuUsage(vmIp):

        cmd = 'ssh -q -o StrictHostKeyChecking=no root@' +vmIp+ ' cat /proc/loadavg | awk \'{print $1}\''
        cpuUsage = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)

        return cpuUsage.strip()


def getOSMemUsage(vmIp):
        cmd='ssh -q -o StrictHostKeyChecking=no root@' +vmIp+ ' free -m | grep \'+\' | awk \'{print $3}\''
        memUsage = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)
        #memUsage = slicingUsage(memUsage , '\n') #not working. future work
        #memlen = len(memUsage )
        #memUsage = memUsage[:memlen-1]

        return memUsage.strip()

def getTaskMemUsage(vmIp):
	cmd = 'ssh -q -o StrictHostKeyChecking=no root@' +vmIp+\
	" cat /proc/`cat /root/memory.pid`/status | grep VmSize | awk '{print $2}'"
	memUsage = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)
	
	return memUsage if memUsage.strip() != '' else 0

def getIoUsage(vmIp):

	cmd='ssh -q -o StrictHostKeyChecking=no root@' +vmIp+ ' iostat -d -x 1 2 | grep [a-z]da | tail -1 | awk \'{print $(NF)}\''
	#cmd='ssh root@' +vmIp+ ' free -m | grep \'+\' | awk \'{print $3}\''
	ioUsage = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE)
	#memUsage = slicingUsage(ioUsage , '\n') #not working. future work
	#iolen = len(ioUsage )
	#ioUsage = ioUsage[:iolen - 1]

	return ioUsage.strip()
{'fraction_non_alphanumeric': 0.20815776167200403, 'fraction_numerical': 0.004719366256531266, 'mean_word_length': 2.9402390438247012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '924727', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1792, 'n_words': 478}