示例#1
0
文件: cmt.c 项目: scamicha/lmt
int
lmt_cmt_string_v1 (pctx_t ctx, char *s, int len)
{
    ListIterator itr = NULL;
    List ostlist = NULL;
    int retval = -1;
    char *name;

    if (proc_lustre_ostlist (ctx, &ostlist) < 0)
        goto done;
    int ost_count = list_count(ostlist);
    if (ost_count == 0) {
        errno = 0;
        goto done;
    }
   
    sprintf(s, "1;%d;", ost_count);
    itr = list_iterator_create (ostlist);
    while ((name = list_next (itr))) {
        int used = strlen (s);
       if (_get_ostinfo_string (ctx, name, s + used, len - used) < 0)
            goto done;
    }
    retval = 0;
    printf("CMT string: %s\n", s);
done:
    if (itr)
        list_iterator_destroy (itr);
    if (ostlist)
        list_destroy (ostlist);
    return retval;
}
示例#2
0
文件: ost.c 项目: haasken/lmt
int
lmt_ost_string_v2 (pctx_t ctx, char *s, int len)
{
    static uint64_t cpuused = 0, cputot = 0;
    ListIterator itr = NULL;
    List ostlist = NULL;
    struct utsname uts;
    double cpupct, mempct;
    int used, n, retval = -1;
    char *name;

    if (proc_lustre_ostlist (ctx, &ostlist) < 0)
        goto done;
    if (list_count (ostlist) == 0) {
        errno = 0;
        goto done;
    }
    if (uname (&uts) < 0) {
        err ("uname");
        goto done;
    }
    if (proc_stat2 (ctx, &cpuused, &cputot, &cpupct) < 0) {
        if (lmt_conf_get_proto_debug ())
            err ("error reading cpu usage from proc");
        goto done;
    }
    if (_get_mem_usage (ctx, &mempct) < 0)
        goto done;
    n = snprintf (s, len, "2;%s;%f;%f;",
                  uts.nodename,
                  cpupct,
                  mempct);
    if (n >= len) {
        if (lmt_conf_get_proto_debug ())
            msg ("string overflow");
        goto done;
    }
    itr = list_iterator_create (ostlist);
    while ((name = list_next (itr))) {
        used = strlen (s);
        if (_get_oststring_v2 (ctx, name, s + used, len - used) < 0)
            goto done;
    }
    retval = 0;
done:
    if (itr)
        list_iterator_destroy (itr);
    if (ostlist)
        list_destroy (ostlist);
    return retval;
}