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

Missing properties #32

Closed christrotter closed 9 years ago

christrotter commented 9 years ago

Edit: I would like to add, this could very well be user error, so please point it out if so!

Thanks so much for writing and sharing this!! Found that installing via Chef cookbook just wouldn't do anything (2008R2), so tried the manual version here to troubleshoot. (2012R2)

When I first tried to run the startup script on 2008R2:

PS C:\Windows\system32> Import-Module graphite-powershell
Import-Module : The 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\graphite-powershell\graphite-powershell.psd1' m
odule cannot be imported because its manifest contains one or more members that are not valid. The valid manifest membe
rs are ('ModuleToProcess', 'NestedModules', 'GUID', 'Author', 'CompanyName', 'Copyright', 'ModuleVersion', 'Description
', 'PowerShellVersion', 'PowerShellHostName', 'PowerShellHostVersion', 'CLRVersion', 'DotNetFrameworkVersion', 'Process
orArchitecture', 'RequiredModules', 'TypesToProcess', 'FormatsToProcess', 'ScriptsToProcess', 'PrivateData', 'RequiredA
ssemblies', 'ModuleList', 'FileList', 'FunctionsToExport', 'VariablesToExport', 'AliasesToExport', 'CmdletsToExport').
Remove the members that are not valid ('RootModule'), then try to import the module again.
At line:1 char:14
+ Import-Module <<<<  graphite-powershell
    + CategoryInfo          : InvalidData: (C:\Windows\syst...powershell.psd1:String) [Import-Module], InvalidOperatio
   nException
    + FullyQualifiedErrorId : Modules_InvalidManifestMember,Microsoft.PowerShell.Commands.ImportModuleCommand

Googling gave me a fix:

# This is the PSD1 file...
# Script module or binary module file associated with this manifest.
OLD:   RootModule = 'Graphite-Powershell.psm1'
NEW:  ModuleToProcess = 'Graphite-Powershell.psm1'

Now that it's actually running...I get a bunch of these:

PS C:\GraphitePowershellFunctions> start-statstographite -verbose
The property 'NodeHostName' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\graphite-powershell\Functions\Internal.ps1:40 char:5
+     $Config.NodeHostName = $xmlfile.Configuration.Graphite.NodeHostName
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

<snip, a lot of these>

The property 'SendUsingUDP' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\graphite-powershell\Functions\Internal.ps1:52 char:5
+     [bool]$Config.SendUsingUDP = [System.Convert]::ToBoolean($xmlfile.Configurat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict
The property 'MSSQLMetics' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\graphite-powershell\Functions\Internal.ps1:93 char:5
+     $Config.MSSQLMetricPath = $xmlfile.Configuration.MSSQLMetics.MetricPath
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

<snip, a lot of these>

I found the first one is resolved by modifying the config XML: OLD: $env:COMPUTERNAME NEW: $env:COMPUTERNAME

The 2nd (IIRC) was resolved by adding in the 'SendUsingUDP' config option.

The 3rd is clearly a typo: 'MSSQLMetics'.

After finally getting it started and letting it run for a while, started getting these: (snipped)

The property 'MSSQLMetics' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\graphite-powershell\Functions\Internal.ps1:96 char:5
+     [int]$Config.MSSQLConnectTimeout = $xmlfile.Configuration.MSSQLMetics.SQLCon ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

The property 'MSSQLMetics' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\graphite-powershell\Functions\Internal.ps1:97 char:5
+     [int]$Config.MSSQLQueryTimeout = $xmlfile.Configuration.MSSQLMetics.SQLQuery ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

The property 'MSSQLMetics' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\graphite-powershell\Functions\Internal.ps1:102 char:28
+     foreach ($sqlServer in $xmlfile.Configuration.MSSQLMetics.SQLServers.SQLServ ...
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

Again, looks like something from the XML file. Interestingly, your main readme has a similar typo: MSSQLMetics Configuration Section

I think I can get it working enough for my purposes (guessing this is just a case of missing stuff from the config file - even though you'd think it wasn't required), just thought I'd let you know it was slightly broken.

christrotter commented 9 years ago

Yup, added this to my config XML and the last errors are gone.

  <MSSQLMetics>
    <MetricPath />
    <MetricSendIntervalSeconds />
    <MetricTimeSpan />
    <SQLConnectionTimeoutSeconds/>
    <SQLQueryTimeoutSeconds/>
    <SQLServers>
        <SQLServer />
    </SQLServers>
  </MSSQLMetics>

I was then getting errors like this:

VERBOSE: Removing Underscores as the switch is enabled
VERBOSE: NicePhyiscalDisks switch is enabled
VERBOSE: Job Execution Time To Get to Clean Metrics: 0.0039282 seconds.
The variable '$samplePath' cannot be retrieved because it has not been set.
At C:\Program Files\WindowsPowerShell\Modules\graphite-powershell\Functions\Start-StatsToGraphite.ps1:152 char:65
+                     Write-Verbose "Filtering out Sample Name: $($samplePath) as  ...
+                                                                 ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (samplePath:String) [], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined

VERBOSE: Filtering out Sample Name:  as it matches something in the filters.
VERBOSE: Job Execution Time To Get to Clean Metrics: 0.0157992 seconds.

I simply modified that write-output (SQLmetrics section) from $samplePath to $sample. Seems less angry.

One last issue now:

PS C:\Users\cama.buildsvc> start-statstographite -verbose
The property 'ServerInstance' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\graphite-powershell\Functions\Internal.ps1:105 char:9
+         $Config.MSSQLServers += [pscustomobject]@{
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

This is all due to the start script not ignoring the fact that I am not using SQL metrics. If it could just ignore that...most of this would be a moot point. Hope this helps clear it up!

MattHodge commented 9 years ago

Thanks for the detailed post @christrotter .. I will try and handle this a little better in the code.

christrotter commented 9 years ago

I don't recall the documentation mentioning this, and I'll post this over in the Chef cookbook page as well, but the service install is dependent on two things:

  1. At least PowerShell v3.0
  2. The Graphite-Powershell module being present In retrospect, it seems clear that the Chef cookbook is solely designed to simplify the service installation, and not function as a complete package.
MattHodge commented 9 years ago

Fixed in Graphite-PowerShell v1.2.1.

Thanks for reporting the issue!

MattHodge commented 9 years ago

v1.2.1 had a bug, please grab Graphite-PowerShell v1.2.2 instead.

ghostsquad commented 9 years ago

this fix will mask configuration errors. You should just CHECK if the mysql section exists, and if it does, pull in the configurations. I don't think this should be wrapped in a try/catch at all.