Exemplo n.º 1
0
static void
process_stat_struct (int which, const void *ptr, const char *dev, const char *mac,
			 const char *type_name, const char *misc_name)
{
	uint32_t misc = 0;
	int i;

	assert (which >= 1);
	assert (which < STATIC_ARRAY_SIZE (bounds));

	for (i = bounds[which - 1]; i < bounds[which]; i++)
	{
		uint32_t val = *(uint32_t *)(((char *) ptr) + specs[i].offset) ;

		if (item_watched (i) && (val != 0))
			submit_derive (dev, type_name, specs[i].name, mac, val);

		if (item_summed (i))
			misc += val;
	}
	
	if (misc != 0)
		submit_derive (dev, type_name, misc_name, mac, misc);

}
Exemplo n.º 2
0
static int
process_station (int sk, const char *dev, struct ieee80211req_sta_info *si)
{
	struct iwreq iwr;
	static char mac[DATA_MAX_NAME_LEN];
	struct ieee80211req_sta_stats stats;
	const struct ieee80211_nodestats *ns = &stats.is_stats;
	int status;

	macaddr_to_str (mac, sizeof (mac), si->isi_macaddr);

	if (item_watched (STAT_NODE_TX_RATE))
		submit_gauge (dev, "node_tx_rate", mac, NULL,
			(si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL) / 2);

	if (item_watched (STAT_NODE_RSSI))
		submit_gauge (dev, "node_rssi", mac, NULL, si->isi_rssi);

	memset (&iwr, 0, sizeof (iwr));
	sstrncpy(iwr.ifr_name, dev, sizeof (iwr.ifr_name));
	iwr.u.data.pointer = (void *) &stats;
	iwr.u.data.length = sizeof (stats);
	memcpy(stats.is_u.macaddr, si->isi_macaddr, IEEE80211_ADDR_LEN);
	status = ioctl(sk, IEEE80211_IOCTL_STA_STATS, &iwr);
	if (status < 0)
	{
		/* Silent, because not all interfaces support all ioctls. */
		DEBUG ("madwifi plugin: Sending IO-control "
				"IEEE80211_IOCTL_STA_STATS to device %s "
				"failed with status %i.",
				dev, status);
		return (status);
	}

	/* These two stats are handled as a special case as they are
	   a pair of 64bit values */
	if (item_watched (STAT_NODE_OCTETS))
		submit_derive2 (dev, "node_octets", mac, NULL,
			ns->ns_rx_bytes, ns->ns_tx_bytes);

	/* This stat is handled as a special case, because it is stored
	   as uin64_t, but we will ignore upper half */
	if (item_watched (STAT_NS_RX_BEACONS))
		submit_derive (dev, "node_stat", "ns_rx_beacons", mac,
			(ns->ns_rx_beacons & 0xFFFFFFFF));

	/* All other node statistics */
	process_stat_struct (NOD_STAT, ns, dev, mac, "node_stat", "ns_misc");
	return (0);
}
Exemplo n.º 3
0
static void submit_antx (const char *dev, const char *name,
		u_int32_t *vals, int vals_num)
{
	char ti2[16];
	int i;

	for (i = 0; i < vals_num; i++)
	{
		if (vals[i] == 0)
			continue;

		ssnprintf (ti2, sizeof (ti2), "%i", i);
		submit_derive (dev, "ath_stat", name, ti2,
				(derive_t) vals[i]);
	}
}
Exemplo n.º 4
0
static int apache_read_host (user_data_t *user_data) /* {{{ */
{
	int i;

	char *ptr;
	char *saveptr;
	char *lines[16];
	int   lines_num = 0;

	char *fields[4];
	int   fields_num;

	apache_t *st;

	st = user_data->data;

	assert (st->url != NULL);
	/* (Assured by `config_add') */

	if (st->curl == NULL)
	{
		int status;

		status = init_host (st);
		if (status != 0)
			return (-1);
	}
	assert (st->curl != NULL);

	st->apache_buffer_fill = 0;
	if (curl_easy_perform (st->curl) != CURLE_OK)
	{
		ERROR ("apache: curl_easy_perform failed: %s",
				st->apache_curl_error);
		return (-1);
	}

	/* fallback - server_type to apache if not set at this time */
	if (st->server_type == -1)
	{
		WARNING ("apache plugin: Unable to determine server software "
				"automatically. Will assume Apache.");
		st->server_type = APACHE;
	}

	ptr = st->apache_buffer;
	saveptr = NULL;
	while ((lines[lines_num] = strtok_r (ptr, "\n\r", &saveptr)) != NULL)
	{
		ptr = NULL;
		lines_num++;

		if (lines_num >= 16)
			break;
	}

	for (i = 0; i < lines_num; i++)
	{
		fields_num = strsplit (lines[i], fields, 4);

		if (fields_num == 3)
		{
			if ((strcmp (fields[0], "Total") == 0)
					&& (strcmp (fields[1], "Accesses:") == 0))
				submit_derive ("apache_requests", "",
						atoll (fields[2]), st);
			else if ((strcmp (fields[0], "Total") == 0)
					&& (strcmp (fields[1], "kBytes:") == 0))
				submit_derive ("apache_bytes", "",
						1024LL * atoll (fields[2]), st);
		}
		else if (fields_num == 2)
		{
			if (strcmp (fields[0], "Scoreboard:") == 0)
				submit_scoreboard (fields[1], st);
			else if ((strcmp (fields[0], "BusyServers:") == 0) /* Apache 1.* */
					|| (strcmp (fields[0], "BusyWorkers:") == 0) /* Apache 2.* */)
				submit_gauge ("apache_connections", NULL, atol (fields[1]), st);
			else if ((strcmp (fields[0], "IdleServers:") == 0) /* Apache 1.x */
					|| (strcmp (fields[0], "IdleWorkers:") == 0) /* Apache 2.x */)
				submit_gauge ("apache_idle_workers", NULL, atol (fields[1]), st);
		}
	}

	st->apache_buffer_fill = 0;

	return (0);
} /* }}} int apache_read_host */
Exemplo n.º 5
0
static void submit (int cpu_num, derive_t *derives)
{

	int i = 0;

	if (!report_percent && report_by_cpu) {
		derive_t cpu_active = 0;
		for (i = 0; i < CPU_SUBMIT_ACTIVE; i++)
		{
			if (derives[i] == -1)
				continue;

			if (i != CPU_SUBMIT_IDLE)
				cpu_active += derives[i];

			submit_derive(cpu_num, i, derives[i]);
		}
		if (report_active)
			submit_derive(cpu_num, CPU_SUBMIT_ACTIVE, cpu_active);
	}
	else /* we are reporting percents */
	{
		cdtime_t cdt;
		gauge_t percent;
		gauge_t cpu_total = 0;
		gauge_t cpu_active = 0;
		gauge_t local_rates[CPU_SUBMIT_MAX];

		cpu_count++;
		if (cpu_states_grow())
			return;

		memset(local_rates, 0, sizeof(local_rates));

		cdt = cdtime();
		for (i = 0; i < CPU_SUBMIT_ACTIVE; i++) {
			value_t rate;
			int index;

			if (derives[i] == -1)
				continue;

			index = (cpu_num * CPU_SUBMIT_MAX) + i;
			if (value_to_rate(&rate, derives[i], &percents[index],
					  DS_TYPE_DERIVE, cdt) != 0) {
				local_rates[i] = -1;
				continue;
			}

			local_rates[i] = rate.gauge;
			cpu_total += rate.gauge;
			if (i != CPU_SUBMIT_IDLE)
				cpu_active += rate.gauge;
		}
		if (cpu_total == 0.0)
			return;

		if (report_active)
			local_rates[CPU_SUBMIT_ACTIVE] = cpu_active;

		for (i = 0; i < CPU_SUBMIT_MAX; i++) {
			if (local_rates[i] == -1)
				continue;

			percent = (local_rates[i] / cpu_total) * 100;
			if (report_by_cpu)
				submit_percent (cpu_num, i, percent);
			else {
				if (agg_percents[i] == -1)
					agg_percents[i] = percent;
				else
					agg_percents[i] += percent;
			}

		}
	}
}
Exemplo n.º 6
0
static int memcached_read (user_data_t *user_data)
{
  char buf[4096];
  char *fields[3];
  char *ptr;
  char *line;
  char *saveptr;
  int fields_num;

  gauge_t bytes_used = NAN;
  gauge_t bytes_total = NAN;
  gauge_t hits = NAN;
  gauge_t gets = NAN;
  gauge_t incr_hits = NAN;
  derive_t incr = 0;
  gauge_t decr_hits = NAN;
  derive_t decr = 0;
  derive_t rusage_user = 0;
  derive_t rusage_syst = 0;
  derive_t octets_rx = 0;
  derive_t octets_tx = 0;

  memcached_t *st;
  st = user_data->data;

  /* get data from daemon */
  if (memcached_query_daemon (buf, sizeof (buf), st) < 0) {
    return -1;
  }

#define FIELD_IS(cnst) \
  (((sizeof(cnst) - 1) == name_len) && (strcmp (cnst, fields[1]) == 0))

  ptr = buf;
  saveptr = NULL;
  while ((line = strtok_r (ptr, "\n\r", &saveptr)) != NULL)
  {
    int name_len;

    ptr = NULL;

    fields_num = strsplit(line, fields, 3);
    if (fields_num != 3)
      continue;

    name_len = strlen(fields[1]);
    if (name_len == 0)
      continue;

    /*
     * For an explanation on these fields please refer to
     * <https://github.com/memcached/memcached/blob/master/doc/protocol.txt>
     */

    /*
     * CPU time consumed by the memcached process
     */
    if (FIELD_IS ("rusage_user"))
    {
      rusage_user = atoll (fields[2]);
    }
    else if (FIELD_IS ("rusage_system"))
    {
      rusage_syst = atoll(fields[2]);
    }

    /*
     * Number of threads of this instance
     */
    else if (FIELD_IS ("threads"))
    {
      submit_gauge2 ("ps_count", NULL, NAN, atof (fields[2]), st);
    }

    /*
     * Number of items stored
     */
    else if (FIELD_IS ("curr_items"))
    {
      submit_gauge ("memcached_items", "current", atof (fields[2]), st);
    }

    /*
     * Number of bytes used and available (total - used)
     */
    else if (FIELD_IS ("bytes"))
    {
      bytes_used = atof (fields[2]);
    }
    else if (FIELD_IS ("limit_maxbytes"))
    {
      bytes_total = atof(fields[2]);
    }

    /*
     * Connections
     */
    else if (FIELD_IS ("curr_connections"))
    {
      submit_gauge ("memcached_connections", "current", atof (fields[2]), st);
    }
    else if (FIELD_IS ("listen_disabled_num"))
    {
      submit_derive ("memcached_connections", "listen_disabled", atof (fields[2]), st);
    }

    /*
     * Commands
     */
    else if ((name_len > 4) && (strncmp (fields[1], "cmd_", 4) == 0))
    {
      const char *name = fields[1] + 4;
      submit_derive ("memcached_command", name, atoll (fields[2]), st);
      if (strcmp (name, "get") == 0)
        gets = atof (fields[2]);
    }

    /*
     * Increment/Decrement
     */
    else if (FIELD_IS("incr_misses"))
    {
      derive_t incr_count = atoll (fields[2]);
      submit_derive ("memcached_ops", "incr_misses", incr_count, st);
      incr += incr_count;
    }
    else if (FIELD_IS ("incr_hits"))
    {
      derive_t incr_count = atoll (fields[2]);
      submit_derive ("memcached_ops", "incr_hits", incr_count, st);
      incr_hits = atof (fields[2]);
      incr += incr_count;
    }
    else if (FIELD_IS ("decr_misses"))
    {
      derive_t decr_count = atoll (fields[2]);
      submit_derive ("memcached_ops", "decr_misses", decr_count, st);
      decr += decr_count;
    }
    else if (FIELD_IS ("decr_hits"))
    {
      derive_t decr_count = atoll (fields[2]);
      submit_derive ("memcached_ops", "decr_hits", decr_count, st);
      decr_hits = atof (fields[2]);
      decr += decr_count;
    }

    /*
     * Operations on the cache, i. e. cache hits, cache misses and evictions of items
     */
    else if (FIELD_IS ("get_hits"))
    {
      submit_derive ("memcached_ops", "hits", atoll (fields[2]), st);
      hits = atof (fields[2]);
    }
    else if (FIELD_IS ("get_misses"))
    {
      submit_derive ("memcached_ops", "misses", atoll (fields[2]), st);
    }
    else if (FIELD_IS ("evictions"))
    {
      submit_derive ("memcached_ops", "evictions", atoll (fields[2]), st);
    }

    /*
     * Network traffic
     */
    else if (FIELD_IS ("bytes_read"))
    {
      octets_rx = atoll (fields[2]);
    }
    else if (FIELD_IS ("bytes_written"))
    {
      octets_tx = atoll (fields[2]);
    }
  } /* while ((line = strtok_r (ptr, "\n\r", &saveptr)) != NULL) */

  if (!isnan (bytes_used) && !isnan (bytes_total) && (bytes_used <= bytes_total))
    submit_gauge2 ("df", "cache", bytes_used, bytes_total - bytes_used, st);

  if ((rusage_user != 0) || (rusage_syst != 0))
    submit_derive2 ("ps_cputime", NULL, rusage_user, rusage_syst, st);

  if ((octets_rx != 0) || (octets_tx != 0))
    submit_derive2 ("memcached_octets", NULL, octets_rx, octets_tx, st);

  if (!isnan (gets) && !isnan (hits))
  {
    gauge_t rate = NAN;

    if (gets != 0.0)
      rate = 100.0 * hits / gets;

    submit_gauge ("percent", "hitratio", rate, st);
  }

  if (!isnan (incr_hits) && incr != 0)
  {
    gauge_t incr_rate = 100.0 * incr_hits / incr;
    submit_gauge ("percent", "incr_hitratio", incr_rate, st);
    submit_derive ("memcached_ops", "incr", incr, st);
  }

  if (!isnan (decr_hits) && decr != 0)
  {
    gauge_t decr_rate = 100.0 * decr_hits / decr;
    submit_gauge ("percent", "decr_hitratio", decr_rate, st);
    submit_derive ("memcached_ops", "decr", decr, st);
  }

  return 0;
} /* int memcached_read */
Exemplo n.º 7
0
static int apache_read_host (user_data_t *user_data) /* {{{ */
{
	char *ptr;
	char *saveptr;
	char *line;

	char *fields[4];
	int   fields_num;

	apache_t *st;

	st = user_data->data;

	int status;

	char *content_type;
	static const char *text_plain = "text/plain";

	assert (st->url != NULL);
	/* (Assured by `config_add') */

	if (st->curl == NULL)
	{
		status = init_host (st);
		if (status != 0)
			return (-1);
	}
	assert (st->curl != NULL);

	st->apache_buffer_fill = 0;
	if (curl_easy_perform (st->curl) != CURLE_OK)
	{
		ERROR ("apache: curl_easy_perform failed: %s",
				st->apache_curl_error);
		return (-1);
	}

	/* fallback - server_type to apache if not set at this time */
	if (st->server_type == -1)
	{
		WARNING ("apache plugin: Unable to determine server software "
				"automatically. Will assume Apache.");
		st->server_type = APACHE;
	}

	status = curl_easy_getinfo (st->curl, CURLINFO_CONTENT_TYPE, &content_type);
	if ((status == CURLE_OK) && (content_type != NULL) &&
	    (strncasecmp (content_type, text_plain, strlen (text_plain)) != 0))
	{
		WARNING ("apache plugin: `Content-Type' response header is not `%s' "
			"(received: `%s'). Expecting unparseable data. Please check `URL' "
			"parameter (missing `?auto' suffix ?)",
			text_plain, content_type);
	}

	ptr = st->apache_buffer;
	saveptr = NULL;
	while ((line = strtok_r (ptr, "\n\r", &saveptr)) != NULL)
	{
		ptr = NULL;
		fields_num = strsplit (line, fields, STATIC_ARRAY_SIZE (fields));

		if (fields_num == 3)
		{
			if ((strcmp (fields[0], "Total") == 0) && (strcmp (fields[1], "Accesses:") == 0))
				submit_derive ("apache_requests", "", atoll (fields[2]), st);
			else if ((strcmp (fields[0], "Total") == 0) && (strcmp (fields[1], "kBytes:") == 0))
				submit_derive ("apache_bytes", "", 1024LL * atoll (fields[2]), st);
		}
		else if (fields_num == 2)
		{
			if (strcmp (fields[0], "Scoreboard:") == 0)
				submit_scoreboard (fields[1], st);
			else if ((strcmp (fields[0], "BusyServers:") == 0) /* Apache 1.* */
					|| (strcmp (fields[0], "BusyWorkers:") == 0) /* Apache 2.* */)
				submit_gauge ("apache_connections", NULL, atol (fields[1]), st);
			else if ((strcmp (fields[0], "IdleServers:") == 0) /* Apache 1.x */
					|| (strcmp (fields[0], "IdleWorkers:") == 0) /* Apache 2.x */)
				submit_gauge ("apache_idle_workers", NULL, atol (fields[1]), st);
		}
	}

	st->apache_buffer_fill = 0;

	return (0);
} /* }}} int apache_read_host */