extern zbx_mutex_t diskstats_lock;
#define LOCK_DISKSTATS zbx_mutex_lock(diskstats_lock)
#define UNLOCK_DISKSTATS zbx_mutex_unlock(diskstats_lock)
static void apply_diskstat(ZBX_SINGLE_DISKDEVICE_DATA *device, time_t now, zbx_uint64_t *dstat)
time_t clock[ZBX_AVG_COUNT], sec;
int index[ZBX_AVG_COUNT];
if (ZBX_MAX_COLLECTOR_HISTORY == device->index)
device->clock[device->index] = now;
device->r_sect[device->index] = dstat[ZBX_DSTAT_R_SECT];
device->r_oper[device->index] = dstat[ZBX_DSTAT_R_OPER];
device->r_byte[device->index] = dstat[ZBX_DSTAT_R_BYTE];
device->w_sect[device->index] = dstat[ZBX_DSTAT_W_SECT];
device->w_oper[device->index] = dstat[ZBX_DSTAT_W_OPER];
device->w_byte[device->index] = dstat[ZBX_DSTAT_W_BYTE];
clock[ZBX_AVG1] = clock[ZBX_AVG5] = clock[ZBX_AVG15] = now + 1;
index[ZBX_AVG1] = index[ZBX_AVG5] = index[ZBX_AVG15] = -1;
for (i = 0; i < ZBX_MAX_COLLECTOR_HISTORY; i++)
if (0 == device->clock[i])
if ((device->clock[i] >= (now - (t * 60))) && (clock[ZBX_AVG ## t] > device->clock[i]))\
clock[ZBX_AVG ## t] = device->clock[i];\
index[ZBX_AVG ## t] = i;\
#define SAVE_DISKSTAT(t)\
if (-1 == index[ZBX_AVG ## t] || 0 == now - device->clock[index[ZBX_AVG ## t]])\
device->r_sps[ZBX_AVG ## t] = 0;\
device->r_ops[ZBX_AVG ## t] = 0;\
device->r_bps[ZBX_AVG ## t] = 0;\
device->w_sps[ZBX_AVG ## t] = 0;\
device->w_ops[ZBX_AVG ## t] = 0;\
device->w_bps[ZBX_AVG ## t] = 0;\
sec = now - device->clock[index[ZBX_AVG ## t]];\
device->r_sps[ZBX_AVG ## t] = (dstat[ZBX_DSTAT_R_SECT] - device->r_sect[index[ZBX_AVG ## t]]) / (double)sec;\
device->r_ops[ZBX_AVG ## t] = (dstat[ZBX_DSTAT_R_OPER] - device->r_oper[index[ZBX_AVG ## t]]) / (double)sec;\
device->r_bps[ZBX_AVG ## t] = (dstat[ZBX_DSTAT_R_BYTE] - device->r_byte[index[ZBX_AVG ## t]]) / (double)sec;\
device->w_sps[ZBX_AVG ## t] = (dstat[ZBX_DSTAT_W_SECT] - device->w_sect[index[ZBX_AVG ## t]]) / (double)sec;\
device->w_ops[ZBX_AVG ## t] = (dstat[ZBX_DSTAT_W_OPER] - device->w_oper[index[ZBX_AVG ## t]]) / (double)sec;\
device->w_bps[ZBX_AVG ## t] = (dstat[ZBX_DSTAT_W_BYTE] - device->w_byte[index[ZBX_AVG ## t]]) / (double)sec;\