Пример #1
0
static void
monitoring_loop(service_info_t *si)
{
	long jiffies = 0;
	GTimer *timer;
	GError *error = NULL;
	guint proc_count;

	timer = g_timer_new();
	monitor_get_status(svc_mon, si);
	_add_custom_tags(si);

	proc_count = supervisor_children_startall(NULL, NULL);
	DEBUG("First started %u processes", proc_count);

	for (;;) { /* main loop */
		struct timeval tv_sleep;

		if (flag_restart_children) {
			if (auto_restart_children) {
				supervisor_children_repair(CHILD_KEY);
				supervisor_children_enable(CHILD_KEY, TRUE);
				proc_count = supervisor_children_startall(NULL,NULL);

				DEBUG("Started %u processes", proc_count);
				flag_restart_children = !!proc_count;
			} else {
				DEBUG("One of my children died, I will die too (auto_restart_children=%d)", auto_restart_children);
				break;
			}
		}

		if (!flag_running)
			break;

		if (g_timer_elapsed(timer, NULL) >= 1.0) {
			if (!((++jiffies) % monitor_period)) {
				monitor_get_status(svc_mon, si);
				_add_custom_tags(si);
			}
			if (!register_namespace_service(si, &error)) {
				ERROR("Failed to register the service: %s", gerror_get_message(error));
				g_clear_error(&error);
			}
			g_timer_reset(timer);
		}

		tv_sleep.tv_sec = 1L;
		tv_sleep.tv_usec = 0L;
		select(0, NULL, NULL, NULL, &tv_sleep);
		errno = 0;
	}

	supervisor_children_stopall(4);
	supervisor_children_catharsis(NULL, NULL);

	g_free(timer);
}
Пример #2
0
static void
monitoring_loop(service_info_t *si)
{
	long jiffies = 0;
	GTimer *timer;
	GError *error = NULL;
	guint proc_count;

	timer = g_timer_new();
	monitor_get_status(svc_mon, si);
	_add_custom_tags(si);

	proc_count = supervisor_children_startall(NULL, NULL);
	GRID_DEBUG("First started %u processes", proc_count);

	while (flag_running) { /* main loop */

		if (flag_restart_children) {
			if (auto_restart_children) {
				supervisor_children_repair(CHILD_KEY);
				supervisor_children_enable(CHILD_KEY, TRUE);
				proc_count = supervisor_children_startall(NULL,NULL);

				GRID_DEBUG("Started %u processes", proc_count);
				flag_restart_children = !!proc_count;
			} else {
				GRID_DEBUG("One of my children died, I will die too (auto_restart_children=%d)", auto_restart_children);
				break;
			}
		}

		if (!flag_running)
			break;

		gdouble elapsed = g_timer_elapsed(timer, NULL);
		if (elapsed >= 1.0) {
			if (!((++jiffies) % monitor_period)) {
				monitor_get_status(svc_mon, si);
				_add_custom_tags(si);
			}
			if (!register_namespace_service(si, &error)) {
				GRID_WARN("Failed to register the service: %s", gerror_get_message(error));
				g_clear_error(&error);
			}
			g_timer_reset(timer);
			elapsed = 0.0;
		}

		g_usleep (1000000UL - ((gulong)elapsed));
	}

	supervisor_children_stopall(4);
	supervisor_children_catharsis(NULL, NULL);

	g_free(timer);
}
Пример #3
0
static void
_task_register(gpointer p)
{
	if (PSRV(p)->flag_noregister)
		return;

	/* Computes the avg requests rate/time */
	time_t now = oio_ext_monotonic_time () / G_TIME_SPAN_SECOND;

	grid_single_rrd_push (PSRV(p)->gsr_reqcounter, now,
			network_server_stat_getone(PSRV(p)->server,
				g_quark_from_static_string(OIO_STAT_PREFIX_REQ)));
	grid_single_rrd_push (PSRV(p)->gsr_reqtime, now,
			network_server_stat_getone(PSRV(p)->server,
				g_quark_from_static_string(OIO_STAT_PREFIX_TIME)));

	guint64 avg_counter = grid_single_rrd_get_delta(PSRV(p)->gsr_reqcounter,
			now, 4);
	guint64 avg_time = grid_single_rrd_get_delta(PSRV(p)->gsr_reqtime,
			now, 4);

	avg_counter = MACRO_COND(avg_counter != 0, avg_counter, 1);
	avg_time = MACRO_COND(avg_time != 0, avg_time, 1);

	service_tag_set_value_i64(service_info_ensure_tag(PSRV(p)->si->tags,
				"stat.total_reqpersec"), avg_counter / 4);
	service_tag_set_value_i64(service_info_ensure_tag(PSRV(p)->si->tags,
				"stat.total_avreqtime"), (avg_time)/(avg_counter));

	/* send the registration now */
	GError *err = register_namespace_service(PSRV(p)->si);
	if (err) {
		g_message("Service registration failed: (%d) %s", err->code, err->message);
		g_clear_error(&err);
	}
}