Example #1
0
int
main(int argc, const char *argv[])
{
  int c, ret;

  if((ret = omlc_init("click_mon", &argc, argv, NULL)) < 0) {
    logerror("Could not initialise OML\n");
    return -1;
  }

  /* Parse command line arguments */
  poptContext optCon = poptGetContext(NULL, argc, argv, options, 0); /* options is defined in click_mon_popt.h */
  while ((c = poptGetNextOpt(optCon)) > 0) {}

  /* Initialise measurement points, only if OML is not disabled */
  oml_register_mps(); /* Defined in click_mon_oml.h */
  if(ret == 0 && omlc_start()) {
    logerror("Could not start OML\n");
    return -1;
  }

  run(g_opts, g_oml_mps_click_mon); /* Do some work and injections, see above */

  omlc_close();

  return 0;
}
Example #2
0
/** Clean up connection to the monitoring OML server. */
void
oml_cleanup(void)
{
  if(oml_enabled) {
    omlc_close();
    oml_enabled = 0;
  }
}
Example #3
0
int
main(int argc, const char *argv[])
{
  int c, i, ret;

  /* Reconstruct command line */
  size_t cmdline_len = 0;
  for(i = 0; i < argc; i++) {
    cmdline_len += strlen(argv[i]) + 1;
  }
  char *cmdline = oml_malloc(cmdline_len);
  cmdline[0] = '\0';
  for(i = 0; i < argc; i++) {
    strncat(cmdline, argv[i], cmdline_len);
    cmdline_len -= strlen(argv[i]);
    strncat(cmdline, " ", cmdline_len);
    cmdline_len--;
  }

  /* Initialize OML */
  if((ret = omlc_init("generator", &argc, argv, NULL)) < 0) {
    logerror("Could not initialise OML\n");
    return -1;
  }

  /* Parse command line arguments */
  poptContext optCon = poptGetContext(NULL, argc, argv, options, 0); /* options is defined in generator_popt.h */
  while ((c = poptGetNextOpt(optCon)) > 0) {}

  /* Initialise measurement points and start OML */
  oml_register_mps(); /* Defined in generator_oml.h */
  if(omlc_start()) {
    logerror("Could not start OML\n");
    return -1;
  }

  /* Inject some metadata about this application */
  OmlValueU v;
  omlc_zero(v);
  omlc_set_string(v, PACKAGE_NAME);
  omlc_inject_metadata(NULL, "appname", &v, OML_STRING_VALUE, NULL);

  omlc_set_string(v, PACKAGE_VERSION);
  omlc_inject_metadata(NULL, "version", &v, OML_STRING_VALUE, NULL);

  omlc_set_string(v, cmdline);
  omlc_inject_metadata(NULL, "cmdline", &v, OML_STRING_VALUE, NULL);
  omlc_reset_string(v);
  oml_free(cmdline);

  /* Inject measurements */
  run(g_opts, g_oml_mps_generator); /* Do some work and injections, see above */

  omlc_close();

  return 0;
}
Example #4
0
END_TEST

