|
SQL Query File
|
The script will be executed with every scanning interval. The list contains SQL scripts from the database management system specific \Custom Sensors\sql subfolder of your PRTG installation. Store your script there. If used on a remote probe, the file must be stored on the system running the remote probe. If used on a cluster probe, you must store the file on all servers running a cluster node!
For more information on how to find this path, please see Data Storage section.Demo Serveruptime.sql
SELECT AVG(UnitPrice) FROM Products. If you want to use transactions, separate the individual steps with semicolons ";".
Please be aware that with each request, the full result set will be transferred,
so use filters and limits in your query.
See also this Knowledge Base article: Why do I have to store SQL sensor queries and custom scripts in files on the probe computer?
SQL Variables
You can use the following variables in your query file to have them replaced by an input parameter. This is useful if you have various SQL sensors with queries that differ in only one parameter.
- Microsoft SQL, MySQL, PostgreSQL: @prtg
- Oracle SQL: :prtg
- ADO SQL: ? (question mark)
@prtg, :prtg, and ? behave like common SQL variables, so consider the general rules for SQL variables. For example, you cannot use a variable for a table in the FROM statement of a query.
Example for variables usage: SELECT * FROM Table WHERE @prtg
|
Use Input Parameter
|
Define if you want to pass a parameter to your SQL query file. This will replace the variables @prtg (Microsoft SQL, MySQL, PostgreSQL), or :prtg (Oracle SQL), or ? (ADO SQL) in the SQL query, considering the general rules for SQL variables. Choose between:
- Don't use input parameter (default): Execute the SQL query file without using variables.
- Use input parameter: Execute an SQL query file that contains a variable. Provide the parameter you want to use in the query below.
|
Input Parameter
|
Use input parameter@prtg:prtg?
%sensorid%deviceid
|
Use Transaction
|
- Don't use transaction (default)
- Use transaction and always rollbackSQL query file
- Use transaction and commit on successSQL query file
|
Data Processing
|
- Just execute the query: If you select this option, the sensor will only show information about the number of affected rows and the execution time of the query. Affected rows are rows that were changed somehow with the query (for example, created, deleted, edited).
- Count table rows: Choose this option if you perform a SELECT statement and want to monitor how many rows of the data table this statement returns.
- Process data table: Select this option to read and analyze the queried data table. If you select this option, the sensor will count rows with SELECT statements as well.
|
Handle DBNull in Channel Values as
|
This setting is only visible if you select Process data table above. Define the sensor behavior if DBNull is returned by the query. Choose between:
- Error: The sensor will show a Down status if DBNull is reported.
- Number 0: The sensor will recognize the result DBNull as a valid value and interpret it as the number 0.
|
Select Channel Value by
|
This setting is only visible if you select Process data table above. Define how the desired cell in the database table will be selected. This is necessary to configure the cells that will be used in the sensor channels. Choose between:
- Column number: The channel value will be determined by using the value in row 0 of the column whose number you specify below.
- Column name: The channel value will be determined by using the value in row 0 of the column whose name you specify below.
- Row number: The channel value will be determined by using the value in column 0 of the row whose number you specify below.
- Key value pair: The channel value will be determined by searching in column 0 for the key you specify below and returning the value in column 1 of the same row where the key value was found.
The option you choose here also defines the method to optionally determine a value for the sensor message. For details, see setting Use Data Table Value in Sensor Message below.
Please see m
|
Sensor Channel #x
|
This setting is only visible if you select Process data table above. You can define up to 10 different channels for the data processing of this sensor. You have to define at least one data channel if you process the data table, so you will see all available settings for Channel #1 without enabling it manually. For all other possible channels, choose between:
- Disable: This channel will not be added to the sensor.
- Enable: This channel will be added to the sensor. Define the settings as described above.
Once a sensor is created, you cannot change this value. It is shown for reference purposes only. If you need to change this, please add the sensor anew.
|
Sensor Channel #x Name
|
This setting is only visible if you select Process data table above. Enter a unique name for the channel. Please enter a string. Channels will be generated dynamically with this name as identifier. Once a sensor is created, you cannot change this value. It is shown for reference purposes only. If you need to change this, please add the sensor anew.
|
Sensor Channel #x Column Number
|
This setting is only visible if you select Column number above. Provide the number of the column which will be used to determine the channel value in row 0. Please enter an integer value.
|
Sensor Channel #x Column Name
|
This setting is only visible if you select Column number above. Provide the name of the column which will be used to determine the channel value in row 0. Please enter a string.
|
Sensor Channel #x Row Number
|
This setting is only visible if you select Row number above. Provide the number of the row which will be used to determine the channel value in column 0. Please enter an integer value.
|
Sensor Channel #x Key
|
This setting is only visible if you select Key value pair above. Provide the key to search for in column 0 of the data table. The value in column 1 of the same row where the key value was found will be used to determine the channel value. Please enter a string.
|
Sensor Channel #x Mode
|
This setting is only visible if you select Process data table above. Define how to display the determined value in the channel. Once a sensor is created, you cannot change this value. It is shown for reference purposes only. If you need to change this, please add the sensor anew. Choose between:
- Absolute (recommended): Shows the value as the sensor retrieves it from the data table.
- Difference: The sensor calculates and shows the difference between the last and the current value returned from the data table.
|
Sensor Channel #x Unit
|
This setting is only visible if you select Process data table above. Define the unit of the channel value. Once a sensor is created, you cannot change this value. It is shown for reference purposes only. If you need to change this, please add the sensor anew. Choose between:
- BytesBandwidth
- BytesMemory
- BytesDisk
- Temperature
- Percent
- TimeResponse
- TimeSeconds
- TimeHours
- Count
- CPU
- BytesFile
- SpeedDisk
- SpeedNet
- Custom
- Value Lookup
For more information about the available units, please refer to the PRTG Application Programming Interface (API) Definition for custom sensors.
To use lookups with this channel, choose Value Lookup and select your lookup file below. Do not use Custom for using lookups with this sensor!
|
Sensor Channel #x Custom Unit
|
This setting is only visible if you select Custom above. Define a unit for the channel value. Please enter a string.
|
Sensor Channel #x Value Lookup
|
This settings is only visible if you select Value Lookup above. Select a lookup file that you want to use with this channel.
|
Use Data Table Value in Sensor Message
|
This setting is only visible if you select Process data table above. Define if the sensor message will show a value from the data table. Choose between:
- Disable: Do not use a custom sensor message.
- Enable: Define a custom sensor message with a defined value of the data table. Define the value selection below.
The method to determine a value for the sensor message is defined in setting Select Channel Value by above.
|
Sensor Message Column Number
|
This setting is only visible if you select Column number and Use Data Table Value in Sensor Message above. Enter the number of a column. The sensor message will show the value in row 0 of this column. Please enter an integer value.
Columns and rows start with index 0.
|
Sensor Message Column Name
|
This setting is only visible if you select Column name and Use Data Table Value in Sensor Message above. Enter the name of a column. The sensor message will show the value in row 0 of this column. Please enter a string.
Columns and rows start with index 0.
|
Sensor Message Row Number
|
This setting is only visible if you select Row number and Use Data Table Value in Sensor Message above. Enter the number of a row. The sensor message will show value in column 0 of this row. Please enter an integer value.
Columns and rows start with index 0.
|
Sensor Message Key
|
This setting is only visible if you select Key value pair and Use Data Table Value in Sensor Message above. Enter a key to search for in column 0 of the data table. The sensor message will show the value in column 1 of the row where the key has been found. Please enter a string.
Columns and rows start with index 0.
|
Sensor Message
|
This setting is only visible if you select Use Data Table Value in Sensor Message above. Define the sensor message. Please enter a string. Use the placeholder {0} at the position where the value will be added.
Example: The message is {0}
|
If Sensor Message Changes
|
Define what this sensor will do when the sensor value changes. You can choose between:
- Ignore changes (default): The sensor takes no action on change.
- Trigger 'change' notification: The sensor sends an internal message indicating that its value has changed. In combination with a Change Trigger, you can use this mechanism to trigger a notification whenever the sensor value changes.
|
Sensor Result
|
Define what PRTG will do with the sensor results. Choose between:
- Discard sensor result: Do not store the sensor result.
- Write sensor result to disk (Filename: "Result of Sensor [ID].txt"): Store the last result received from the sensor to the Logs (Sensor) directory in the PRTG data folder on the probe system the sensor is running on (on the Master node if in a cluster). File names: Result of Sensor [ID].txt and Result of Sensor [ID].Data.txt. This is for debugging purposes. PRTG overrides these files with each scanning interval.
For more information on how to find the folder used for storage, see section Data Storage.
This option is not available on cloud probes in PRTG in the cloud.
|