ODBC監視は、Zabbixフロントエンドの Database monitor item タイプに相当します。
ODBCはデータベース管理システム(DBMS)にアクセスするためのC言語のミドルウェアAPIです。
ODBCのコンセプトはMicrosoftによって開発され、その後他のプラットフォームにも移植されました。
ZabbixはODBCでサポートされている全てのデータベースに問い合わせをすることができます。
そのため、Zabbixはデータベースに直接接続せず、ODBCインターフェースとODBCで設定されたドライバを利用します。
この機能により、例えば、特定のデータベースキューや利用統計の確認など、複数の目的で異なるデータベースを
より効率的に監視することが可能です。
Zabbixは最も一般的に利用されているオープンソースのODBC API実装の1つであるunixODBCをサポートしています。
ODBCチェックについては、known issuesも参照してください。
unixODBC をインストールする推奨される方法は、Linux オペレーティングシステムのデフォルトパッケージリポジトリを
使用することです。最も人気のあるLinuxディストリビューションでは、unixODBCはデフォルトで
パッケージリポジトリに含まれています。
もし利用できない場合は、unixODBCのホームページで入手することができます。
http://www.unixodbc.org/download.html.
RedHat/Fedora ベースのシステムで yum パッケージマネージャを使用して unixODBC をインストールします。
SUSE ベースのシステムで zypper パッケージマネージャを使用して unixODBC をインストールします。
unixODBC-develパッケージは、unixODBCをサポートするZabbixをコンパイルするために必要です。
監視するデータベースには、unixODBCデータベースドライバをインストールする必要があります。
unixODBCには、サポートされているデータベースとドライバのリストがあります。
http://www.unixodbc.org/drivers.html
Linuxディストリビューションによっては、データベースドライバがパッケージリポジトリに含まれている場合があります。
RedHat/Fedora ベースのシステムで、yum パッケージマネージャを使用して MySQL データベースドライバをインストールする場合:
SUSE ベースのシステムで、zypper パッケージマネージャを使用して MySQL データベースドライバをインストールする場合:
ODBCの設定は、odbcinst.ini と odbc.ini ファイルを編集することによって行われます。
設定ファイルの場所を確認するには、次のように入力します。
odbcinst.ini は、インストールされている ODBC データベースドライバーの一覧を表示するために使用されます。
パラメータの詳細:
属性 | 説明 |
---|---|
mysql | Database driver name. |
Description | Database driver description. |
Driver | Database driver library location. |
odbc.ini は、データソースの定義に使用されます:
[test]
Description = MySQL test database
Driver = mysql
Server = 127.0.0.1
User = root
Password =
Port = 3306
Database = zabbix
パラメータの詳細:
属性 | 説明 |
---|---|
test | Data source name (DSN). |
Description | Data source description. |
Driver | Database driver name - as specified in odbcinst.ini |
Server | Database server IP/DNS. |
User | Database user for connection. |
Password | Database user password. |
Port | Database connection port. |
Database | Database name. |
ODBC接続が正常に動作しているかどうかを確認するために、データベースへの接続をテストする必要があります。
これは isql ユーティリティ(unixODBC パッケージに含まれています)で行うことができます。
shell> isql test
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
ODBCサポートを有効にするには、以下のフラグを付けてZabbixをコンパイルする必要があります。
Zabbixのインストールについて詳しくは、source codeを参照してください。
データベース監視 item を設定します。
必須入力項目には、赤いアスタリスクが付けられています。
特にデータベース監視の項目について、入力する必要があります:
型 | ここで Database monitor を選択 |
Key | Enter one of the two supported item keys: db.odbc.select[<unique short description>,<dsn>,<connection string>] - this item is designed to return one value, i.e. the first column of the first row of the SQL query result. If a query returns more than one column, only the first column is read. If a query returns more than one line, only the first line is read. db.odbc.get[<unique short description>,<dsn>,<connection string>] - this item is capable of returning multiple rows/columns in JSON format. Thus it may be used as a master item that collects all data in one system call, while JSONPath preprocessing may be used in dependent items to extract individual values. For more information, see an example of the returned format, used in low-level discovery. This item is supported since Zabbix 4.4. The unique description will serve to identify the item in triggers, etc. Although dsn and connection string are optional parameters, at least one of them should be present. If both data source name (DSN) and connection string are defined, the DSN will be ignored.The data source name, if used, must be set as specified in odbc.ini. The connection string may contain driver-specific arguments. Example (connection for MySQL ODBC driver 5): => db.odbc.get[MySQL example,,"Driver=/usr/local/lib/libmyodbc5a.so;Database=master;Server=127.0.0.1;Port=3306"] |
User name | Enter the database user name This parameter is optional if user is specified in odbc.ini. If connection string is used, and User name field is not empty, it is appended to the connection string as UID=<user> |
Password | Enter the database user password This parameter is optional if password is specified in odbc.ini. If connection string is used, and Password field is not empty, it is appended to the connection string as PWD=<password> . |
SQL query | Enter the SQL query. Note that with the db.odbc.select[] item the query must return one value only. |
Type of information | It is important to know what type of information will be returned by the query, so that it is selected correctly here. With an incorrect type of information the item will turn unsupported. |
select ...
を使用した他のクエリと同様に結果セットを返す必要があります。 問い合わせの構文は、それを処理するRDBMSに依存します。ストレージプロシージャへのリクエストの構文は call
キーワードで 開始する必要があります。ODBCのエラーメッセージは、詳細な情報を提供するためにフィールドに分かれて構成されています。
たとえば、以下のようなものです。
Cannot execute ODBC query: [SQL_ERROR]:[42601][7][ERROR: syntax error at or near ";"; Error while executing the query]
└───────────┬───────────┘ └────┬────┘ └──┬──┘└┬┘└─────────────────────────────┬─────────────────────────────────────┘
│ │ │ └─ Native error code └─ Native error message
│ │ └─ SQLState
└─ Zabbix message └─ ODBC return code
エラーメッセージの長さは2048バイトに制限されているため、メッセージは切り捨てられる可能性があることに注意してください。
複数のODBC診断レコードがある場合、Zabbixはそれらを(|
で区切って)制限された長さになるように連結しようと試みます。