/** Check that an empty <collect /> sends all streams to that collection point (#1272) */
START_TEST (test_config_empty_collect)
{
  OmlMP *mp;
  OmlValueU v[2];
  char buf[1024];
  char config[] = "<omlc domain='check_liboml2_config' id='test_config_empty_collect'>\n"
                  "  <collect url='file:test_config_empty_collect' encoding='text' />\n"
                  "</omlc>";
  int s1found = 0;
  FILE *fp;

  logdebug("%s\n", __FUNCTION__);

  MAKEOMLCMDLINE(argc, argv, "file:test_config_empty_collect");
  argv[1] = "--oml-config";
  argv[2] = "test_config_empty_collect.xml";
  argc = 3;

  fp = fopen (argv[2], "w");
  fail_unless(fp != NULL, "Could not create configuration file %s: %s", argv[2], strerror(errno));
  fail_unless(fwrite(config, sizeof(config), 1, fp) == 1,
      "Could not write configuration in file %s: %s", argv[2], strerror(errno));
  fclose(fp);

  unlink("test_config_empty_collect");

  fail_if(omlc_init(__FUNCTION__, &argc, argv, NULL),
      "Could not initialise OML");
  mp = omlc_add_mp(__FUNCTION__, mp_def);
  fail_if(mp==NULL, "Could not add MP");
  fail_if(omlc_start(), "Could not start OML");

  omlc_set_uint32(v[0], 1);
  omlc_set_uint32(v[1], 2);

  fail_if(omlc_inject(mp, v), "Injection failed");

  omlc_close();

  fp = fopen(__FUNCTION__, "r");
  fail_unless(fp != NULL, "Output file %s missing", __FUNCTION__);

  while(fgets(buf, sizeof(buf), fp) && !s1found) {
    if (!strncmp(buf, "schema: 1", 9)) {
        s1found = 1;
    }
  }
  fail_unless(s1found, "Schema 1 never defined");

  fclose(fp);
}
Example #5
0
static void test_main(void *param)
{
  int8_t result = omlc_init ("Simple");
  if (result == -1) {
    printf ("Could not initialise OML\n");
    while(1);
  } else if (result == 1) {
    printf ("OML was disabled by the user, exiting\n");
    while(1);
  }
  
  OmlMPDef mp_def [] = {
    { "count", OML_UINT32_VALUE },
    { "count_str", OML_STRING_VALUE },
    { "count_real", OML_DOUBLE_VALUE },
    { NULL, (OmlValueT)0 }
  };
  
  OmlMP *mp = omlc_add_mp ("counter", mp_def);
  
  if (mp == NULL) {
    printf ("Error: could not register Measurement Point 'counter'");
    while(1);
  }
  
  omlc_start();
  
  uint32_t i = 0;
  for (i = 0; i < 100; i++) {
    uint32_t count = i;
    char count_str[16];
    double count_real = (double)i;
    OmlValueU values[3];
    
    omlc_zero_array(values, 3);
    
    snprintf(count_str, sizeof(count_str), "%d", i);
    
    omlc_set_uint32 (values[0], count);
    omlc_set_string (values[1], count_str);
    omlc_set_double (values[2], count_real);
    
    omlc_inject (mp, values);
    
    omlc_reset_string(values[1]);
  }
  omlc_close();
  while(1);
}
Example #6
0
END_TEST

/** Check that multiple <collect /> do not trigger a "Measurement stream 'd_lin' already exists" error (#1154) */
START_TEST (test_config_multi_collect)
{
  OmlMP *mp;
  OmlValueU v[2];
  char buf[1024], *bufp;
  char *dests[2] = { "test_config_multi_collect1", "test_config_multi_collect2" };
  char config[] = "<omlc domain='check_liboml2_config' id='test_config_multi_collect'>\n"
                  "  <collect url='file:test_config_multi_collect1' encoding='text' />\n"
                  "  <collect url='file:test_config_multi_collect2' encoding='text' />\n"
                  "</omlc>";
  int i, s1found = 0, emptyfound = 0, n, datafound[2] = {0, 0};
  FILE *fp;

  logdebug("%s\n", __FUNCTION__);

  MAKEOMLCMDLINE(argc, argv, "file:test_config_multi_collect");
  argv[1] = "--oml-config";
  argv[2] = "test_config_multi_collect.xml";
  argc = 3;

  fp = fopen (argv[2], "w");
  fail_unless(fp != NULL, "Could not create configuration file %s: %s", argv[2], strerror(errno));
  fail_unless(fwrite(config, sizeof(config), 1, fp) == 1,
      "Could not write configuration in file %s: %s", argv[2], strerror(errno));
  fclose(fp);

  unlink("test_config_multi_collect1");
  unlink("test_config_multi_collect2");

  fail_if(omlc_init(__FUNCTION__, &argc, argv, NULL),
      "Could not initialise OML");
  mp = omlc_add_mp(__FUNCTION__, mp_def);
  fail_if(mp==NULL, "Could not add MP");
  fail_if(omlc_start(), "Could not start OML");

  omlc_set_uint32(v[0], 1);
  omlc_set_uint32(v[1], 2);

  fail_if(omlc_inject(mp, v), "Injection failed");

  omlc_close();

  for (i=0; i<2; i++) {
    s1found = 0;
    fp = fopen(dests[i], "r");
    fail_unless(fp != NULL, "Output file %s missing", __FUNCTION__);

    emptyfound = 0;
    while(fgets(buf, sizeof(buf), fp) && (!s1found || !datafound[i])) {

      if (!strncmp(buf, "schema: 1", 9)) {
        s1found = 1;

      } else if (emptyfound) {
        /* We know we are passed the header;
         * We check that the data is here, that is, we have
         * 5 tab-delimited fields (ts, schemaid, seqno, d1, d2) */
        bufp = buf;
        n = 0;
        while(++n<6 && strtok(bufp, "\t")) {
          bufp = NULL; /* Make strtok continue on the same string */
        };
        if (n==6) {
          datafound[i] = 1;
        }

      } else if (*buf == '\n') {
        emptyfound = 1;
      }
    }
    fail_unless(s1found, "Schema 1 never defined in %s", dests[i]);
    fail_unless(datafound[i], "No actual data in %s", dests[i]);

    fclose(fp);
  }
}