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

Dynamic lists on SQL metrics. #44

Closed kasperbrandenburg closed 9 years ago

kasperbrandenburg commented 9 years ago

Hi,

Would it be possible to change the SQLMetric collection to multiple rows in the resultset. E.g. grabbing multiple performance counters from dm_os_performance_counters and also generating the Graphite metric based on SQL resultset instead of having it hardcoded in the configXML

SELECT GETDATE() AS LogDate , object_name AS object_name , CASE instance_name WHEN '' THEN '_Total' ELSE instance_name END AS instance_name , counter_name AS counter_name , cntr_value AS cntr_value FROM sys.dm_os_performance_counters WITH (NOLOCK)

                # Run the SQL Command
                try
                {
                    $commandMeasurement = Measure-Command -Expression {
                        $sqlresult = Invoke-SQLCmd @sqlCmdParams

                        # Build the MetricPath that will be used to send the metric to Graphite
                        $metricPath = $Config.MSSQLMetricPath + '.' + $query.MetricName

                        $metricsToSend[$metricPath] = $sqlresult[0]
                    }
kasperbrandenburg commented 9 years ago

I created a pull-request for this :) https://github.com/MattHodge/Graphite-PowerShell-Functions/pull/47