Hey,
I am attempting to use Zabbix to query an MSSQL database and get the duration of the query (in miliseconds).
It has mostly worked - I created a Powershell script that queries the database and outputs the duration, and put it on a host. I then created a Zabbix item for that host that activates the script every 30 seconds.
The problem is, the values that I receive when Zabbix runs the scripts are different than the ones I get when running the script manually on the host!
For example, when I run the script manually I get values like "9.0009" or "15.0015". But when Zabbix runs the script I get much higher values like "989.09". I really have no idea what is causing the difference, because the script should be running on the local host either way. I have a feeling this is a Zabbix issue and not a Powershell issue.
This is the Powershell script:
Note that, as you can see, it also saves the start time, end time and result in a txt file.
This is the txt file:
Those lower values are from when I ran the script manually. The high ones are from when Zabbix ran the script.
I would appreciate any help regarding this issue.
Thanks!
I am attempting to use Zabbix to query an MSSQL database and get the duration of the query (in miliseconds).
It has mostly worked - I created a Powershell script that queries the database and outputs the duration, and put it on a host. I then created a Zabbix item for that host that activates the script every 30 seconds.
The problem is, the values that I receive when Zabbix runs the scripts are different than the ones I get when running the script manually on the host!
For example, when I run the script manually I get values like "9.0009" or "15.0015". But when Zabbix runs the script I get much higher values like "989.09". I really have no idea what is causing the difference, because the script should be running on the local host either way. I have a feeling this is a Zabbix issue and not a Powershell issue.
This is the Powershell script:
Code:
Write-Output "Starting check..." | Out-File -append c:\scripts\test.txt
$StartTime = Get-Date
Write-Output "Start Time: ${StartTime}" | Out-File -append c:\scripts\test.txt
$Server = "SERVERNAME"
$Username = 'USER'
$Password = 'PASS'
Write-Output "Invoking query" | Out-File -append c:\scripts\test.txt
Invoke-SqlCmd -ServerInstance $Server -Query "select @@version" > $null -Username $Username -Password $Password
$EndTime = Get-Date
$Duration = New-TimeSpan -Start $StartTime -End $EndTime
Write-Output "End Time: ${EndTime}" | Out-File -append c:\scripts\test.txt
$Delta = $Duration.TotalMilliseconds
Write-Output "Delta: ${Delta}" | Out-File -append c:\scripts\test.txt
Write-Output $Delta
This is the txt file:
Code:
Starting check... Start Time: 05/30/2016 14:13:12 Invoking query End Time: 05/30/2016 14:13:13 Delta: 918.0918 Starting check... Start Time: 05/30/2016 14:13:42 Invoking query End Time: 05/30/2016 14:13:43 Delta: 908.0881 Starting check... Start Time: 05/30/2016 14:14:13 Invoking query End Time: 05/30/2016 14:14:14 Delta: 936.0936 Starting check... Start Time: 05/30/2016 14:14:16 Invoking query End Time: 05/30/2016 14:14:16 Delta: 15.0015 Starting check... Start Time: 05/30/2016 14:14:17 Invoking query End Time: 05/30/2016 14:14:17 Delta: 4.0004 Starting check... Start Time: 05/30/2016 14:14:17 Invoking query End Time: 05/30/2016 14:14:17 Delta: 6.0006 Starting check... Start Time: 05/30/2016 14:14:17 Invoking query End Time: 05/30/2016 14:14:17 Delta: 15.0015
I would appreciate any help regarding this issue.
Thanks!