Exemple #1
0
void
GetDiskLoad (int Maximum, int data [3], LoadGraph *g)
{
	static gboolean first_call = TRUE;
	static guint64 lastread = 0, lastwrite = 0;
	static AutoScaler scaler;

	glibtop_mountlist mountlist;
	glibtop_mountentry *mountentries;
	guint i;
	int max;

	guint64 read, write;
	guint64 readdiff, writediff;


	if(first_call)
	{
	    autoscaler_init(&scaler, 60, 500);
	}

	read = write = 0;

	mountentries = glibtop_get_mountlist (&mountlist, FALSE);

	for (i = 0; i < mountlist.number; i++)
	{
		glibtop_fsusage fsusage;

		if (strcmp(mountentries[i].type, "smbfs") == 0
		    || strcmp(mountentries[i].type, "nfs") == 0
		    || strcmp(mountentries[i].type, "cifs") == 0)
			continue;

		glibtop_get_fsusage(&fsusage, mountentries[i].mountdir);
		read += fsusage.read; write += fsusage.write;
	}

	g_free(mountentries);

	readdiff  = read - lastread;
	writediff = write - lastwrite;

	lastread  = read;
	lastwrite = write;

	if(first_call)
	{
		first_call = FALSE;
		memset(data, 0, 3 * sizeof data[0]);
		return;
	}

	max = autoscaler_get_max(&scaler, readdiff + writediff);

	data[0] = (float)Maximum *  readdiff / (float)max;
	data[1] = (float)Maximum * writediff / (float)max;
	data[2] = (float)Maximum - (data [0] + data[1]);
}
Exemple #2
0
void
multiload_graph_temp_get_data (int Maximum, int data[2], LoadGraph *g, TemperatureData *xd, gboolean first_call)
{
	TemperatureSourceData *use = NULL;

	guint i, m;

	// read phase: fills in current temperature values
	switch (sources_support) {
		case TEMP_SOURCE_SUPPORT_HWMON:
			list_temp_hwmon(&sources_list, FALSE);
			break;
		case TEMP_SOURCE_SUPPORT_ACPITZ:
			list_temp_acpitz(&sources_list, FALSE);
			break;
		case TEMP_SOURCE_NO_SUPPORT:
			return;
		default:
			g_assert_not_reached();
			return;
	}

	// select phase: choose which source to show
	if (g->config->filter_enable && g->config->filter[0] != '\0') {
		for (i=0; sources_list[i].temp_path[0]!='\0'; i++) {
			if (strcmp(sources_list[i].name, g->config->filter) == 0) {
				use = &sources_list[i];
				g_debug("[graph-temp] Using source '%s' (selected by filter)", sources_list[i].name);
				break;
			}
			g_debug("[graph-temp] No source found for filter '%s'", g->config->filter);
		}
	}
	if (use == NULL) { // filter disabled or filter value not found - auto selection
		for (i=1, m=0; sources_list[i].temp_path[0]!='\0'; i++) {
			if (sources_list[i].temp > sources_list[m].temp)
				m = i;
		}
		use = &sources_list[m];
	}

	// output phase
	int max = autoscaler_get_max(&xd->scaler, g, use->temp);
	if (max == 0) {
		memset(data, 0, 2*sizeof(data[0]));
	} else {
		if (use->critical > 0 && use->critical < use->temp) {
			data[0] = rint (Maximum * (use->critical) / max);
			data[1] = rint (Maximum * (use->temp - use->critical) / max);
		} else {
			data[0] = rint (Maximum * (use->temp) / max);
			data[1] = 0;
		}
	}

	strcpy(xd->name, use->name);
	xd->value = use->temp;
	xd->max = use->critical;
}
Exemple #3
0
void
GetNet (int Maximum, int data [4], LoadGraph *g)
{
    enum Types {
	IN_COUNT = 0,
	OUT_COUNT = 1,
	LOCAL_COUNT = 2,
	COUNT_TYPES = 3
	};

    static int ticks = 0;
    static gulong past[COUNT_TYPES] = {0};
    static AutoScaler scaler;

    gulong present[COUNT_TYPES] = {0};

    guint i;
    gchar **devices;
    glibtop_netlist netlist;


    if(ticks == 0)
    {
	autoscaler_init(&scaler, 60, 501);
    }


    devices = glibtop_get_netlist(&netlist);

    for(i = 0; i < netlist.number; ++i)
    {
	int index;
	glibtop_netload netload;

	glibtop_get_netload(&netload, devices[i]);

	g_return_if_fail((netload.flags & needed_netload_flags) == needed_netload_flags);

	if (!(netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP)))
	    continue;

	if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK)) {
	    /* for loopback in and out are identical, so only count in */
	    present[LOCAL_COUNT] += netload.bytes_in;
	    continue;
	}

	/*
	 * Do not include virtual devices (VPN, PPPOE...) to avoid
	 * counting the same throughput several times.
	 */
	if (is_net_device_virtual(devices[i]))
		continue;

	present[IN_COUNT] += netload.bytes_in;
	present[OUT_COUNT] += netload.bytes_out;
    }

    g_strfreev(devices);
    netspeed_add(g->netspeed_in, present[IN_COUNT]);
    netspeed_add(g->netspeed_out, present[OUT_COUNT]);

    if(ticks < 2) /* avoid initial spike */
    {
	ticks++;
	memset(data, 0, COUNT_TYPES * sizeof data[0]);
    }
    else
    {
	int delta[COUNT_TYPES];
	int max;
	int total = 0;

	for (i = 0; i < COUNT_TYPES; i++)
	{
	    /* protect against weirdness */
	    if (present[i] >= past[i])
		    delta[i] = (present[i] - past[i]);
	    else
		    delta[i] = 0;
	    total += delta[i];
	}

	max = autoscaler_get_max(&scaler, total);

	for (i = 0; i < COUNT_TYPES; i++)
	    data[i]   = rint (Maximum * (float)delta[i]  / max);
    }

    //data[4] = Maximum - data[3] - data[2] - data[1] - data[0];
    data[COUNT_TYPES] = Maximum;
    for (i = 0; i < COUNT_TYPES; i++)
	data[COUNT_TYPES] -= data[i];

    memcpy(past, present, sizeof past);
}