Juanito99 / Windows.Server.Webservice.LogdirectoryWatcher

Monitor Log directories of Webservers on Windows
GNU General Public License v3.0
2 stars 0 forks source link

Volatile Properties #7

Closed PChipVIA closed 6 years ago

PChipVIA commented 6 years ago

Hi Looking at class Windows.Server.Webservice.LogdirectoryWatcher.WebSite.Base, I noticed that it contains at least 4 volatile properties: LogDirModifiedDate,LogDirScanDate, LogDirSizeInMB, LogDirNoOfFiles.

As per https://social.technet.microsoft.com/wiki/contents/articles/14256.operations-manager-management-pack-authoring-classes-and-relationships.aspx#Properties_that_Update_Too_Frequently you should not have properties in classes that change often (as it may cause config churn -- Some post from Kevin Holman). Logically those properties will change every time the discovery will run (every 14400 seconds).

Unless needed, I would recommend you stop discovering them..

HTH

Juanito99 commented 6 years ago

Hi @PChipVIA ,

thanks for your kind feedback. I am aware of the volatile properties and also that it's not a best-practice to do so. As the discovery only runs every 4 hours and the data which is changed is small I believed that there is more benefit than disadvantage by providing the information so that you can get this information at glance in the state view.

Have you noticed any negative performance impact on the database or on the agent machine after importing the MP?

After reading Brians article again I think collecting the size via rule might be also quiet interesting.

Thank you!! :+1:

I'll consider you suggestions.

PChipVIA commented 6 years ago

Hi @Juanito99 ,

For the volatile properties, I think the entire record updates if a single property changes so IMHO the cons outweigh the pros. Collection Rule indeed would be best as it would allow one to see growth/trends over time. I haven't installed the MP, just wanted to reverse engineer how you detected Tomcat servers and how you detected the log folder... :+1: Learn every day!

If I can add a little more to the thread. Couple things

I created a PoC script which addresses the points above (of course there is a need to adjust the classes, relationships & monitoring) ` ForEach ($Tomcat in Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\services\Tomcat*) {

$apacheBaseDirectory = [Regex]::Matches($Tomcat.GetValue('ImagePath'), '(?i)[a-z\\0-9\._()\-: ]{1,}(?=bin\\tomcat\d{1}.exe)') | Select-Object -ExpandProperty Value

$apacheLogConfig = Get-Content (Join-Path $apacheBaseDirectory 'conf\logging.properties') | Where-Object { $_ -notmatch "^(\s+)?;|^\s*$|^#" }

[PSCustomObject]@{
    Tomcat = $Tomcat.Name -split '\\' | Select-Object -Last 1
    BaseDirectory = $apacheBaseDirectory
    LogConfig = $apacheLogConfig
} | Format-Table # Format List/Table not needed in script, just to show handlers on screen

ForEach ($Handler in ($apacheLogConfig | Where-Object{ $_ -match '^handlers = (.*)' }) -replace '^handlers = ' -split '\s*,\s*' | Where-Object{ $_ -match 'file' }) {
    $HandlerDirectory = $HandlerPrefix = $null
    $HandlerDirectory = (($apacheLogConfig | Where-Object{ $_ -match "^$Handler\.directory" }) -split '\s=\s')[1] -replace '\/', '\' -replace '\$\{catalina.base\}\\', $apacheBaseDirectory
    $HandlerPrefix = (($apacheLogConfig | Where-Object{ $_ -match "^$Handler\.prefix" }) -split '\s=\s')[1]

    [PSCustomObject]@{
        Handler = $Handler.Split('.')[0]
        Level   = (($apacheLogConfig | Where-Object{ $_ -match "^$Handler\.level" }) -split '\s=\s')[1]
        Directory = $HandlerDirectory
        Prefix  = $HandlerPrefix
        # Not to use in discovery, but should be in probe script
        LogSize = [Math]::Round(((Get-ChildItem (Join-Path $HandlerDirectory "$HandlerPrefix*") | Measure-Object -property length -sum).Sum / 1mb -as [double]), 2)
    }
}

} `

(sorry first time posting on GitHub, can't seem to figure out the code stuff)

Juanito99 commented 6 years ago

Hi @PChipVia,

great feedback. Many thanks. I am on the way to vacation and a bit limited with phone and time, so keep a bit short this time :-)

If I don't mixup I pulled the log folder out of the registry, or just for Apache ...

You are absolutely right about I only cover one instance. Haven't thought there might be multliple. I will check the code when back :-)

Second when I am back I will remove the frequently changing properties. Thinking a while longer I think I may be one of the reasons for slowing down our SCOM ... Oops ... As you said learn every day :-)

I will update here and would be glad to get feedback after updated later ...

Kind regards

Ruben

Juanito99 commented 6 years ago

Hi @PChipVIA ,

I changed the classes and removed those attributes as suggested. A rule is now recording the size of the log file folders.

For the mentioned Tomcat issue I can't find the time at the moment. - Nevertheless, may thanks for this hint! :+1:

Ruben