diff --git a/Functions/Start-StatsToGraphite.ps1 b/Functions/Start-StatsToGraphite.ps1 index 97b8799..6a00953 100644 --- a/Functions/Start-StatsToGraphite.ps1 +++ b/Functions/Start-StatsToGraphite.ps1 @@ -18,6 +18,9 @@ Function Start-StatsToGraphite .Parameter SqlMetrics Includes SQL Metrics defined in XML config + + .Parameter ConfigXMLPath + Uses this configuration file instead of the one inside the module folder .Example PS> Start-StatsToGraphite @@ -51,9 +54,19 @@ Function Start-StatsToGraphite [Parameter(Mandatory = $false)] [switch]$TestMode, [switch]$ExcludePerfCounters = $false, - [switch]$SqlMetrics = $false + [switch]$SqlMetrics = $false, + [string]$ConfigXMLPath ) + # Override the config path set in the module if one is provided explicitly + if (-not [string]::IsNullOrWhiteSpace($ConfigXMLPath)) { + $configPath = $ConfigXMLPath + } + + if (-not (Test-Path -PathType Leaf -LiteralPath $configPath)){ + throw "Cannot find configuration file - $configPath" + } + # Run The Load XML Config Function $Config = Import-XMLConfig -ConfigPath $configPath @@ -142,7 +155,11 @@ Function Start-StatsToGraphite $cleanNameOfSample = ConvertTo-GraphiteMetric -MetricToClean $sample.Path -HostName $Config.NodeHostName -MetricReplacementHash $Config.MetricReplace # Build the full metric path - $metricPath = $Config.MetricPath + '.' + $cleanNameOfSample + if (-not [string]::IsNullOrWhiteSpace($Config.MetricPath)) { + $metricPath = $Config.MetricPath + '.' + $cleanNameOfSample + } else { + $metricPath = $cleanNameOfSample + } $metricsToSend[$metricPath] = $sample.Cookedvalue }