Monitoring Oracle Tablespaces

Hello everyone,

I’m trying to monitor Oracle tablespaces using Checkmk, but I’m facing some difficulties. I have Checkmk running on a Linux server and I’m using the Oracle plugin for monitoring my database in windows. However, I’m not getting the expected results when trying to retrieve tablespace information.

Here’s what I have done so far:

  1. Installed and configured the Oracle agent plugin.
  2. Checked the database user permissions to ensure it has the necessary privileges.
  3. Reviewed the Checkmk discovery process, but tablespaces are not appearing as expected.

Has anyone encountered a similar issue? Any guidance on troubleshooting or additional configurations needed would be greatly appreciated.

Thanks in advance!

1 Like

I had this type of issue, I’ve solved it using the remote connection option connecting to itself. Are you using Agent Bakery or modifyng the configuration file by your self?

The Oracle tablespace checks are run as async checks (both for Linux and Windows). You may find that the async job that generates the tablespace check output is not completing for some reason.

Take a look under the “C:\ProgramData\checkmk\agent\tmp” directory on the Oracle DB winsdows server and check if there are files labelled “async_SQLs.*”. This will be the output of the Oracle plugin for the tablespace checks. You should see files labelled “sync_SQLs.<<ORACLE_SID>>.txt” there at minimum.

I had noticed on one customer site that for some reason the async checks were not running for the Oracle plugin - not sure if this was due to a security restriction.

What version of Oracle are you monitoring?

2 Likes

Hi!
Im modifying the configuration file by myself in the server that i want to monitor. The files “60_mk_oracle.ps1”, “check_mk.ini”, “mk_oracle.cfg” and “Oracle.ManagedDataAccess.dll” are in “C:\ProgramData\checkmk\agent\plugins”.


60_mk_oracle.ps1

Parámetros de conexión a Oracle

$oracleUser = “USER”
$oraclePassword = “P@SSW0RD”
$oracleHost = “HOSTNAME”
$oracleSID = “ORACLESID”
$oraclePort = “1521”

Cadena de conexión sin privilegios de DBA

$connectionString = “User Id=$oracleUser;Password=$oraclePassword;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$oracleHost)(PORT=$oraclePort)))(CONNECT_DATA=(SERVICE_NAME=$oracleSID)))”

Conexión a Oracle

try {
Write-Host “Loading Oracle DLL…”
Add-Type -Path “C:\ProgramData\checkmk\agent\plugins\Oracle.ManagedDataAccess.dll”
Write-Host “DLL loaded successfully”

Write-Host "Creating Oracle connection..."
$oracleConnection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionString)
Write-Host "Opening Oracle connection..."
$oracleConnection.Open()
Write-Host "Connection opened successfully"

# Consulta SQL mejorada para evitar valores negativos y mejorar precisión
$query = @"
SELECT t.tablespace_name, 
       ROUND(SUM(df.bytes) / 1024 / 1024, 2) AS allocated_mb, 
       ROUND(SUM(df.bytes - NVL(f.free_bytes, 0)) / 1024 / 1024, 2) AS used_mb,
       CASE 
           WHEN SUM(df.bytes) = 0 THEN 0
           ELSE ROUND((SUM(df.bytes - NVL(f.free_bytes, 0)) / SUM(df.bytes)) * 100, 2) 
       END AS used_percent
FROM dba_tablespaces t
JOIN dba_data_files df ON t.tablespace_name = df.tablespace_name
LEFT JOIN (
    SELECT tablespace_name, SUM(bytes) AS free_bytes 
    FROM dba_free_space 
    GROUP BY tablespace_name
) f ON t.tablespace_name = f.tablespace_name
GROUP BY t.tablespace_name
HAVING SUM(df.bytes - NVL(f.free_bytes, 0)) >= 0

"@

Write-Host "Executing query..."
$command = $oracleConnection.CreateCommand()
$command.CommandText = $query
$reader = $command.ExecuteReader()
Write-Host "Query executed successfully"

# Mostrar el encabezado en el formato esperado por Checkmk
Write-Host "<<<oracle_tablespaces>>>"

# Leer los resultados
while ($reader.Read()) {
    $tablespace = $reader["tablespace_name"]
    $allocatedMb = $reader["allocated_mb"]
    $usedMb = $reader["used_mb"]
    $usedPercent = $reader["used_percent"]
    
    # Mostrar la salida en el formato esperado por Checkmk
    Write-Host "$tablespace|$allocatedMb|$usedMb|$usedPercent"
}

# Cerrar la conexión
$oracleConnection.Close()
Write-Host "Connection closed successfully"

} catch {
Write-Host “Error: $($_.Exception.Message)”
}


check_mk.ini

[plugins]
enabled = yes
execution =
- pattern: C:\ProgramData\checkmk\agent\plugins\60_mk_oracle.ps1
async: yes
group: Users
run: true


