Capturing a database health snapshot from a client application
You can capture health snapshots
using the snapshot monitor API in a C or C++ application. A number
of different health snapshot request types can be accessed by specifying
parameters in the db2GetSnapshot API.
Important: The health monitor, health indicators, and related components have been deprecated and might be
removed in a future release. Health monitor is not supported in Db2®
pureScale® environments. For
more information, see Health monitor has been deprecated.
Before you begin
You must be attached to an instance to capture a health snapshot.
If there is not an attachment to an instance, then a default instance
attachment is created. To obtain a snapshot of a remote instance,
you must first attach to that instance.
Procedure
Include the sqlmon.h and db2ApiDf.h libraries in your code.
These libraries are located in the sqllib\include directory.
#include <db2ApiDf.h>
#include <sqlmon.h>
Set the snapshot buffer unit size to 50 KB.
#define SNAPSHOT_BUFFER_UNIT_SZ 51200
Declare the sqlma, sqlca, sqlm_collected, and db2GetSnapshotData
structures.
Populate the db2GetSnapshotData structure with the snapshot
request type (from the sqlma structure), buffer information, and
other information required to capture a snapshot.
Include logic to handle buffer overflow. After a snapshot
is taken, the sqlcode is checked for a buffer overflow. If a buffer
overflow occurs, the buffer is cleared, reinitialized, and the snapshot
is taken again.