Wednesday, November 06, 2013

RRDTool Server Dashboards

I started to use RRDTool to record and chart performance counters of my servers. Here is a dashboard for one system I deal with. There are about 6 servers involved. Some counters apply to different servers.


There is a lot going on in this chart. It shows terminal server sessions, iops, available ram, cpu, SQL connections, and sql batchs. Together, these are the key counters that really show the health of the system. I don't report network activity because it is not as important in this context.

If you look at this next one for a single file server, I look at different counters. The nice thing about using RRDTool to generate graphs is that you can really build something customized to your environment.


The last one I am going to post is of my Hyper-V cluster. The storage iScsi connections are at the top for each individual node. Across the middle is the aggregate activity of all hosts and guests to the rest of the network. The bottom shows iops on the SAN and available ram for the cluster.


This is still a work in progress but these charts are already providing a lot of value and insight into our servers.

Using RRDTool to graph pings to a host.

I started to use RRDTool again for system monitoring. One item I wanted to track and graph is ping latency to a host. First thing we need to do is create a rrd file to hold the data.

    .\rrdtool.exe create datafile.rrd -s 15  DS:data:GAUGE:900:0:U  RRA:AVERAGE:0.5:1:2020    RRA:MAX:0.5:1:2020  
 
This is a basic file that will hold about a week worth of pings at a resolution of 15 seconds. The next step is to start collecting data.

while($true){
            Test-Connection -ComputerName Computername -Count 1 -BufferSize 1460 |
                ForEach-Object{ .\rrdtool.exe update datafile.rrd N:$($_.ResponseTime)}
             Sleep 14
        }

I jumped right in with this one. Ping the host forever every 14 seconds and record it in our datafile. I know we defined the file as receiving samples every 15 seconds but it is ok if we record more often. RRDTool will aggregate the values for us. Our next step is to produce a graph.

.\rrdtool.exe graph graph.png --start -15 -u 20 -l 0 -w 400 -h 300 -t "Pings to host" DEF:"A0"="datafile.rrd":data:AVERAGE AREA:A0#FF000022 LINE2:A0#FF0000:"Ping to host"

The graph will be 400x300 over the last 15 minutes with the average ping in red. It may look something like the one below. I had to extend it out 4 hours to show a little variety in ping times.

RRDTool ping graph sample
I took this further and created a dashboard for all of my servers. I customized the charts so that they looked green if the host is up and red if the host goes offline.
The graph command for something like this gets a little more complicated, but it highlights what you can do with RRDTool. This graph shows 5 minutes of time and goes gray after 24 hours of downtime. Here is the code for those charts if you are interested. 

Get-Content .\PingList.txt | ForEach-Object {
.\rrdtool.exe graph .\Graphs\$_.ping.png -s now-300s -e now-25s -u 5 -l 0 -w 200 -h 60 -t "$_" -c BACK#000000 -c FONT#00ff00 -c CANVAS#FF0000 -c GRID#000000 -c MGRID#000000 -c ARROW#000000 -c AXIS#00ff00 -c SHADEA#000000 -c SHADEB#000000 `
    DEF:"A0"=".\ServersIV\$_.ping.rrd":data:AVERAGE `
    DEF:"PS"=".\ServersIV\$_.ping.rrd":data:AVERAGE:end=now-24h:start=end-24h `
    SHIFT:PS:86400 `
    CDEF:A0T=A0`,1`,+ `
    CDEF:A0TU=A0T`,UN `
    VDEF:MM=A0TU`,MINIMUM `
    CDEF:PST=PS`,1`,+`,UN `
    VDEF:PSMM=PST`,MINIMUM `
    TICK:MM#FFCC00:.5 `
    TICK:PSMM#333333:1 `
    TICK:A0T#339933:1 `
    AREA:A0#00000088 `
    LINE2:A0#000000  ;
}


Friday, October 04, 2013

