Skip to content

Asynchronous ODBC polling

Glaber polls database monitoring items (db.odbc.select, db.odbc.discovery, db.odbc.get) asynchronously: all unixODBC calls are moved out of the poller processes into a separate ODBC worker process.

This solves a well-known problem of the classic Zabbix ODBC pollers: a hang inside a proprietary ODBC driver (most often Oracle) blocks the whole poller fork forever. The driver library cannot be fixed, so Glaber isolates it in a disposable worker process instead.

How it works

  • Each ODBC poller fork (StartGlbODBCWorkers) owns exactly one worker process.
  • The fork works with its worker in strict lockstep: it picks one item from the queue, sends the query to the worker and does not send anything else until the response arrives or the item timeout fires. The timeout therefore always measures the actual query processing time.
  • Items of the same host always arrive to the same fork (hostid % forks), so per-host connection state stays on one worker.
  • If the timeout fires, the fork considers the worker hung inside the ODBC driver, kills it and starts a new one; the next item from the queue goes to the fresh worker. Only the single in-flight item fails.
  • As a backstop the worker also arms alarm(timeout + 5) around every ODBC call and terminates itself if a driver call hangs, so a dead worker is detected and restarted even without the poller timeout. The poller fork kills the worker on its own item timeout plus 10 seconds.

The poller fork itself never executes driver code and can never hang.

Configuration

# number of async ODBC poller forks, each runs its own worker
StartGlbODBCWorkers=1

# optional: path to the standalone worker executable
#ODBCWorkerLocation=/usr/sbin/worker_odbc
Parameter Description
StartGlbODBCWorkers Number of asynchronous ODBC poller forks (0-1000, default 0). Requires server/proxy built with --with-unixodbc.
ODBCWorkerLocation Path to the standalone worker_odbc executable. When not set, the embedded mode is used (see below).

The classic StartODBCPollers parameter still exists, but the asynchronous worker-based polling is the recommended way: it is immune to driver hangs.

Embedded mode (default)

When ODBCWorkerLocation is not set, the server/proxy spawns its own executable with the --odbc-worker flag:

glaber_server --odbc-worker
glaber_proxy --odbc-worker

In this mode the binary runs the serial ODBC worker loop instead of the server/proxy. No separate worker binary needs to be installed, and the worker version can never drift apart from the server version.

The flag can be combined with worker options:

glaber_server --odbc-worker -t 5 -d 4
  • -t <seconds> — default request timeout (default 3)
  • -d <level> — debug log level 0-5 (default 3)

Standalone worker

The build also produces a small standalone worker_odbc executable (src/glb_odbc_worker/). Point ODBCWorkerLocation to it if you prefer a separate binary. It is also handy for manual testing — the worker reads newline-delimited JSON requests from stdin and writes JSON responses to stdout:

echo '{"id":1,"dsn":"mydsn","query":"select 1","type":"select","timeout":5}' | worker_odbc
{"id":1,"code":200,"value":"1"}

Request fields: id (item id), dsn, connection (connection string, alternative to DSN), user, pass, query, type (select | discovery | get), timeout, optional debug.

Response codes:

Code Meaning
200 Success, value contains the result
503 Connection failure, the host interface is penalized
500 Item-level error (bad query, conversion failure), no interface penalty

Notes

  • Throughput per fork is serial by design: one query at a time. Scale with StartGlbODBCWorkers if you have many ODBC items or slow queries.
  • A hung driver costs exactly one item (failed with timeout) and one worker restart; the rest of the queue is processed by the fresh worker.
  • Worker logs go to stderr; stdout carries only the JSON protocol.