Hi there,
I'm using:
PowerShell allows to perform database queries i.e. from ORACLE DB.
Following the instructions at Use Oracle ODP.NET and PowerShell to Simplify Data Access and Oracle Data Provider for .NET / ODP.NET connection strings leads to the following (working) PowerShell Script:
# Load Oracle.ManagedDataAccess.dll module in PowerShellAdd-Type -Path "C:\Program Files\WindowsPowerShell\Modules\Oracle\lib\netstandard2.0\Oracle.ManagedDataAccess.dll"
$connectionString = "Data Source=<NAME_OF_TNSNAMES_ENTRY>;User Id=<DB_USERNAME>;Password=<DB_PASSWORD>"$connection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionString)
$connection.open()$command = $connection.CreateCommand()
$command.CommandText = "SELECT 'JOB_A' JOB_NAME, 1 STATUS FROM dualUNION SELECT 'JOB_B' JOB_NAME, 2 STATUS FROM dualUNION SELECT 'JOB_C' JOB_NAME, 3 STATUS FROM dualUNION SELECT 'JOB_D' JOB_NAME, 4 STATUS FROM dualUNION SELECT 'JOB_E' JOB_NAME, 5 STATUS FROM dualUNION SELECT 'JOB_F' JOB_NAME, 6 STATUS FROM dualUNION SELECT 'JOB_G' JOB_NAME, 7 STATUS FROM dualUNION SELECT 'JOB_H' JOB_NAME, 8 STATUS FROM dualUNION SELECT 'JOB_I' JOB_NAME, 9 STATUS FROM dualUNION SELECT 'JOB_J' JOB_NAME, 10 STATUS FROM dual"
$queryResult = $command.ExecuteReader()
while ($queryResult.Read()) {$queryResult.GetOracleString(0).Value$queryResult.GetOracleDecimal(1).Value}
$connection.close()
When I execute this PowerShell script, I get the following output (as expected):PS C:\Windows\system32> C:\Program Files\powershell_prom_client\test_oracle_query.ps1JOB_A1JOB_B2JOB_C3JOB_D4JOB_E5JOB_F6JOB_G7JOB_H8JOB_I9JOB_J10
Due to the fact that my query (in real world) contains several thousand rows of output, I would like to pursue a generic approach to avoid setting a separate PowerShell variable for each table cell data...
But currently I don't know what data structure is necessary or how to parse my results (JOB_NAMES (column 1) and STATUS (column 2)) in order to trasmit them subsequently to Prometheus, so that Prometheus "understands" that there is not only one single value arriving simultaneously but mutltiple values (table data) simultaneously instead...
PS: When I would be able to receive the database query data as table data in Prometheus, I would like to use Grafana's Bar Gauge visualization. Grafana's Bar Gauge in the context of MySQL exporter supports the possibility to generically repeat every column value of type string of a specific datatable column as display name (like in my case every JOB_NAME) and it's corresponding value (like in my case STATUS). See for more information Bar Gauge : How to show Series name from a query’s row value (MySQL)?
Thanks for your help in advance!