Get Daily CPU statistics in your mail

Thanks to the previous post (http://lucd.info/?p=1455) and a little extra scripting, i am able to run a script which will run daily scheduled and email the results to my mailbox.

This script will mail a CSV file with all cpu averages in 5 minutes samples between 7.30 and 19:30 off a specific Virtual machine.

If other counters are needed, you can find them in the following document: http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/visdk25programmingguide.pdf

Beneath is the script i’m using (change all bold items):

Add-PSSnapin VMware.VimAutomation.Core

# Mail variables
$enablemail="yes"
$smtpServer = "smtpserver"
$mailfrom = "emailadres"
$mailto = "emailadres1,emailadres2"

# Server Variables
$VIServer = "viserver"
$vmName = "vmname"

# Log File Location
$log = "path\CPU_Stats" + "_" + $VMname+ ".csv"

# Connect to the VI Server
Connect-VIServer $VIServer

# Script
$esxImpl = Get-VM -Name $vmName
$todayMidnight = (Get-Date -Hour 0 -Minute 0 -Second 0).AddMinutes(-1)
$workingDays = "Monday","Tuesday","Wednesday","Thursday","Friday"
$dayStart = New-Object DateTime(1,1,1,7,30,0)     # 07:30 AM
$dayEnd = New-Object DateTime(1,1,1,19,30,0)      # 07:30 PM

$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $todayMidnight.AddDays(-0) -Finish $todayMidnight.AddDays(+1)
$report = $stats | Where-Object {
	$workingDays -contains $_.Timestamp.DayOfWeek -and
	$_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and
	$_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay
}

$report | Export-Csv $log -NoTypeInformation

if ($enablemail -match "yes")
{
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($log)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $mailfrom
$msg.To.Add($mailto)
$msg.Subject = “CPU Statistics $VMname”
$msg.Body = “Business-hours CPU Statistics are attached   ”
$msg.Attachments.Add($att)
$smtp.Send($msg)
}

$VIServer | Disconnect-VIServer -Confirm:$false

Use a USB key to install Windows 7

How to create a bootable USB key from which you can install Windows 7 on your system.

  1. Start diskpart on your machine (Start, run, diskpart)
  2. Then check which disk is your usb key with list disk
  3. Select your USB key with select disk 3 where “3” is your USB key
  4. Run Clean (this will wipe your usb key)
  5. Run  Create partition primary to create a new primary partition
  6. Set the created partition to active with the command Active
  7. Format the partition as a Fat32 file system:  Format fs=fat32 quick
  8. Assign a drive letter to your USB key for easy access from a explorer
  9. Copy the complete contents of the Windows 7 installation disk to you USB key (drag & drop)

Now you have a USB key with an installable windows 7 on it. It will install faster then a DVD and it’s easier to carry it with you. Another advantage is that you can install netbooks without dvd players from the USB key.

Ubuntu Server 9 Commands

Trying to install an Ubuntu Server but i’m not an expert, so here are a few commands to help it setup:

changing proxy config for internet access:

  • export http_proxy=http://<proxy address>:<proxy port>

Getting SSH to work:

  • sudo apt-get install openssh-server

Add new user:

  • sudo adduser <username>

Add user to groups:

  • sudo usermod -a -G <group> <user>

Check group members

  • sudo id <user>

esxcfg-info – VMware ESX Server Info tool

/usr/sbin/esxcfg-info provides a view of the internal state of the VMkernel and Service Console components.  This tool is designed to provide information used in debugging and troubleshooting VMware ESX Servers.

OPTIONS
     -N N    Print info output for N iterations.

     -a –all
             Print all information available through esxcfg-info.

     -w –hardware
             Print hardware information.

     -r –resource
             Print resource and schedule information.

     -s –storage
             Print storage and disk-related information.

     -n –network
             Print console and VMkernel networking information.

     -y –system
             Print ESX Server system software information.

     -o –advopt
             Print the advanced options.

Stats like:

                  \==+Vcpu 0 Times :
                     |----Up Time...................................5948953771096
                     |----Used Time.................................121045150047
                     |----System time...............................757604332
                     |----Run Time..................................120931466689
                     |----Total Wait Time...........................5810226229619
                     |----Ready Time................................17792379668
                     |----Extra Time................................137103851718
                  \==+Vcpu 1 Times :
                     |----Up Time...................................5948953683199
                     |----Used Time.................................86015359219
                     |----System time...............................0
                     |----Run Time..................................86442159816
                     |----Total Wait Time...........................5841800107575
                     |----Ready Time................................20711030428
                     |----Extra Time................................137103851718
                  \==+Affinity Info :
                     |----Constrained...............................false
                     |----Joint.....................................true
                     |----User set..................................false
                     |----HyperThreading............................Any
                  \==+Memory Client Stats :
                     |----Touched...................................102.40 MB
                     |----Current Size..............................2.00 GB
                     |----Target Size...............................1.42 GB
                     |----Balloon Active............................1 KB
                     |----Balloon Size..............................0 KB
                     |----Balloon Target............................0 KB
                     |----Balloon Maximum...........................1.30 GB
                     |----Checkpoint Read...........................0 KB
                     |----Checkpoint Target.........................0 KB
                     |----Shared....................................1.26 GB
                     |----Zero......................................166.54 MB
                     |----Shared Saved..............................797.06 MB
                     |----COW hint..................................711.30 MB
                     |----Userworld Overhead........................47.45 MB
                     |----Overhead..................................116.24 MB
                     |----Overhead Maximum..........................207.61 MB

PowerCLI – VM Guest Disk Sizes

A oneline script to show the VM disk (or partiton) for each of your VM’s:

ForEach ($VM in (Get-VM |Get-View)){($VM.Guest.Disk |Select @{N=“Name“;E={$VM.Name}},DiskPath, @{N=“Capacity(MB)“;E={[math]::Round($_.Capacity/ 1MB)}}, @{N=“Free Space(MB)“;E={[math]::Round($_.FreeSpace / 1MB)}}, @{N=“Free Space %“;E={[math]::Round(((100 * ($_.FreeSpace))/ ($_.Capacity)),0)}}) | Format-Table}

Or look at the “advanced” script of virtu-al (http://www.virtu-al.net/2010/01/27/powercli-virtual-machine-disk-usage/)