Exemplo n.º 1
0
int
main (int argc, char **argv)
{
	if (argc < 2) {
		g_printerr ("Usage:i\n");
		g_printerr (" %s addr IP:PORT\n", argv[0]);
		g_printerr (" %s cid  OIOURL\n", argv[0]);
		g_printerr (" %s hash [PREFIX]\n", argv[0]);
		g_printerr (" %s stat [path]...\n", argv[0]);
		return 2;
	}
	oio_ext_set_random_reqid ();

	if (!strcmp("addr", argv[1])) {
		for (int i=2; i<argc ;++i)
			_dump_addr (argv[i]);
		return 0;
	} else if (!strcmp("cid", argv[1])) {
		for (int i=2; i<argc ;++i)
			_dump_cid (argv[i]);
		return 0;
	} else if (!strcmp("hash", argv[1])) {
		if (argc < 2 || argc > 4) {
			g_printerr ("Usage: %s hash ACCOUNT [PREFIX]\n", argv[0]);
			return 1;
		}
		_same_hash (argv[2], argc==4 ? argv[3] : "");
		return 0;
	} else if (!strcmp("stat", argv[1])) {
		_sysstat (argv+2);
		return 0;
	}

	return 1;
}
Exemplo n.º 2
0
Arquivo: lmtmetric.c Projeto: LLNL/lmt
int
main (int argc, char *argv[])
{
    pctx_t ctx;
    char buf[CEREBRO_MAX_DATA_STRING_LEN];
    char *proc_root = "/proc";
    char *metric = NULL;
    unsigned long update_period = 0;
    int c, n = 0;

    err_init (argv[0]);
    lmt_conf_init (0, NULL);
    lmt_conf_set_proto_debug (1);

    optind = 0;
    opterr = 0;
    while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) {
        switch (c) {
        case 'm':   /* --metric NAME */
            metric = optarg;
            break;
        case 'r':   /* --proc-root DIR */
            proc_root = optarg;
            break;
        case 't':   /* --update-period SECS */
            update_period = strtoul (optarg, NULL, 10);
            break;
        default:
            usage ();
        }
    }
    if (optind < argc)
        usage();
    if (metric && strcmp (metric, "ost") && strcmp (metric, "mdt")
            && strcmp (metric, "osc") && strcmp (metric, "router")
            && strcmp (metric, "sysstat"))
        usage();
    if (!metric)
        metric = "sysstat";

    if (!(ctx = proc_create (proc_root)))
        err_exit ("proc_create");

    do {
        errno = 0;
        if (!strcmp (metric, "sysstat"))
            n = _sysstat (ctx, buf, sizeof (buf));
        else if (!strcmp (metric, "ost"))
            n = lmt_ost_string_v2 (ctx, buf, sizeof (buf));
        else if (!strcmp (metric, "mdt"))
            n = lmt_mdt_string_v2 (ctx, buf, sizeof (buf));
        else if (!strcmp (metric, "osc"))
            n = lmt_osc_string_v1 (ctx, buf, sizeof (buf));
        else if (!strcmp (metric, "router"))
            n = lmt_router_string_v1 (ctx, buf, sizeof (buf));
        if (n < 0 && errno == 0)
            msg ("%s metric information unavailable", metric);
        else if (n < 0)
            err ("%s metric", metric);
        else
            printf ("%s: %s\n", metric, buf);
        if (update_period > 0)
            sleep (update_period);
    } while (update_period > 0);

    proc_destroy (ctx);
    exit (0);
}