Ejemplo n.º 1
0
static int mc_handle_metadata_msg (Ganglia_metadata_msg *msg) /* {{{ */
{
  switch (msg->id)
  {
    case gmetadata_full:
    {
      Ganglia_metadatadef msg_meta;
      staging_entry_t *se;
      const data_set_t *ds;
      metric_map_t *map;

      msg_meta = msg->Ganglia_metadata_msg_u.gfull;

      if (msg_meta.metric.tmax == 0)
        return (-1);

      map = metric_lookup (msg_meta.metric_id.name);
      if (map == NULL)
      {
        DEBUG ("gmond plugin: Not handling meta data %s.",
            msg_meta.metric_id.name);
        return (0);
      }

      ds = plugin_get_ds (map->type);
      if (ds == NULL)
      {
        WARNING ("gmond plugin: Could not find data set %s.", map->type);
        return (-1);
      }

      DEBUG ("gmond plugin: Received meta data for %s/%s.",
          msg_meta.metric_id.host, msg_meta.metric_id.name);

      pthread_mutex_lock (&staging_lock);
      se = staging_entry_get (msg_meta.metric_id.host,
          msg_meta.metric_id.name,
          map->type, map->type_instance,
          ds->ds_num);
      if (se != NULL)
        se->vl.interval = TIME_T_TO_CDTIME_T (msg_meta.metric.tmax);
      pthread_mutex_unlock (&staging_lock);

      if (se == NULL)
      {
        ERROR ("gmond plugin: staging_entry_get failed.");
        return (-1);
      }

      break;
    }

    default:
    {
      return (-1);
    }
  }

  return (0);
} /* }}} int mc_handle_metadata_msg */
Ejemplo n.º 2
0
static int staging_entry_update(const char *host, const char *name, /* {{{ */
                                const char *type, const char *type_instance,
                                size_t ds_index, int ds_type, value_t value) {
  const data_set_t *ds;
  staging_entry_t *se;

  ds = plugin_get_ds(type);
  if (ds == NULL) {
    ERROR("gmond plugin: Looking up type %s failed.", type);
    return (-1);
  }

  if (ds->ds_num <= ds_index) {
    ERROR("gmond plugin: Invalid index %zu: %s has only %zu data source(s).",
          ds_index, ds->type, ds->ds_num);
    return (-1);
  }

  pthread_mutex_lock(&staging_lock);

  se = staging_entry_get(host, name, type, type_instance, ds->ds_num);
  if (se == NULL) {
    pthread_mutex_unlock(&staging_lock);
    ERROR("gmond plugin: staging_entry_get failed.");
    return (-1);
  }
  if (se->vl.values_len != ds->ds_num) {
    pthread_mutex_unlock(&staging_lock);
    return (-1);
  }

  if (ds_type == DS_TYPE_COUNTER)
    se->vl.values[ds_index].counter += value.counter;
  else if (ds_type == DS_TYPE_GAUGE)
    se->vl.values[ds_index].gauge = value.gauge;
  else if (ds_type == DS_TYPE_DERIVE)
    se->vl.values[ds_index].derive += value.derive;
  else if (ds_type == DS_TYPE_ABSOLUTE)
    se->vl.values[ds_index].absolute = value.absolute;
  else
    assert(23 == 42);

  se->flags |= (0x01 << ds_index);

  /* Check if all data sources have been set. If not, return here. */
  if (se->flags != ((0x01 << se->vl.values_len) - 1)) {
    pthread_mutex_unlock(&staging_lock);
    return (0);
  }

  /* Check if the interval of this metric is known. If not, request meta data
   * and return. */
  if (se->vl.interval == 0) {
    /* No meta data has been received for this metric yet. */
    se->flags = 0;
    pthread_mutex_unlock(&staging_lock);

    request_meta_data(host, name);
    return (0);
  }

  plugin_dispatch_values(&se->vl);

  se->flags = 0;
  pthread_mutex_unlock(&staging_lock);

  return (0);
} /* }}} int staging_entry_update */
Ejemplo n.º 3
0
static int staging_entry_update (const char *host, const char *name, /* {{{ */
    const char *type, const char *type_instance,
    size_t ds_index, int ds_type, value_t value)
{
  const data_set_t *ds;
  staging_entry_t *se;

  ds = plugin_get_ds (type);
  if (ds == NULL)
  {
    ERROR ("gmond plugin: Looking up type %s failed.", type);
    return (-1);
  }

  if (ds->ds_num <= ds_index)
  {
    ERROR ("gmond plugin: Invalid index %zu: %s has only %zu data source(s).",
        ds_index, ds->type, ds->ds_num);
    return (-1);
  }

  pthread_mutex_lock (&staging_lock);

  se = staging_entry_get (host, name, type, type_instance, ds->ds_num);
  if (se == NULL)
  {
    pthread_mutex_unlock (&staging_lock);
    ERROR ("gmond plugin: staging_entry_get failed.");
    return (-1);
  }
  if (se->vl.values_len != ds->ds_num)
  {
    pthread_mutex_unlock (&staging_lock);
    return (-1);
  }

  if (ds_type == DS_TYPE_COUNTER)
    se->vl.values[ds_index].counter += value.counter;
  else if (ds_type == DS_TYPE_GAUGE)
    se->vl.values[ds_index].gauge = value.gauge;
  else if (ds_type == DS_TYPE_DERIVE)
    se->vl.values[ds_index].derive += value.derive;
  else if (ds_type == DS_TYPE_ABSOLUTE)
    se->vl.values[ds_index].absolute = value.absolute;
  else
    assert (23 == 42);

  se->flags |= (0x01 << ds_index);

  /* Check if all values have been set and submit if so. */
  if (se->flags == ((0x01 << se->vl.values_len) - 1))
  {
    /* `staging_lock' is unlocked in `staging_entry_submit'. */
    staging_entry_submit (host, name, se);
  }
  else
  {
    pthread_mutex_unlock (&staging_lock);
  }

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