MattHodge / Graphite-PowerShell-Functions

A group of PowerShell functions that allow you to send Windows Performance counters to a Graphite Server, all configurable from a simple XML file.
https://hodgkins.io/using-powershell-to-send-metrics-graphite
GNU General Public License v3.0
218 stars 71 forks source link

Feature request: can I execute external ps1 scripts from GraphitePowerShell service #18

Closed toni-moreno closed 9 years ago

toni-moreno commented 9 years ago

Hi @MattHodge

I would like to exploit this powerful tool to take metrics from other scripts. We have already done a ps1 script capable to parse apache logs but we would like to send over the same GraphitePowerShell service .

Thank you very much!

MattHodge commented 9 years ago

Hi @toni-moreno, you should be able to do this using the functions that are exposed with with my script - https://github.com/MattHodge/Graphite-PowerShell-Functions#functions

The function Send-GraphiteMetric would be what you are after.

If you do Get-Help Send-GraphiteMetric -Examples you will see some examples that you can use.

I would create a wrapper script which dot sources your apache log parsing script and dot sources my script, then run your function and get a variable with the result. Then use Send-GraphiteMetric to send this to graphite. Here is a very basic/high level example:,

# Dot Source the 2 scripts to get access to their functions
. .\Graphite-PowerShell.ps1
. .\Apache-Log-Counter.ps1

# Get-ApacheLogs is your function
$count404 = Get-ApacheLogs -HTTPCode 404

# Send the metric over to Graphite
Send-GraphiteMetric -CarbonServer myserver.local -CarbonServerPort 2003 -MetricPath mydatacenter.servers.webserver01.apache.httpcode.404 -MetricValue $count404 -DateTime (Get-Date)

Hope this helps.

toni-moreno commented 9 years ago

ok , thank you very much!