Esempio n. 1
0
static void statsd_config_free(statsd_config_t *conf)
{
  void *key = NULL;
  void *value = NULL;

  if (NULL == conf)
    return;

  while (c_avl_pick (conf->metrics_tree, &key, &value) == 0) {
    sfree (key);
    statsd_metric_free (value);
  }

  c_avl_destroy(conf->metrics_tree);

  sfree(conf->node_name);
  sfree(conf->host);
  sfree(conf->service);
  sfree(conf->timer_percentile);
  sfree(conf->global_prefix);
  sfree(conf->counter_prefix);
  sfree(conf->timer_prefix);
  sfree(conf->gauge_prefix);
  sfree(conf->set_prefix);
  sfree(conf->global_postfix);

  sfree(conf);
  conf = NULL;

  return;
}
Esempio n. 2
0
static int statsd_shutdown (void) /* {{{ */
{
  void *key;
  void *value;

  pthread_mutex_lock (&metrics_lock);

  if (network_thread_running)
  {
    network_thread_shutdown = 1;
    pthread_kill (network_thread, SIGTERM);
    pthread_join (network_thread, /* retval = */ NULL);
  }
  network_thread_running = 0;

  while (c_avl_pick (metrics_tree, &key, &value) == 0)
  {
    sfree (key);
    sfree (value);
  }
  c_avl_destroy (metrics_tree);
  metrics_tree = NULL;

  sfree (conf_node);
  sfree (conf_service);

  pthread_mutex_unlock (&metrics_lock);

  return (0);
} /* }}} int statsd_shutdown */
Esempio n. 3
0
static void statsd_metric_free (statsd_metric_t *metric) /* {{{ */
{
  if (metric == NULL)
    return;

  if (metric->latency != NULL)
  {
    latency_counter_destroy (metric->latency);
    metric->latency = NULL;
  }

  if (metric->set != NULL)
  {
    void *key;
    void *value;

    while (c_avl_pick (metric->set, &key, &value) == 0)
    {
      sfree (key);
      assert (value == NULL);
    }

    c_avl_destroy (metric->set);
    metric->set = NULL;
  }

  sfree (metric);
} /* }}} void statsd_metric_free */
Esempio n. 4
0
void lookup_destroy(lookup_t *obj) /* {{{ */
{
  int status;

  if (obj == NULL)
    return;

  while (42) {
    char *type = NULL;
    by_type_entry_t *by_type = NULL;

    status = c_avl_pick(obj->by_type_tree, (void *)&type, (void *)&by_type);
    if (status != 0)
      break;

    DEBUG("utils_vl_lookup: lookup_destroy: Destroying type \"%s\".", type);
    sfree(type);
    lu_destroy_by_type(obj, by_type);
  }

  c_avl_destroy(obj->by_type_tree);
  obj->by_type_tree = NULL;

  sfree(obj);
} /* }}} void lookup_destroy */
Esempio n. 5
0
static void lu_destroy_by_type(lookup_t *obj, /* {{{ */
                               by_type_entry_t *by_type) {

  while (42) {
    char *plugin = NULL;
    user_class_list_t *user_class_list = NULL;
    int status;

    status = c_avl_pick(by_type->by_plugin_tree, (void *)&plugin,
                        (void *)&user_class_list);
    if (status != 0)
      break;

    DEBUG("utils_vl_lookup: lu_destroy_by_type: Destroying plugin \"%s\".",
          plugin);
    sfree(plugin);
    lu_destroy_user_class_list(obj, user_class_list);
  }

  c_avl_destroy(by_type->by_plugin_tree);
  by_type->by_plugin_tree = NULL;

  lu_destroy_user_class_list(obj, by_type->wildcard_plugin_list);
  by_type->wildcard_plugin_list = NULL;

  sfree(by_type);
} /* }}} int lu_destroy_by_type */
void
free_data_tree (c_avl_tree_t *t) {
	void *key;
	void *value;
	void *tkey;
	c_avl_tree_t *tt;
	assert(t != NULL);

	while (c_avl_pick (t, &tkey, (void *)&tt) == 0) {
		free(tkey);
		while (c_avl_pick (tt, &key, &value) == 0) {
			free (key);
			free (value);
		}
		c_avl_destroy (tt);
	}
	c_avl_destroy (t);
}
Esempio n. 7
0
static void zone_submit_values(c_avl_tree_t *tree) {
  char zonename[ZONENAME_MAX];
  zoneid_t *zoneid = NULL;
  zone_stats_t *stats = NULL;

  while (c_avl_pick(tree, (void **)&zoneid, (void **)&stats) == 0) {
    if (getzonenamebyid(*zoneid, zonename, sizeof(zonename)) == -1) {
      WARNING("zone plugin: error retrieving zonename");
    } else {
      zone_submit_value(zonename, (gauge_t)FRC2PCT(stats->pctcpu));
    }
    free(stats);
    free(zoneid);
  }
  c_avl_destroy(tree);
}
Esempio n. 8
0
/* Must hold metrics_lock when calling this function. */
static int statsd_metric_clear_set_unsafe(statsd_metric_t *metric) /* {{{ */
{
  void *key;
  void *value;

  if ((metric == NULL) || (metric->type != STATSD_SET))
    return EINVAL;

  if (metric->set == NULL)
    return 0;

  while (c_avl_pick(metric->set, &key, &value) == 0) {
    sfree(key);
    sfree(value);
  }

  return 0;
} /* }}} int statsd_metric_clear_set_unsafe */
Esempio n. 9
0
static void cj_tree_free (c_avl_tree_t *tree) /* {{{ */
{
    char *name;
    void *value;

    while (c_avl_pick (tree, (void *) &name, (void *) &value) == 0)
    {
        cj_key_t *key = (cj_key_t *)value;

        if (CJ_IS_KEY(key))
            cj_key_free (key);
        else
            cj_tree_free ((c_avl_tree_t *)value);

        sfree (name);
    }

    c_avl_destroy (tree);
} /* }}} void cj_tree_free */
Esempio n. 10
0
static int ethstat_shutdown (void)
{
  void *key = NULL;
  void *value = NULL;

  if (value_map == NULL)
    return (0);

  while (c_avl_pick (value_map, &key, &value) == 0)
  {
    sfree (key);
    sfree (value);
  }

  c_avl_destroy (value_map);
  value_map = NULL;

  return (0);
}
Esempio n. 11
0
/*
 * Private functions
 */
