Beispiel #1
0
Datei: ost.c Projekt: 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;
}
Beispiel #2
0
Datei: mdt.c Projekt: LaHaine/lmt
int
lmt_mdt_string_v1 (pctx_t ctx, char *s, int len)
{
    static uint64_t cpuused = 0, cputot = 0;
    struct utsname uts;
    int n, used, retval = -1;
    double cpupct, mempct;
    List mdtlist = NULL;
    ListIterator itr = NULL;
    char *name;

    if (proc_lustre_mdtlist (ctx, &mdtlist) < 0)
        goto done;
    if (list_count (mdtlist) == 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, "1;%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 (mdtlist);
    while ((name = list_next (itr))) {
        used = strlen (s);
        if (_get_mdtstring (ctx, name, s + used, len - used) < 0)
            goto done;
    }
    if (s[strlen (s) - 1] == ';') /* chomp traling semicolon */
        s[strlen (s) - 1] = '\0';
    retval = 0;
done:
    if (itr)
        list_iterator_destroy (itr);
    if (mdtlist)
        list_destroy (mdtlist);
    return retval;
}
Beispiel #3
0
static int
_sysstat (pctx_t ctx, char *buf, int len)
{
    static uint64_t cpuusage = 0, cputot = 0;
    double cpupct, mempct;
    uint64_t ktot, kfree;
    int ret = -1;

    if (proc_stat2 (ctx, &cpuusage, &cputot, &cpupct) < 0)
        goto done;
    if (proc_meminfo (ctx, &ktot, &kfree) < 0)
        goto done;
    mempct = ((double)(ktot - kfree) / (double)(ktot)) * 100.0;
    snprintf (buf, len, "cpu_util: %.2f%% mem_util: %.2f%%", cpupct, mempct);
    ret = 0;
done:
    return ret;
}
Beispiel #4
0
int
lmt_client_string (pctx_t ctx, char *s, int len)
{
    static uint64_t cpuused = 0, cputot = 0;
    struct utsname uts;
    double cpupct, mempct;
    int n, retval = -1, lustre_mounted = 0;
    hash_t stats_hash = NULL;
    uint64_t read_bytes = 0, write_bytes = 0;
    uint64_t read_count = 0, write_count = 0;
    uint64_t open_count = 0, close_count = 0;
    uint64_t getattr_count = 0, setattr_count = 0;
    uint64_t seek_count = 0, fsync_count = 0;
    uint64_t dhits_count = 0, dmisses_count = 0;
    char *path_base = "/proc/fs/lustre/llite", stats_file[256], name[256];
    DIR  *d = NULL;
    struct dirent *dir;

    d = opendir(path_base);
    if (d != NULL) {
        lustre_mounted = 1;
        while ((dir = readdir(d)) != NULL) {
            if (!strncmp(dir->d_name, ".", 1)) continue;
            strcpy(name, dir->d_name);
        }
    }
    closedir(d);

    if (uname (&uts) < 0) {
        err ("uname");
        goto done;
    }
    if (proc_stat2 (ctx, &cpuused, &cputot, &cpupct) < 0) {
        err ("error reading cpu usage from proc");
        goto done;
    }
    if (_get_mem_usage (ctx, &mempct) < 0)
        goto done;

    sprintf(stats_file, "%s/%s/stats", path_base, name);
    if (lustre_mounted && !access(stats_file, R_OK)) {
        if (proc_lustre_hashstats (ctx, name, &stats_hash) < 0) {
            err ("error reading lustre %s stats from proc", name);
            goto done;
        }
        proc_lustre_parsestat (stats_hash, "read_bytes", NULL, NULL, NULL,
                               &read_bytes, NULL);
        proc_lustre_parsestat (stats_hash, "read_bytes", &read_count, NULL, NULL,
                               NULL, NULL);
        proc_lustre_parsestat (stats_hash, "write_bytes", NULL, NULL, NULL,
                               &write_bytes, NULL);
        proc_lustre_parsestat (stats_hash, "write_bytes", &write_count, NULL, NULL,
                              NULL, NULL);
        proc_lustre_parsestat (stats_hash, "open", &open_count, NULL, NULL,
                              NULL, NULL);
        proc_lustre_parsestat (stats_hash, "close", &close_count, NULL, NULL,
                              NULL, NULL);
        proc_lustre_parsestat (stats_hash, "getattr", &getattr_count, NULL, NULL,
                              NULL, NULL);
        proc_lustre_parsestat (stats_hash, "setattr", &setattr_count, NULL, NULL,
                              NULL, NULL);
        proc_lustre_parsestat (stats_hash, "seek", &seek_count, NULL, NULL,
                              NULL, NULL);
        proc_lustre_parsestat (stats_hash, "fsync", &fsync_count, NULL, NULL,
                              NULL, NULL);
        proc_lustre_parsestat (stats_hash, "dirty_pages_hits", &dhits_count, NULL, NULL,
                              NULL, NULL);
        proc_lustre_parsestat (stats_hash, "dirty_pages_misses", &dmisses_count, NULL, NULL,
                              NULL, NULL);
    }
    n = snprintf (s, len, "%f;%f"
                  ";%"PRIu64";%"PRIu64";%"PRIu64";%"PRIu64
                  ";%"PRIu64";%"PRIu64";%"PRIu64";%"PRIu64
                  ";%"PRIu64";%"PRIu64";%"PRIu64";%"PRIu64,
		  cpupct, mempct,
                  read_bytes, read_count, write_bytes, write_count,
                  open_count, close_count, getattr_count, setattr_count,
                  seek_count, fsync_count, dhits_count, dmisses_count);
    if (n >= len) {
        msg ("string overflow");
        goto done;
    }
    retval = 0;
done:
    return retval;
}