9 years ago
Monitor the size of a folder
I had a discussion with one of the support Engineers and like to raise this as a feature request. I would like to monitor a folder size on a windows and set up an alert if the utilization reaches "...
Yeah the data source we built used the same Get-ChildItem method with the recurse modifier. Worked great when we were looking at small number of folders. Attached the xml if anyone may be looking to do something similar. AD script gets all sub folders one tier down and passes them as wild values. Collection script uses the Get-ChildItem -recurse method to report the size in MB. Again this works great for monitoring a directory with a limited number of sub-directories, but has issues when monitoring a directory with a ton of sub-directories.
<?xml version="1.0" encoding="UTF-8" ?>
<feed version="1.0" hasPendingRequests="false" >
<company></company>
<status>200</status>
<errmsg>OK</errmsg>
<interval>0</interval>
<entry type="predatasource">
<version>1478878984</version>
<name>FolderSizeTest</name>
<displayedas>FolderSizeTest</displayedas>
<description></description>
<collector>script</collector>
<hasMultiInstances>true</hasMultiInstances>
<schedule>600</schedule>
<appliesTo>false()</appliesTo>
<wildcardauto>true</wildcardauto>
<wildcardpersist>true</wildcardpersist>
<wildcardlinuxscript>ad_script</wildcardlinuxscript>
<wildcardlinuxcmdline>type="powerShell" </wildcardlinuxcmdline>
<wildcardwinscript>ad_script</wildcardwinscript>
<wildcardwincmdline>type="powerShell" </wildcardwincmdline>
<wildcardgroovyscript># Pass credentials and hostname as arguments
$hostname = "##HOSTNAME##"
$user = "##wmi.USER##"
$pass = "##wmi.PASS##"
# Change the password into a secure string to be used in the credentials
$remotepass= ConvertTo-SecureString -String $pass -AsPlainText -Force
# Build the credential
$remotecredential= new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$remotepass
# Invoke command to run command remotely on host
Invoke-Command -ComputerName $hostname -ScriptBlock {
#Folder to get sub-directories hardcoded here (C:\) but could also be set to reference a system property
$colItems = (Get-ChildItem C:\ | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
foreach ($i in $colItems){Write-Host "$($i.FullName)##$($i.Name)"}
} -credential $remotecredential</wildcardgroovyscript>
<wildcardschedule>1440</wildcardschedule>
<wildcarddisable>false</wildcarddisable>
<agdmethod>none</agdmethod>
<agdparams></agdparams>
<group></group>
<tags></tags>
<technology></technology>
<adlist><![CDATA[{"agdmethod":"none","method":"ad_script","agdparams":"","id":0,"filters":[],"params":{"type":"powerShell","groovyscript":"# Pass credentials and hostname as arguments\n$hostname = \"##HOSTNAME##\"\n$user = \"##wmi.USER##\"\n$pass = \"##wmi.PASS##\"\n \n# Change the password into a secure string to be used in the credentials\n$remotepass= ConvertTo-SecureString -String $pass -AsPlainText -Force\n \n# Build the credential \n$remotecredential= new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$remotepass\n\n# Invoke command to run command remotely on host\nInvoke-Command -ComputerName $hostname -ScriptBlock {\n\n#Folder to get sub-directories hardcoded here (C:\\) but could also be set to reference a system property\n$colItems = (Get-ChildItem C:\\ | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)\nforeach ($i in $colItems){Write-Host \"$($i.FullName)##$($i.Name)\"}\n\n} -credential $remotecredential"}}]]></adlist>
<schemaVersion>1</schemaVersion>
<dataSourceType>1</dataSourceType>
<attributes>
<attribute>
<name>scripttype</name>
<value>powerShell</value>
<comment></comment>
</attribute>
<attribute>
<name>scriptgroovy</name>
<value># Pass credentials and hostname as arguments
$hostname = "##HOSTNAME##"
$user = "##wmi.USER##"
$pass = "##wmi.PASS##"
$wildvalue = "##WILDVALUE##"
# Change the password into a secure string to be used in the credentials
$remotepass= ConvertTo-SecureString -String $pass -AsPlainText -Force
# Build the credential
$remotecredential= new-object -typename System.Management.Automation.PSCredential -argumentlist $user,$remotepass
Invoke-Command -ComputerName $hostname -ScriptBlock {
param ($wild)
$colItems = (Get-ChildItem $wild -recurse | Measure-Object -property length -sum)
"{0:f2}" -f ($colItems.sum / 1MB)
} -credential $remotecredential -ArgumentList $wildvalue</value>
<comment></comment>
</attribute>
<attribute>
<name>windowsscript</name>
<value>Collect_Veeam_V_Folder5.ps1</value>
<comment></comment>
</attribute>
<attribute>
<name>linuxscript</name>
<value></value>
<comment></comment>
</attribute>
<attribute>
<name>windowscmdline</name>
<value>##ps.hostname## ##ps.user## ##ps.pass## ##wildvalue##</value>
<comment></comment>
</attribute>
<attribute>
<name>linuxcmdline</name>
<value></value>
<comment></comment>
</attribute>
</attributes>
<datapoints>
<datapoint>
<name>size</name>
<dataType>7</dataType>
<type>2</type>
<postprocessormethod>none</postprocessormethod>
<postprocessorparam></postprocessorparam>
<usevalue>output</usevalue>
<alertexpr></alertexpr>
<alertmissing>1</alertmissing>
<alertsubject></alertsubject>
<alertbody></alertbody>
<description>size in MB of folder</description>
<maxvalue></maxvalue>
<minvalue></minvalue>
<userparam1></userparam1>
<userparam2></userparam2>
<userparam3></userparam3>
<iscomposite>false</iscomposite>
<rpn></rpn>
<alertTransitionIval>0</alertTransitionIval>
<alertClearTransitionIval>0</alertClearTransitionIval>
</datapoint>
</datapoints>
<graphs>
<graph>
<name>Size</name>
<title>Size</title>
<verticallabel>TB</verticallabel>
<rigid>false</rigid>
<maxvalue>NaN</maxvalue>
<minvalue>0.0</minvalue>
<displayprio>1</displayprio>
<timescale>1day</timescale>
<base1024>false</base1024>
<graphdatapoints>
<graphdatapoint>
<name>size</name>
<datapointname>size</datapointname>
<cf>1</cf>
</graphdatapoint>
</graphdatapoints>
<graphvirtualdatapoints>
<graphvirtualdatapoint>
<name>sizeTB</name>
<rpn>(size/1024/1024)</rpn>
</graphvirtualdatapoint>
</graphvirtualdatapoints>
<graphdatas>
<graphdata>
<type>2</type>
<legend>Used</legend>
<color>blue</color>
<datapointname>sizeTB</datapointname>
<isvirtualdatapoint>true</isvirtualdatapoint>
</graphdata>
</graphdatas>
</graph>
</graphs>
<overviewgraphs>
<overviewgraph>
<name>Overview</name>
<title>Overview</title>
<verticallabel>TB</verticallabel>
<rigid>false</rigid>
<maxvalue>NaN</maxvalue>
<minvalue>0.0</minvalue>
<displayprio>1</displayprio>
<timescale>1day</timescale>
<base1024>false</base1024>
<aggregated>false</aggregated>
<datapoints>
<overviewgraphdatapoint>
<name>size</name>
<datapointname>size</datapointname>
<cf>1</cf>
<aggregateMethod>SUM</aggregateMethod>
</overviewgraphdatapoint>
</datapoints>
<virtualdatapoints>
<overviewgraphvirtualdatapoint>
<name>sizeTB</name>
<rpn>size/1024/1024</rpn>
</overviewgraphvirtualdatapoint>
</virtualdatapoints>
<lines>
<overviewgraphline>
<type>1</type>
<legend>##INSTANCE##</legend>
<datapointname>sizeTB</datapointname>
<isvirtualdatapoint>true</isvirtualdatapoint>
<color>blue</color>
</overviewgraphline>
</lines>
</overviewgraph>
</overviewgraphs>
<scripts>
</scripts>
</entry>
</feed>