Пример #1
0
static void stats_set_entity_decode (long handle, const char *name, const char *value)
{
    xmlParserCtxtPtr parser = xmlNewParserCtxt();
    if (parser)
    {
        xmlChar *decoded = xmlStringDecodeEntities (parser,
                (const xmlChar *) value, XML_SUBSTITUTE_BOTH, 0, 0, 0);
        stats_set (handle, name, (void*)decoded);
        xmlFreeParserCtxt (parser);
        xmlFree (decoded);
        return;
    }
    stats_set (handle, name, value);
}
Пример #2
0
void stats_init(struct stats_t *pStats, unsigned str, unsigned dex, unsigned con, unsigned intel, unsigned wis)
{
    strcpy(pStats->name[ST_Str], "Strength");
    strcpy(pStats->name[ST_Dex], "Dexterity");
    strcpy(pStats->name[ST_Con], "Constitution");
    strcpy(pStats->name[ST_Int], "Intelligence");
    strcpy(pStats->name[ST_Wis], "Wisdom");
    stats_set(pStats, str, dex, con, intel, wis);
}
Пример #3
0
static void collect_sysv_shm(struct stats_type *type)
{
  struct stats *stats = NULL;
  const char *path = "/proc/sysvipc/shm";
  FILE *file = NULL;
  char file_buf[4096];
  char *line_buf = NULL;
  size_t line_buf_size = 0;

  stats = get_current_stats(type, NULL);
  if (stats == NULL)
    goto out;

  file = fopen(path, "r");
  if (file == NULL) {
    ERROR("cannot open `%s': %m\n", path);
    goto out;
  }
  setvbuf(file, file_buf, _IOFBF, sizeof(file_buf));

  /* Skip header. */
  getline(&line_buf, &line_buf_size, file);

  unsigned long long mem_used = 0, segs_used = 0;

  while (getline(&line_buf, &line_buf_size, file) >= 0) {
    unsigned long long seg_size = 0;
    if (sscanf(line_buf, "%*d %*d %*o %llu", &seg_size) < 1)
      continue;

    mem_used += seg_size;
    segs_used++;
  }

  stats_set(stats, "mem_used", mem_used);
  stats_set(stats, "segs_used", segs_used);

 out:
  free(line_buf);
  if (file != NULL)
    fclose(file);
}
Пример #4
0
static void ps_collect_loadavg(struct stats *stats)
{
  const char *path = "/proc/loadavg";
  unsigned long long load[3][2];
  unsigned long long nr_running = 0, nr_threads = 0;

  memset(load, 0, sizeof(load));

  /* Ignore last_pid (sixth field). */
  if (pscanf(path, "%llu.%llu %llu.%llu %llu.%llu %llu/%llu",
             &load[0][0], &load[0][1],
             &load[1][0], &load[1][1],
             &load[2][0], &load[2][1],
             &nr_running, &nr_threads) != 8) {
    /* XXX */
    return;
  }

  stats_set(stats, "load_1",  load[0][0] * 100 + load[0][1]);
  stats_set(stats, "load_5",  load[1][0] * 100 + load[1][1]);
  stats_set(stats, "load_15", load[2][0] * 100 + load[2][1]);
  stats_set(stats, "nr_running", nr_running);
  stats_set(stats, "nr_threads", nr_threads);
}
Пример #5
0
void stats_set_args (long handle, const char *name, const char *format, ...)
{
    va_list val;
    int ret;
    stats_source_t *src_stats = (stats_source_t *)handle;
    char buf[1024];

    if (name == NULL)
        return;
    va_start (val, format);
    ret = vsnprintf (buf, sizeof (buf), format, val);
    va_end (val);

    if (ret < 0 || (unsigned int)ret >= sizeof (buf))
    {
        WARN2 ("problem with formatting %s stat %s",
                src_stats == NULL ? "global" : src_stats->source, name);
        return;
    }
    stats_set (handle, name, buf);
}
Пример #6
0
static void ps_collect_proc_stat(struct stats *stats)
{
  const char *path = "/proc/stat";
  FILE *file = NULL;
  char file_buf[4096];
  char *line = NULL;
  size_t line_size = 0;

  file = fopen(path, "r");
  if (file == NULL) {
    ERROR("cannot open `%s': %m\n", path);
    goto out;
  }
  setvbuf(file, file_buf, _IOFBF, sizeof(file_buf));

  while (getline(&line, &line_size, file) >= 0) {
    char *key, *rest = line;
    key = wsep(&rest);
    if (key == NULL || rest == NULL)
      continue;

    if (strncmp(key, "cpu", 3) == 0)
      continue;

    if (strcmp(key, "intr") == 0)
      continue;

    errno = 0;
    unsigned long long val = strtoull(rest, NULL, 0);
    if (errno == 0)
      stats_set(stats, key, val);
  }

 out:
  free(line);
  if (file != NULL)
    fclose(file);
}
Пример #7
0
void fserve_scan (time_t now)
{
    avl_node *node;
    avl_tree_wlock (fh_cache);
    node = avl_get_first (fh_cache);
    while (node)
    {
        fh_node *fh = node->key;
        node = avl_get_next (node);

        thread_mutex_lock (&fh->lock);
        if (global.running != ICE_RUNNING)
            fh->expire = 0;
        if (now == (time_t)0)
        {
            fh->expire = 0;
            thread_mutex_unlock (&fh->lock);
            continue;
        }

        if (fh->finfo.limit)
        {
            fbinfo *finfo = &fh->finfo;
            if (fh->stats == 0)
            {
                int len = strlen (finfo->mount) + 10;
                char *str = alloca (len);
                char buf[20];
                snprintf (str, len, "%s-%s", (finfo->flags & FS_FALLBACK) ? "fallback" : "file", finfo->mount);
                fh->stats = stats_handle (str);
                stats_set_flags (fh->stats, "fallback", "file", STATS_COUNTERS|STATS_HIDDEN);
                stats_set_flags (fh->stats, "outgoing_kbitrate", "0", STATS_COUNTERS|STATS_HIDDEN);
                snprintf (buf, sizeof (buf), "%d", fh->refcount);
                stats_set_flags (fh->stats, "listeners", buf, STATS_GENERAL|STATS_HIDDEN);
                snprintf (buf, sizeof (buf), "%d", fh->peak);
                stats_set_flags (fh->stats, "listener_peak", buf, STATS_GENERAL|STATS_HIDDEN);
                fh->prev_count = fh->refcount;
            }
            else
            {
                stats_lock (fh->stats, NULL);
                if (fh->prev_count != fh->refcount)
                {
                    fh->prev_count = fh->refcount;
                    stats_set_args (fh->stats, "listeners", "%ld", fh->refcount);
                    stats_set_args (fh->stats, "listener_peak", "%ld", fh->peak);
                }
            }
            if (fh->stats_update <= now)
            {
                fh->stats_update = now + 5;
                stats_set_args (fh->stats, "outgoing_kbitrate", "%ld",
                        (long)((8 * rate_avg (fh->out_bitrate))/1024));
            }
            stats_release (fh->stats);
        }

        if (fh->refcount == 0 && fh->expire >= 0 && now >= fh->expire)
        {
            DEBUG1 ("timeout of %s", fh->finfo.mount);
            if (fh->stats)
            {
                stats_lock (fh->stats, NULL);
                stats_set (fh->stats, NULL, NULL);
            }
            remove_fh_from_cache (fh);
            thread_mutex_unlock (&fh->lock);
            _delete_fh (fh);
            continue;
        }
        thread_mutex_unlock (&fh->lock);
    }
    avl_tree_unlock (fh_cache);
}
Пример #8
0
// FLOAT input
void stats_float(t_stats *x, double f)
{
	stats_set(x, f);
	stats_bang(x);
}
Пример #9
0
// INT input
void stats_int(t_stats *x, long n)
{
	stats_set(x,(double)n);
	stats_bang(x);
}
void combatant_t::increment_ct_meter(){
  set_ct_meter(m_ct_meter + stats_set().speed());
}
Пример #11
0
static void proc_collect_pid(struct stats_type *type, const char *pid)
{
  struct stats *stats = NULL;
  char path[32];
  char process[512];
  FILE *file = NULL;
  char file_buf[4096];
  char *line = NULL;
  size_t line_size = 0;

  char name[16];
  char cmask[512];
  char mmask[32];

  TRACE("pid %s\n", pid);

  snprintf(path, sizeof(path), "/proc/%s/status", pid);
  file = fopen(path, "r");
  
  if (file == NULL) {
    ERROR("cannot open `%s': %m\n",path);
    goto out;
  }
  setvbuf(file, file_buf, _IOFBF, sizeof(file_buf));
  
  while (getline(&line, &line_size, file) >= 0) {
    char *key, *rest = line;
    key = wsep(&rest);
    
    if (key == NULL || rest == NULL)
	continue;

    rest[strlen(rest) - 1] = '\0';
    if (strcmp(key, "Name:") == 0) {     
      if (!strcmp("bash", rest) || !strcmp("ssh", rest) || 
	  !strcmp("sshd", rest) || !strcmp("metacity", rest))
	goto out;
      
      strcpy(name, rest);
    }
    else if (strcmp(key, "Cpus_allowed_list:") == 0) {
      strcpy(cmask, rest);
    }
    else if (strcmp(key, "Mems_allowed_list:") == 0) {
      strcpy(mmask, rest);
    }
  }

  snprintf(process, sizeof(process), "%s/%s/%s/%s", name, pid, cmask, mmask);
  stats = get_current_stats(type, process);       
  if (stats == NULL)
    goto out;

  fseek(file, 0, SEEK_SET);
  while (getline(&line, &line_size, file) >= 0) {
    char *key, *rest = line;
    key = wsep(&rest);
    
    if (key == NULL || rest == NULL)
	continue;

    errno = 0;
    key[strlen(key) - 1] = '\0';  
    unsigned long long val = strtoull(rest, NULL, 0);
    if (errno == 0)
      stats_set(stats, key, val);
  }
  
 out:
  free(line);
  if (file != NULL)
    fclose(file);

}
Пример #12
0
static void collect_mdc_fs(struct stats *stats, const char *d_name)
{
  char *path = NULL;
  FILE *file = NULL;
  char file_buf[4096];
  char *line_buf = NULL;
  size_t line_buf_size = 0;

  if (asprintf(&path, "%s/%s/stats", MDC_DIR_PATH, d_name) < 0) {
    ERROR("cannot create path: %m\n");
    goto out;
  }

  file = fopen(path, "r");
  if (file == NULL) {
    ERROR("cannot open `%s': %m\n", path);
    goto out;
  }
  setvbuf(file, file_buf, _IOFBF, sizeof(file_buf));

  // $ cat /proc/fs/lustre/mdc/work-MDT0000-mdc-ffff8104435c8c00/stats
  // snapshot_time             1315505833.280916 secs.usecs
  // req_waittime              1885503 samples [usec] 32 4826358 908745020 670751020176306
  // req_active                1885503 samples [reqs] 1 357 2176198 17811836
  // mds_getattr               231 samples [usec] 50 5735 45029 60616599
  // mds_close                 312481 samples [usec] 38 356200 47378914 142563767708
  // mds_readpage              12187 samples [usec] 80 16719 3185676 4923626688
  // mds_connect               1 samples [usec] 302 302 302 91204
  // mds_getstatus             1 samples [usec] 273 273 273 74529
  // mds_statfs                30 samples [usec] 130 444 7765 2137505
  // mds_sync                  262 samples [usec] 3042 4826358 33767303 73003166559545
  // mds_quotactl              6030 samples [usec] 466 1667578 23448377 4610731893889
  // ldlm_cancel               169832 samples [usec] 32 8257 25752413 4873947759
  // obd_ping                  112820 samples [usec] 40 1543848 548167082 592878039802964

  /* Skip snapshot. */
  getline(&line_buf, &line_buf_size, file);

  while (getline(&line_buf, &line_buf_size, file) >= 0) {
    char *line = line_buf;
    char *key = wsep(&line);
    if (key == NULL || line == NULL)
      continue;

    unsigned long long count = 0, sum = 0;
    if (sscanf(line, "%llu samples %*s %*u %*u %llu", &count, &sum) != 2)
      continue;

    if (strcmp(key, "req_waittime") == 0) {
      stats_set(stats, "reqs", count);
      stats_set(stats, "wait", sum);
    } else {
      stats_set(stats, key, count);
    }
  }

 out:
  free(line_buf);
  if (file != NULL)
    fclose(file);
  free(path);
}
Пример #13
0
static void collect_hca_port(struct stats *stats, char *hca_name, int hca_port)
{
  struct ibmad_port *mad_port = NULL;
  int mad_timeout = 15;
  int mad_classes[] = { IB_SMI_DIRECT_CLASS, IB_PERFORMANCE_CLASS, };

  mad_port = mad_rpc_open_port(hca_name, hca_port, mad_classes, 2);
  if (mad_port == NULL) {
    ERROR("cannot open MAD port for HCA `%s' port %d\n", hca_name, hca_port);
    goto out;
  }

  /* For reasons we don't understand, PMA queries can only be LID
     addressed.  But we don't know the LID of the switch to which the
     HCA is connected, so we send a SMP on the directed route 0,1 and
     ask the port to identify itself. */

  ib_portid_t sw_port_id = {
    .drpath = {
      .cnt = 1,
      .p = { 0, 1, },
    },
  };

  uint8_t sw_info[64];
  memset(sw_info, 0, sizeof(sw_info));
  if (smp_query_via(sw_info, &sw_port_id, IB_ATTR_PORT_INFO, 0, mad_timeout, mad_port) == NULL) {
    ERROR("cannot query port info: %m\n");
    goto out;
  }

  int sw_lid, sw_port;
  mad_decode_field(sw_info, IB_PORT_LID_F, &sw_lid);
  mad_decode_field(sw_info, IB_PORT_LOCAL_PORT_F, &sw_port);
  printf("IB_ATTR_PORT_INFO(drpath.p = {0, 1}): switch_lid %d, switch_local_port %d\n",
          sw_lid, sw_port);

  sw_port_id.lid = sw_lid;

  uint8_t sw_pma[1024];
  memset(sw_pma, 0, sizeof(sw_pma));
  if (pma_query_via(sw_pma, &sw_port_id, sw_port, mad_timeout, IB_GSI_PORT_COUNTERS_EXT, mad_port) == NULL) {
    ERROR("cannot query performance counters of switch LID %d, port %d: %m\n", sw_lid, sw_port);
    goto out;
  }

  uint64_t sw_rx_bytes, sw_rx_packets, sw_tx_bytes, sw_tx_packets;
  mad_decode_field(sw_pma, IB_PC_EXT_RCV_BYTES_F, &sw_rx_bytes);
  mad_decode_field(sw_pma, IB_PC_EXT_RCV_PKTS_F,  &sw_rx_packets);
  mad_decode_field(sw_pma, IB_PC_EXT_XMT_BYTES_F, &sw_tx_bytes);
  mad_decode_field(sw_pma, IB_PC_EXT_XMT_PKTS_F,  &sw_tx_packets);

  TRACE("sw_rx_bytes %lu, sw_rx_packets %lu, sw_tx_bytes %lu, sw_tx_packets %lu\n",
        sw_rx_bytes, sw_rx_packets, sw_tx_bytes, sw_tx_packets);

  /* The transposition of tx and rx is intentional: the switch port
     receives what we send, and conversely. */
  stats_set(stats, "rx_bytes",   sw_tx_bytes);
  stats_set(stats, "rx_packets", sw_tx_packets);
  stats_set(stats, "tx_bytes",   sw_rx_bytes);
  stats_set(stats, "tx_packets", sw_rx_packets);

 out:
  if (mad_port != NULL)
    mad_rpc_close_port(mad_port);
}
Пример #14
0
static int command_metadata (client_t *client, source_t *source, int response)
{
    const char *song, *title, *artist, *artwork, *charset, *url;
    format_plugin_t *plugin;
    xmlDocPtr doc;
    xmlNodePtr node;
    int same_ip = 1;

    doc = xmlNewDoc(XMLSTR("1.0"));
    node = xmlNewDocNode(doc, NULL, XMLSTR("iceresponse"), NULL);
    xmlDocSetRootElement(doc, node);

    DEBUG0("Got metadata update request");

    COMMAND_OPTIONAL(client, "song", song);
    COMMAND_OPTIONAL(client, "title", title);
    COMMAND_OPTIONAL(client, "artist", artist);
    COMMAND_OPTIONAL(client, "url", url);
    COMMAND_OPTIONAL(client, "artwork", artwork);
    COMMAND_OPTIONAL(client, "charset", charset);

    plugin = source->format;
    if (source_running (source))
        if (strcmp (client->connection.ip, source->client->connection.ip) != 0)
            if (response == RAW && connection_check_admin_pass (client->parser) == 0)
                same_ip = 0;

	/* Update stream metadata if needed */
	if (same_ip) {
		static const struct {
			const char		*param;
			const char		*stat_name;
			const char		*hdr[3];
		} fwd[] = {
			{"xstreamname",			"server_name", 			{"ice-name",		"icy-name",			"x-audiocast-name"}},
			{"xstreamdesc",			"server_description",	{"ice-description",	"icy-description",	"x-audiocast-description"}},
			{"xstreamurl",			"server_url",			{"ice-url",			"icy-url",			"x-audiocast-url"}},
			{"xstreamgenre",		"genre",				{"ice-genre",		"icy-genre",		"x-audiocast-genre"}}
		};
		unsigned i;
		for (i = 0; i < sizeof(fwd) / sizeof(*fwd); i++) {
			const char *value;
			unsigned j;
			COMMAND_OPTIONAL(client, fwd[i].param, value);
			if (value && *value) {
				value = auto_recode(value);
				if (source->format->charset)
					stats_set_conv (source->stats, fwd[i].stat_name, value, source->format->charset);
				else
					stats_set (source->stats, fwd[i].stat_name, value);
			} else if (value) {
				stats_set (source->stats, fwd[i].stat_name, NULL);
			}
			for (j = 0; j < 3; j++) {
				if (j == 0 && value && *value) {
					httpp_setvar(source->format->parser, fwd[i].hdr[j], value);
				} else if (value && !*value) {
					httpp_deletevar(source->format->parser, fwd[i].hdr[j]);
				}
			}
		}

	}

    do
    {
        if (same_ip == 0 || plugin == NULL)
            break;
		/* Charset detection (if none specified) */
		if (!charset) {
			const char *r;
			int len;
			charset = "UTF8";
#define CCONV(s) \
			if (s && (r = auto_recode(s))) { \
				len = strlen(r); \
				s = alloca(len + 1); \
				memcpy((char*)s, r, len + 1); \
			}
			CCONV(title);
			CCONV(song);
			CCONV(artist);
		}
		/* Now send prepared metadata */
        if (artwork)
            stats_event (source->mount, "artwork", artwork);
        if (plugin->set_tag)
        {
            if (url)
            {
                plugin->set_tag (plugin, "url", url, charset);
                INFO2 ("Metadata url on %s set to \"%s\"", source->mount, url);
            }
            if (song)
            {
                plugin->set_tag (plugin, "artist", NULL, NULL);
                plugin->set_tag (plugin, "title", song, charset);
                INFO2("Metadata song on %s set to \"%s\"", source->mount, song);
            }
            if (artist)
            {
                plugin->set_tag (plugin, "artist", artist, charset);
                INFO2 ("Metadata artist on %s changed to \"%s\"", source->mount, artist);
            }
            if (title)
            {
                plugin->set_tag (plugin, "title", title, charset);
                INFO2 ("Metadata title on %s changed to \"%s\"", source->mount, title);
            }
            /* updates are now done, let them be pushed into the stream */
            plugin->set_tag (plugin, NULL, NULL, NULL);
        }
        else
        {
            break;
        }
        thread_mutex_unlock (&source->lock);
        xmlNewChild(node, NULL, XMLSTR("message"), XMLSTR("Metadata update successful"));
        xmlNewChild(node, NULL, XMLSTR("return"), XMLSTR("1"));
        return admin_send_response(doc, client, response, "response.xsl");

    } while (0);
    thread_mutex_unlock (&source->lock);
    xmlNewChild(node, NULL, XMLSTR("message"), 
            XMLSTR("Mountpoint will not accept this URL update"));
    xmlNewChild(node, NULL, XMLSTR("return"), XMLSTR("1"));
    return admin_send_response(doc, client, response, "response.xsl");
}