static void fbh_free_tree (c_avl_tree_t *tree) /* {{{ */
{
  int status;

  if (tree == NULL)
    return;

  while (42)
  {
    char *key = NULL;
    char *value = NULL;

    status = c_avl_pick (tree, (void *) &key, (void *) &value);
    if (status != 0)
      break;

    free (key);
    free (value);
  }

  c_avl_destroy (tree);
} /* }}} void fbh_free_tree */
static int
basic_aggregator_read_config_file_and_update_aggregator_definitions(char *filename) {
		oconfig_item_t *ci;
		int status = 0;
		int i;
		int nb_aggregators = 0;
		char *k;
		aggregator_definition_t *agg;

		ci = oconfig_parse_file (filename);
		if(NULL == ci) {
				WARNING (OUTPUT_PREFIX_STRING "Failed to read default config ('%s').", filename);
				return(-1);
		}

		/* Free the aggregator tree : it will be reconfigured from scratch from the file */
		if(NULL != aggregator) {
				while (c_avl_pick (aggregator, (void *)&k, (void *)&agg) == 0) {
						aggregator_definition_free(agg,1);
				}
				c_avl_destroy (aggregator);
		}
		aggregator = c_avl_create((void *) strcmp);
		if(NULL == aggregator) return (-1);

		/* Parse the configuration file */
		for (i = 0; i < ci->children_num; i++)
		{
				oconfig_item_t *child = ci->children + i;

				if (strcasecmp ("aggregator", child->key) == 0) {
						agg = basic_aggregator_config_aggregator (child);
						if(agg) {
								int r;
								r = c_avl_insert(aggregator, agg->resultvalue, agg);
								if(r != 0) {
										ERROR (OUTPUT_PREFIX_STRING "Could not insert aggregator '%s' in the list of aggregators (duplicate ?)",  agg->resultvalue);
										aggregator_definition_free(agg,1);
								} else {
										nb_aggregators++;
								}
						}
				} else if (strcasecmp ("database", child->key) == 0) {
						if ((child->values_num < 1) || (child->values[0].type != OCONFIG_TYPE_STRING)) {
								WARNING (OUTPUT_PREFIX_STRING "`database' needs 1 string arguments.");
								status = -1;
						} else {
								if (strcasecmp ("mysql", child->values[0].value.string) == 0) {
										/* Not implemented yet
										   basic_aggregator_config_mysql_database (child);
										   */
								} else if (strcasecmp ("postgresql", child->values[0].value.string) == 0) {

										/* Not supported yet */
								} else {
										WARNING (OUTPUT_PREFIX_STRING "'%s' is not a known type for `database'.", ci->values[0].value.string);
										status = -1;
								}
						}
				} else
						WARNING (OUTPUT_PREFIX_STRING "Option \"%s\" not allowed here.",
										child->key);
		}

		INFO(OUTPUT_PREFIX_STRING "Registered %d aggregators", nb_aggregators);
		return(status);
}
Esempio n. 13
0
static int ethstat_read_interface(char *device) {
  int fd;
  struct ethtool_gstrings *strings;
  struct ethtool_stats *stats;
  size_t n_stats;
  size_t strings_size;
  size_t stats_size;
  int status;

  fd = socket(AF_INET, SOCK_DGRAM, /* protocol = */ 0);
  if (fd < 0) {
    char errbuf[1024];
    ERROR("ethstat plugin: Failed to open control socket: %s",
          sstrerror(errno, errbuf, sizeof(errbuf)));
    return 1;
  }

  struct ethtool_drvinfo drvinfo = {.cmd = ETHTOOL_GDRVINFO};

  struct ifreq req = {.ifr_data = (void *)&drvinfo};

  sstrncpy(req.ifr_name, device, sizeof(req.ifr_name));

  status = ioctl(fd, SIOCETHTOOL, &req);
  if (status < 0) {
    char errbuf[1024];
    close(fd);
    ERROR("ethstat plugin: Failed to get driver information "
          "from %s: %s",
          device, sstrerror(errno, errbuf, sizeof(errbuf)));
    return -1;
  }

  n_stats = (size_t)drvinfo.n_stats;
  if (n_stats < 1) {
    close(fd);
    ERROR("ethstat plugin: No stats available for %s", device);
    return -1;
  }

  strings_size = sizeof(struct ethtool_gstrings) + (n_stats * ETH_GSTRING_LEN);
  stats_size = sizeof(struct ethtool_stats) + (n_stats * sizeof(uint64_t));

  strings = malloc(strings_size);
  stats = malloc(stats_size);
  if ((strings == NULL) || (stats == NULL)) {
    close(fd);
    sfree(strings);
    sfree(stats);
    ERROR("ethstat plugin: malloc failed.");
    return -1;
  }

  strings->cmd = ETHTOOL_GSTRINGS;
  strings->string_set = ETH_SS_STATS;
  strings->len = n_stats;
  req.ifr_data = (void *)strings;
  status = ioctl(fd, SIOCETHTOOL, &req);
  if (status < 0) {
    char errbuf[1024];
    close(fd);
    free(strings);
    free(stats);
    ERROR("ethstat plugin: Cannot get strings from %s: %s", device,
          sstrerror(errno, errbuf, sizeof(errbuf)));
    return -1;
  }

  stats->cmd = ETHTOOL_GSTATS;
  stats->n_stats = n_stats;
  req.ifr_data = (void *)stats;
  status = ioctl(fd, SIOCETHTOOL, &req);
  if (status < 0) {
    char errbuf[1024];
    close(fd);
    free(strings);
    free(stats);
    ERROR("ethstat plugin: Reading statistics from %s failed: %s", device,
          sstrerror(errno, errbuf, sizeof(errbuf)));
    return -1;
  }

  for (size_t i = 0; i < n_stats; i++) {
    char *stat_name;

    stat_name = (void *)&strings->data[i * ETH_GSTRING_LEN];
    /* Remove leading spaces in key name */
    while (isspace((int)*stat_name))
      stat_name++;

    DEBUG("ethstat plugin: device = \"%s\": %s = %" PRIu64, device, stat_name,
          (uint64_t)stats->data[i]);
    ethstat_submit_value(device, stat_name, (derive_t)stats->data[i]);
  }

  close(fd);
  sfree(strings);
  sfree(stats);

  return 0;
} /* }}} ethstat_read_interface */

static int ethstat_read(void) {
  for (size_t i = 0; i < interfaces_num; i++)
    ethstat_read_interface(interfaces[i]);

  return 0;
}

static int ethstat_shutdown(void) {
  void *key = NULL;
  void *value = NULL;

  if (value_map == NULL)
    return 0;

  while (c_avl_pick(value_map, &key, &value) == 0) {
    sfree(key);
    sfree(value);
  }

  c_avl_destroy(value_map);
  value_map = NULL;

  return 0;
}