Writing Monitors for the Event Monitoring Service (December 1999)

Chapter 3 117
Creating a Resource Monitor
Processing a Resource Update Event
rm_set(obj, RmResourceType, RM_STRING_TYPE, &error_code);
timer = time(NULL);
value.str = ctime(&timer);
rm_set(obj, RmResourceValue, &value, &error_code);
}
else if (strcmp(resource_name, “/samples/sbit32”) == 0) {
/*************************************************************************/
/* Get a random number between 0 and 11. */
/* Why didn’t we stop at 10? */
/* This one goes to 11. */
/*************************************************************************/
rm_set(obj, RmResourceType, RM_SBIT32_TYPE, &error_code);
value.s32 = (int) (drand48() * 12.0);
rm_set(obj, RmResourceValue, &value, &error_code);
}
else if (strcmp(resource_name, “/samples/ubit32”) == 0) {
/*************************************************************************/
/* Get the ever-increasing number of seconds since Jan. 1, 1970. */
/*************************************************************************/
rm_set(obj, RmResourceType, RM_UBIT32_TYPE, &error_code);
value.u32 = time(NULL);
rm_set(obj, RmResourceValue, &value, &error_code);
}
else if (strcmp(resource_name, “/samples/float”) == 0) {
/*************************************************************************/
/* Get the 1 minute average run-queue length. */
/*************************************************************************/
struct pst_dynamic psd_rec;
value.f64 = 0.0;
if (pstat_getdynamic(&psd_rec, sizeof(psd_rec), (size_t)1, 0) != -1) {
value.f64 = psd_rec.psd_avg_1_min;
}
rc = rm_set(obj, RmResourceType, RM_FLOAT64_TYPE, &error_code);
if (rc == -1) {
rm_perror(“Error in rm_set“, error_code);
return -1;
}