So I've recently had a need to begin using Slack. I started out using a web browser, but since there is a Windows client I decided to give it a go. This article isn't about Slack as much as what I was curious about and how I decided to tackle the problem.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
I had read a few comments about the performance of the Slack client, although they may have been in reference to using a web browser, but it actually doesn't matter. Instead I thought, "How can I get some historical data?" You probably have similar needs for things like processes or disk space. Since I was interested in memory utilization I could have used performance counters, and perhaps I'll write about that eventually, but for now I had a simple one line command that gave me the pieces of information I wanted to track.
Get-Process Slack | measure -Property WS -sum | Select Count,Sum
Getting process data (Image Credit: Jeff Hicks)
What I wanted was a way to take that snapshot repeatedly throughout the day and record the results. I decided to use a PowerShell scheduled job.
I wanted a repeating task and in my case I decided to only have it repeat for an 8 hour time span. I used a hashtable of parameters to splat to New-JobTrigger.
$paramHash = @{ RepetitionInterval = (New-TimeSpan -Minutes 30) RepetitionDuration = (New-Timespan -hours 8) at = (Get-Date).AddMinutes(1) Once = $True } $Trigger = New-JobTrigger @paramHash
I elected to kick off the job one minute from the time I created the trigger. I could have used a scriptfile for my command which I expanded to export the results to a CSV file with a little additional information.
$sb = { Param([string]$Path) Get-Process Slack | measure -Property WS -sum | Select @{Name="Computername";Expression={$env:computername}}, @{Name="Date";Expression={Get-Date}},Count,Sum | Export-CSV $path -Append -NoTypeInformation }
All that remains is to create the scheduled job with Register-ScheduledJob.
$path = "C:\work\slackhistory.csv" $paramHash = @{ Name = 'SlackHistory' Trigger = $Trigger MaxResultCount = 4 ScriptBlock = $sb ArgumentList = $path } Register-ScheduledJob @paramHash
Throughout the day, PowerShell added data to my CSV file.
The data csv file (Image Credit: Jeff Hicks)
If you noticed, I suppressed type information. This was so I could easily import the CSV into Excel and do some charting.
Charting the data in Excel (Image Credit: Jeff Hicks)
I formatted a few columns to make a nicer graph. Although I certainly could have formatted values like the WS sum in MB in PowerShell to begin with.
My techniques here are admittedly a little ad-hoc and perhaps not completely ready for an enterprise wide data gathering system, certainly of the "poor man's" flavor. But I hope you see how easy it is to combine PowerShell and scheduled tasks to get the job done.
You probably have questions, so feel free to ask in the comments.
Nice! Thanks for sharing this!