Quick Script: Add permissions to registry key with Powershell

Write-Output "Setting Registry Permissions"
$acl = Get-Acl "HKLM:\SOFTWARE\App"
$person = [System.Security.Principal.NTAccount]"DOMAIN\Domain Users"
$access = [System.Security.AccessControl.RegistryRights]"FullControl"
$inheritance = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit"
$propagation = [System.Security.AccessControl.PropagationFlags]"None"
$type = [System.Security.AccessControl.AccessControlType]"Allow"
$rule = New-Object System.Security.AccessControl.RegistryAccessRule("$person","$access","$inheritance","$propagation","$type")

$acl.SetAccessRule($rule)

$acl |Set-Acl -Path "HKLM:\SOFTWARE\App" 

Friday, September 20, 2013

Quick Script: Run a MSI installer with a transform using Powershell

function Run-MsiExec($installShare, $msiPackage, $Transform, $options){
       $Arguments = "/i `"$env:temp\$msiPackage`" ALLUSERS=2 TRANSFORMS=`"$env:temp\$Transform`" /qn $options"
      
       Copy-Item "$installShare\$msiPackage" "$env:temp\$msiPackage"

       if($Transform){
              Copy-Item "$installShare\$Transform" "$env:temp\$Transform"
       }else{
              $Arguments = "/i `"$env:temp\$msiPackage`" ALLUSERS=2 /qn $options"
       }
       Write-Host "Installing $msiPackage"
    Write-Host "Start-Process -FilePath 'msiexec.exe' -ArgumentList "$Arguments" -Wait -Passthru"
       return (Start-Process -FilePath "msiexec.exe" -ArgumentList "$Arguments" -Wait -Passthru).ExitCode

} 

Thursday, September 12, 2013

Quick Script: Uninstall Software with Powershell

Get-WmiObject win32_product | ?{$_.Name -imatch "software"} | %{$_.Uninstall()} 

Friday, September 06, 2013

Quick Script: Sign script with timestamp using Powershell

$cert = gci cert:\currentuser\my -CodeSigningCert | ?{$_.thumbprint -eq "DA46063E89886D185F19FCD64483E35B1898925D" }

Set-AuthenticodeSignature $args[0] $cert -TimestampServer "http://timestamp.verisign.com/scripts/timstamp.dll" 

Monday, July 29, 2013

Quick Script: check for blank password using Powershell


function Check-AdminPassword(){
$LocalAdministrator = "Administrator"
$PasswordToTest = ""
$Computer = Hostname

$LdapFilter = "(&(objectCategory=Computer)(name=$Computer*))"

$Searcher = New-Object System.DirectoryServices.DirectorySearcher($Null, $LdapFilter)
$Searcher.PageSize = 1000

$PropertiesToLoad = @("name")
$Searcher.PropertiesToLoad.AddRange($PropertiesToLoad)

$Results = @()
$Searcher.FindAll() | %{
  # Variable that can be accessed within the Trap
  $Script:Exception = $Null
  # Capture any error
  Trap [Exception] {
    $Script:Exception = ($_.Exception.Message).Trim()
    Continue;
  }

  # Test binding to the Administrators group with the specified username and password
  [Void](New-Object System.DirectoryServices.DirectoryEntry(`
    "WinNT://$($_.Properties['name'])/Administrators, group", `
    "$($_.Properties['name'])\$LocalAdministrator", `
    $PasswordToTest, 0)).PsBase.Get_Name()

  # If no error is returned the the bind suceeded with this password
  If (!$Script:Exception) {
    Write-Host "[ ] Admin Password on $($_.Properties['name']) is Blank!!!"
   
  } Else {
    Write-Host "[X] Admin Password on $($_.Properties['name']) is set"
    #Write-Host "$($_.Properties['name']): Error binding - $($Script:Exception)"
  }
}
} 
# I am sure I copied most this script form someplace, but not sure where.