Skip to content

Commit

Permalink
fixed formatting errors and file locations
Browse files Browse the repository at this point in the history
  • Loading branch information
baallan committed Aug 30, 2017
1 parent 18a2084 commit e31aec6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
15 changes: 9 additions & 6 deletions ldms/man/Plugin_store_flatfile.man
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ strgp_add plugin=store_flatfile [ <attr> = <value> ]


.SH DESCRIPTION
The flatfile store generates one file per metric with time, producer, component id, and value columns separated by spaces. The file name is $datadir/$container/$metric_name.
The flatfile store generates one file per metric with time, producer, component id, and value columns separated by spaces. The file name is $datadir/$container/$schema/$metric_name.

.PP

Expand Down Expand Up @@ -62,9 +62,9 @@ Please note the argument changes from v2.
.SH BUGS
Numeric array metrics are not presently supported.
There is a maximum of 20 concurrent flatfile stores.
The same metric in multiple schema may generate conflicting files,
if path is not used to separate the data. There is no way to filter which metrics are written. Unchanged meta-metrics are always written.

The store is brittle to schema with multiple definitions, though it ought not to be.
Unchanged meta-metrics are always written anyway.
There is no option to quote string values, handle rollover, or handle buffering.

.SH EXAMPLES
.PP
Expand All @@ -73,11 +73,14 @@ Within ldmsd_controller or in a configuration file
load name=store_flatfile
config name=store_flatfile path=/XXX/datadir

strgp_add name=store_flatfile_meminfo plugin=store_flatfile schema=meminfo container=contain_meminfo
# log only Active from the meminfo sampler
strgp_add name=store_flatfile_meminfo plugin=store_flatfile schema=meminfo container=flat
strgp_prdcr_add name=store_flatfile_meminfo regex=localhost1
strgp_metric_add name=store_flatfile_meminfo metric=Active
strgp_start name=store_flatfile_meminfo regex=localhost1

strgp_add name=store_flatfile_vmstat plugin=store_flatfile schema=vmstat container=contain_vmstat
# log all from vmstat
strgp_add name=store_flatfile_vmstat plugin=store_flatfile schema=vmstat container=flat
strgp_prdcr_add name=store_flatfile_vmstat regex=localhost1
strgp_start name=store_flatfile_vmstat regex=localhost1

Expand Down
52 changes: 35 additions & 17 deletions ldms/src/store/store_flatfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@
#include <coll/idx.h>
#include "ldms.h"
#include "ldmsd.h"
#include <ovis_util/util.h>

/*
* NOTE:
* (flatfile::path) = (root_path)/(comp_type)/(metric)
* (flatfile::path) = (root_path)/(container)/(schema)/(metric)
*/

static idx_t store_idx;
Expand All @@ -90,13 +91,13 @@ struct flatfile_metric_store {

struct flatfile_store_instance {
struct ldmsd_store *store;
char *path; /**< (root_path)/(comp_type) */
char *container;
char *path; /**< (root_path)/(container)/schema */
char *schema;
void *ucontext;
idx_t ms_idx;
LIST_HEAD(ms_list, flatfile_metric_store) ms_list;
int metric_count;
struct flatfile_metric_store *ms[0];
struct flatfile_metric_store *ms[/*flex array*/];
};

static pthread_mutex_t cfg_lock;
Expand Down Expand Up @@ -146,7 +147,7 @@ static void *get_ucontext(ldmsd_store_handle_t _sh)
}