mk_oracle.cfg

oracleUser=USER
oraclePassword=P@SSW0RD
oracleHost=HOSTNAME
oracleSID=ORACLESID
oraclePort=1521

Hi,

Thanks for your response. In “C:\ProgramData\checkmk\agent\tmp” in the windows server i dont have nothing.
Im using Oracle Database 19c Enterprise Edition Release 19.0.0.0.0

In Windows your config file is:

c:\programdata\checkmk\agent\config\mk_oracle_cfg.ps1

The format needs to be along the following (replace the <> as required:

$DBUSER=@("check_mk", "<<password>>", "", "<<db_host>>", "<<db_port>>","<<db_sid>>")

# Sections to run in foreground and wait for the result
$SYNC_SECTIONS=@("instance", "performance", "processes", "sessions", "longactivesessions", "logswitches", "undostat", "recovery_area", "recovery_status", "dataguard_stats", "resumable", "locks", "systemparameter")

# Sections to run in the background, at a slower interval cached
$ASYNC_SECTIONS=@("tablespace","rman","locks")


# Cache time (i.e. check interval) for async sections
$CACHE_MAXAGE=600

1 Like

Its’ okay now? I tried to rescan the checkmk monitor services of my host, but there is nothing new.

Configuración de Checkmk

$DBUSER=@(“dbuser”, “password”, “”, “host”, “port”,“SID”)

Secciones síncronas y asíncronas

$SYNC_SECTIONS=@(“instance”, “performance”, “processes”, “sessions”, “longactivesessions”, “logswitches”, “undostat”, “recovery_area”, “recovery_status”, “dataguard_stats”, “resumable”, “locks”, “systemparameter”)
$ASYNC_SECTIONS=@(“tablespace”,“rman”,“locks”)
$CACHE_MAXAGE=600

Parámetros de conexión a Oracle

$oracleUser = $DBUSER[0]
$oraclePassword = $DBUSER[1]
$oracleHost = $DBUSER[3]
$oraclePort = $DBUSER[4]
$oracleSID = $DBUSER[5]

Cadena de conexión sin privilegios de DBA

$connectionString = “User Id=$oracleUser;Password=$oraclePassword;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=$oracleHost)(PORT=$oraclePort)))(CONNECT_DATA=(SERVICE_NAME=$oracleSID)))”

Conexión a Oracle

try {
Write-Host “Loading Oracle DLL…”
Add-Type -Path “C:\ProgramData\checkmk\agent\plugins\Oracle.ManagedDataAccess.dll”
Write-Host “DLL loaded successfully”

Write-Host "Creating Oracle connection..."
$oracleConnection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionString)
Write-Host "Opening Oracle connection..."
$oracleConnection.Open()
Write-Host "Connection opened successfully"

# Determinar si la sección es asíncrona o no
if ("tablespace" -in $ASYNC_SECTIONS) {
    Write-Host "<<<oracle_tablespace:cached($CACHE_MAXAGE)>>>"
} else {
    Write-Host "<<<oracle_tablespace>>>"
}

# Consulta SQL mejorada
$query = @"
SELECT t.tablespace_name, 
       ROUND(SUM(df.bytes) / 1024 / 1024, 2) AS allocated_mb, 
       ROUND(SUM(df.bytes - NVL(f.free_bytes, 0)) / 1024 / 1024, 2) AS used_mb,
       CASE 
           WHEN SUM(df.bytes) = 0 THEN 0
           ELSE ROUND((SUM(df.bytes - NVL(f.free_bytes, 0)) / SUM(df.bytes)) * 100, 2) 
       END AS used_percent
FROM dba_tablespaces t
JOIN dba_data_files df ON t.tablespace_name = df.tablespace_name
LEFT JOIN (
    SELECT tablespace_name, SUM(bytes) AS free_bytes 
    FROM dba_free_space 
    GROUP BY tablespace_name
) f ON t.tablespace_name = f.tablespace_name
GROUP BY t.tablespace_name
HAVING SUM(df.bytes - NVL(f.free_bytes, 0)) >= 0

"@

Write-Host "Executing query..."
$command = $oracleConnection.CreateCommand()
$command.CommandText = $query
$reader = $command.ExecuteReader()
Write-Host "Query executed successfully"

# Leer los resultados
while ($reader.Read()) {
    $tablespace = $reader["tablespace_name"]
    $allocatedMb = $reader["allocated_mb"]
    $usedMb = $reader["used_mb"]
    $usedPercent = $reader["used_percent"]
    
    # Mostrar la salida en el formato esperado por Checkmk
    Write-Host "$tablespace|$allocatedMb|$usedMb|$usedPercent"
}

# Cerrar la conexión
$oracleConnection.Close()
Write-Host "Connection closed successfully"

} catch {
Write-Host “Error: $($_.Exception.Message)”
}

1 Like