PostgresMP.Unix.DataBaseConnections (UnitMonitor)

Element properties:

TargetPostgresMP.Unix.DataBase
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeUnix.Authoring.ShellScript.MatchesRegExp.ThreeState.MonitorType
RemotableTrue
AccessibilityInternal
Alert Message
DataBaseConnections
Database connection pool is about to finish computer: {0} databse: {1} status: {2}
RunAsDefault

Source Code:

<UnitMonitor ID="PostgresMP.Unix.DataBaseConnections" Accessibility="Internal" Enabled="true" Target="PostgresMP.Unix.DataBase" ParentMonitorID="SystemHealth!System.Health.AvailabilityState" Remotable="true" Priority="Normal" TypeID="UnixAuth!Unix.Authoring.ShellScript.MatchesRegExp.ThreeState.MonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="PostgresMP.Unix.DataBaseConnections.AlertMessage">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Host/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$</AlertParameter1>
<AlertParameter2>$Target/Property[Type="PostgresMP.Unix.DataBase"]/Dbname$</AlertParameter2>
<AlertParameter3>$Data/Context///*[local-name()="StdOut"]$</AlertParameter3>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="StatusOK" MonitorTypeStateID="StatusOK" HealthState="Success"/>
<OperationalState ID="StatusWarning" MonitorTypeStateID="StatusWarning" HealthState="Warning"/>
<OperationalState ID="StatusError" MonitorTypeStateID="StatusError" HealthState="Error"/>
</OperationalStates>
<Configuration>
<Interval>1800</Interval>
<TargetSystem>
$Target/Host/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$
</TargetSystem>
<ShellScript>
#!/bin/sh
DATABASE=postgres
USERNAME=postgres
OUT=$($1/psql -U "${USERNAME}" "${DATABASE}" -w -t -A -c "SELECT COUNT(datid) AS current, (SELECT setting AS mc FROM pg_settings WHERE name = 'max_connections') AS mc, d.datname FROM pg_database d LEFT JOIN pg_stat_activity s ON (s.datid = d.oid) WHERE d.datname = '$2' GROUP BY 2,3 ")
if [ $OUT -gt 93 ]; then
echo "ERROR"$OUT"%"
elif [ $OUT -le 93] &amp;&amp; [ $OUT -ge 85]; then
echo "WARNING"$OUT"%"
else
echo "OK"
fi
</ShellScript>
<ScriptArguments>$Target/Host/Property[Type="PostgresMP.Unix.Application"]/psqlPath$ "$Target/Property[Type="PostgresMP.Unix.DataBase"]/Dbname$"</ScriptArguments>
<Timeout>60</Timeout>
<UserName>$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/UserName$</UserName>
<Password>$RunAs[Name="Unix!Microsoft.Unix.ActionAccount"]/Password$</Password>
<ErrorRegExp>^ERROR</ErrorRegExp>
<WarningRegExp>^WARNING</WarningRegExp>
</Configuration>
</UnitMonitor>