static ldmsd_store_handle_t
open_store(struct ldmsd_store *s, const char *comp_type, const char *container,
open_store(struct ldmsd_store *s, const char *container, const char *schema,
struct ldmsd_strgp_metric_list *metric_list, void *ucontext)
{
struct flatfile_store_instance *si;
Expand All @@ -158,7 +159,7 @@ open_store(struct ldmsd_store *s, const char *comp_type, const char *container,
* Add a component type directory if one does not
* already exist
*/
si = idx_find(store_idx, (void *)container, strlen(container));
si = idx_find(store_idx, (void *)schema, strlen(schema));
if (!si) {
/*
* First, count the metric.
Expand All @@ -168,8 +169,8 @@ open_store(struct ldmsd_store *s, const char *comp_type, const char *container,
TAILQ_FOREACH(x, metric_list, entry) {
metric_count++;
}
sprintf(tmp_path, "%s/%s", root_path, comp_type);
mkdir(tmp_path, 0777);
sprintf(tmp_path, "%s/%s/%s", root_path, container, schema);
f_mkdir_p(tmp_path, 0777);

/*
* Open a new store for this component-type and
Expand All @@ -189,8 +190,8 @@ open_store(struct ldmsd_store *s, const char *comp_type, const char *container,
si->path = strdup(tmp_path);
if (!si->path)
goto err2;
si->container = strdup(container);
if (!si->container)
si->schema = strdup(schema);
if (!si->schema)
goto err3;
i = 0;
char mname[128];
Expand All @@ -216,14 +217,16 @@ open_store(struct ldmsd_store *s, const char *comp_type, const char *container,
if (!ms->path)
goto err4;
ms->file = fopen_perm(ms->path, "a+", LDMSD_DEFAULT_FILE_PERM);
if (!ms->file)
if (!ms->file) {
/* log message needed here from errno */
goto err4;
}
pthread_mutex_init(&ms->lock, NULL);
idx_add(si->ms_idx, name, strlen(name), ms);
LIST_INSERT_HEAD(&si->ms_list, ms, entry);
si->ms[i++] = ms;
}
idx_add(store_idx, (void *)container, strlen(container), si);
idx_add(store_idx, (void *)schema, strlen(schema), si);
}
goto out;
err4:
Expand All @@ -236,13 +239,14 @@ open_store(struct ldmsd_store *s, const char *comp_type, const char *container,
free(ms);
}

free(si->container);
free(si->schema);
err3:
free(si->path);
err2:
idx_destroy(si->ms_idx);
err1:
free(si);
si = NULL;
out:
pthread_mutex_unlock(&cfg_lock);
return si;
Expand Down Expand Up @@ -271,58 +275,72 @@ store(ldmsd_store_handle_t _sh, ldms_set_t set, int *metric_arry, size_t metric_
pthread_mutex_lock(&si->ms[i]->lock);
comp_id = ldms_metric_user_data_get(set, metric_arry[i]);
/* time, host, compid, value */
rc2 = fprintf(si->ms[i]->file, "%"PRIu32".%"PRIu32" %s %"PRIu64,
ts->sec, ts->usec, prod, comp_id);
#define STAMP \
rc2 = fprintf(si->ms[i]->file, "%"PRIu32".%06"PRIu32" %s %"PRIu64, \
ts->sec, ts->usec, prod, comp_id)
enum ldms_value_type metric_type =
ldms_metric_type_get(set, metric_arry[i]);
switch (metric_type) {
case LDMS_V_CHAR_ARRAY:
STAMP;
rc = fprintf(si->ms[i]->file, " %s\n",
ldms_metric_array_get_str(set, metric_arry[i]));
break;
case LDMS_V_U8:
STAMP;
rc = fprintf(si->ms[i]->file, " %u\n",
(unsigned)ldms_metric_get_u8(set, metric_arry[i]));
break;
case LDMS_V_S8:
STAMP;
rc = fprintf(si->ms[i]->file, " %d\n",
(int)ldms_metric_get_s8(set, metric_arry[i]));
break;
case LDMS_V_U16:
STAMP;
rc = fprintf(si->ms[i]->file, " %u\n",
(unsigned)ldms_metric_get_u16(set, metric_arry[i]));
break;
case LDMS_V_S16:
STAMP;
rc = fprintf(si->ms[i]->file, " %d\n",
(int)ldms_metric_get_s16(set, metric_arry[i]));
break;
case LDMS_V_U32:
STAMP;
rc = fprintf(si->ms[i]->file, " %u\n",
(unsigned)ldms_metric_get_u32(set, metric_arry[i]));
break;
case LDMS_V_S32:
STAMP;
rc = fprintf(si->ms[i]->file, " %d\n",
ldms_metric_get_s32(set, metric_arry[i]));
break;
case LDMS_V_U64:
STAMP;
rc = fprintf(si->ms[i]->file, " %"PRIu64"\n",
ldms_metric_get_u64(set, metric_arry[i]));
break;
case LDMS_V_S64:
STAMP;
rc = fprintf(si->ms[i]->file, " %"PRId64"\n",
ldms_metric_get_s64(set, metric_arry[i]));
break;
case LDMS_V_F32:
STAMP;
rc = fprintf(si->ms[i]->file, " %.9g\n",
ldms_metric_get_float(set, metric_arry[i]));
break;
case LDMS_V_D64:
STAMP;
rc = fprintf(si->ms[i]->file, " %.17g\n",
ldms_metric_get_double(set, metric_arry[i]));
break;
default:
/* array types not supported yet. want row and split files options */
break;
}
#undef STAMP
if (rc < 0 || rc2 < 0) {
last_errno = errno;
last_rc = (rc != 0 ? rc : rc2);
Expand Down Expand Up @@ -380,9 +398,9 @@ static void close_store(ldmsd_store_handle_t _sh)
free(ms->path);
free(ms);
}
idx_delete(store_idx, (void *)(si->container), strlen(si->container));
idx_delete(store_idx, (void *)(si->schema), strlen(si->schema));
free(si->path);
free(si->container);
free(si->schema);
idx_destroy(si->ms_idx);
free(si);
pthread_mutex_unlock(&cfg_lock);
Expand Down

0 comments on commit e31aec6

Please sign in to comment.