示例#1
0
/** Constructor.
 * @param config configuration instance
 * @param logger logger for informational output
 * @param prefix configuration prefix where to log for config information
 * @param in_data_size number of entries input value arrays
 * @param in vector of input arrays
 */
LaserDeadSpotsDataFilter::LaserDeadSpotsDataFilter(fawkes::Configuration *config,
						   fawkes::Logger *logger,
						   std::string prefix,
						   unsigned int in_data_size,
						   std::vector<LaserDataFilter::Buffer *> &in)
  : LaserDataFilter(in_data_size, in, in.size())
{
  __logger = logger;

  regex_t pathre;
  int error = 0;
  if ((error = regcomp(&pathre, (prefix + "\\([^/]\\+\\)/\\(start\\|end\\)").c_str(), 0)) != 0) {
    size_t errsize = regerror(error, &pathre, NULL, 0);
    char tmp[errsize];
    regerror(error, &pathre, tmp, errsize);
    regfree(&pathre);
    throw Exception("Failed to compile regular expression: %s", tmp);
  }

  regmatch_t matches[2];

  std::list<std::string> entries;

  Configuration::ValueIterator *vit = config->search(prefix.c_str());
  while (vit->next()) {
    const char *path = vit->path();
    if (regexec(&pathre, path, 2, matches, 0) == 0) {
      unsigned int match1_length = matches[1].rm_eo - matches[1].rm_so;

      char entry[match1_length + 1];    entry[match1_length] = 0;
      strncpy(entry, &(path[matches[1].rm_so]), match1_length);
      entries.push_back(entry);
    }
  }
  delete vit;
  entries.sort();
  entries.unique();

  __dead_spots = new unsigned int[entries.size() * 2];

  for (std::list<std::string>::iterator i = entries.begin(); i != entries.end(); ++i) {
    std::string path = prefix + *i + "/";
    float start = config->get_float((path + "start").c_str()); 
    float end   = config->get_float((path + "end").c_str()); 

    __logger->log_debug("LaserDeadSpotsDataFilter", "Adding dead range [%3.3f, %3.3f] (%s)",
			start, end, i->c_str());
    __cfg_dead_spots.push_back(std::make_pair(start, end));
  }

  __num_spots = __cfg_dead_spots.size();

  if (__num_spots == 0) {
    throw Exception("Dead spots filter enabled but no calibration data exists. Run fflaser_deadspots.");
  }

  calc_spots();
}
示例#2
0
/** Initialize plugin info cache. */
void
PluginManager::init_pinfo_cache()
{
  __pinfo_cache.lock();

  DIR *plugin_dir;
  struct dirent* dirp;
  const char *file_ext = "."SOEXT;

  if ( NULL == (plugin_dir = opendir(PLUGINDIR)) ) {
    throw Exception(errno, "Plugin directory %s could not be opened", PLUGINDIR);
  }

  for (unsigned int i = 0; NULL != (dirp = readdir(plugin_dir)); ++i) {
    char *file_name   = dirp->d_name;
    char *pos         = strstr(file_name, file_ext);
    std::string plugin_name = std::string(file_name).substr(0, strlen(file_name) - strlen(file_ext));
    if (NULL != pos) {
      try {
	__pinfo_cache.push_back(make_pair(plugin_name,
					  plugin_loader->get_description(plugin_name.c_str())));
      } catch (Exception &e) {
	LibLogger::log_warn("PluginManager", "Could not get description of plugin %s, "
			    "exception follows", plugin_name.c_str());
	LibLogger::log_warn("PluginManager", e);
      }
    }
  }

  closedir(plugin_dir);

  try {
    Configuration::ValueIterator *i = __config->search(__meta_plugin_prefix.c_str());
    while (i->next()) {
      if (i->is_string()) {
	std::string p = std::string(i->path()).substr(__meta_plugin_prefix.length());
	std::string s = std::string("Meta: ") + i->get_string();

	__pinfo_cache.push_back(make_pair(p, s));
      }
    }
    delete i;
  } catch (Exception &e) {
  }

  __pinfo_cache.sort();
  __pinfo_cache.unlock();
}
示例#3
0
/** Constructor.
 * @param config Fawkes configuration
 */
FvRetrieverPlugin::FvRetrieverPlugin(Configuration *config)
  : Plugin(config)
{

  std::string prefix = "/firevision/retriever/camera/";
  Configuration::ValueIterator *vi = config->search(prefix.c_str());

  while (vi->next()) {
    if ( ! vi->is_string() ) {
      throw TypeMismatchException("Only values of type string are valid for camera"
				  " argument strings, but got %s for %s",
				  vi->type(), vi->path());
    }

    std::string id = std::string(vi->path()).substr(prefix.length());

    thread_list.push_back(new FvRetrieverThread(vi->get_string().c_str(), id.c_str()));
  }

  if ( thread_list.empty() ) {
    throw Exception("No cameras have been set for fvretriever");
  }

  delete vi;
}
示例#4
0
/** Notify handlers for given path.
 * @param path path to notify handlers for
 * @param comment_changed true if the change is about a comment change,
 * false otherwise
 */
void
Configuration::notify_handlers(const char *path, bool comment_changed)
{
  ChangeHandlerList *h = find_handlers(path);
  Configuration::ValueIterator *value = get_value(path);
  if (value->next()) {
    for (ChangeHandlerList::const_iterator i = h->begin(); i != h->end(); ++i) {
      if (comment_changed) {
	(*i)->config_comment_changed(value);
      } else {
	(*i)->config_value_changed(value);
      }
    }
  } else {
    for (ChangeHandlerList::const_iterator i = h->begin(); i != h->end(); ++i) {
      (*i)->config_value_erased(path);
    }
  }
  delete value;
  delete h;
}
void
ProcRRDThread::init()
{
  __samplerate = 10;
  try {
    __samplerate = config->get_uint("/plugins/procrrd/samplerate");
  } catch (Exception &e) {}

  __timewait = new TimeWait(clock, __samplerate * 1000000);
  __netinterface = "wlan0";
  try {
    __netinterface = config->get_string("/plugins/procrrd/netinterface");
  } catch (Exception &e) {}

  __lastcpu = new unsigned long int[11];
  get_cpu(__lastcpu);

  __net_recv_graph = NULL;
  __net_trans_graph = NULL;
  std::vector<RRDDataSource> rrds;
  // /proc/net/dev
  // use data for net_interface
  // Receive bytes
  rrds.push_back(RRDDataSource("net_recv_bytes", RRDDataSource::COUNTER));
  // Receive packets
  rrds.push_back(RRDDataSource("net_recv_packets", RRDDataSource::COUNTER));
  // Receive errs
  rrds.push_back(RRDDataSource("net_recv_errors", RRDDataSource::COUNTER));
  // Transmit bytes
  rrds.push_back(RRDDataSource("net_trans_bytes", RRDDataSource::COUNTER));
  // Transmit packets
  rrds.push_back(RRDDataSource("net_trans_packets", RRDDataSource::COUNTER));
  // Transmit errs
  rrds.push_back(RRDDataSource("net_trans_errors", RRDDataSource::COUNTER));
  __net_rrd = new RRDDefinition("network", rrds);

  try {
    rrd_manager->add_rrd(__net_rrd);
  } catch (Exception &e) {
    finalize();
    throw;
  }

  std::vector<RRDGraphDataDefinition> defs;
  std::vector<RRDGraphElement *> els;

  defs.push_back(RRDGraphDataDefinition("net_recv_bytes", RRDArchive::AVERAGE,
					__net_rrd));
  defs.push_back(RRDGraphDataDefinition("net_recv_packets", RRDArchive::AVERAGE,
					__net_rrd));
  defs.push_back(RRDGraphDataDefinition("net_recv_errors", RRDArchive::AVERAGE,
					__net_rrd));

  els.push_back(new RRDGraphLine("net_recv_bytes", 1, "006400", "Bytes"));
  els.push_back(new RRDGraphGPrint("net_recv_bytes", RRDArchive::LAST,
				   "  Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_recv_bytes", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_recv_bytes", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("net_recv_packets", 1, "808000", "Packets"));
  els.push_back(new RRDGraphGPrint("net_recv_packets", RRDArchive::LAST,
				   "Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_recv_packets", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_recv_packets", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("net_recv_errors", 1, "FF0000", "Errors"));
  els.push_back(new RRDGraphGPrint("net_recv_errors", RRDArchive::LAST,
				   " Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_recv_errors", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_recv_errors", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  __net_recv_graph = new RRDGraphDefinition("network_recv", __net_rrd,
					      "Network Receive", "",
					      defs, els);

  defs.clear();
  els.clear();

  defs.push_back(RRDGraphDataDefinition("net_trans_bytes", RRDArchive::AVERAGE,
					__net_rrd));
  defs.push_back(RRDGraphDataDefinition("net_trans_packets", RRDArchive::AVERAGE,
					__net_rrd));
  defs.push_back(RRDGraphDataDefinition("net_trans_errors", RRDArchive::AVERAGE,
					__net_rrd));

  els.push_back(new RRDGraphLine("net_trans_bytes", 1, "006400", "Bytes"));
  els.push_back(new RRDGraphGPrint("net_trans_bytes", RRDArchive::LAST,
				   "  Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_trans_bytes", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_trans_bytes", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("net_trans_packets", 1, "808000", "Packets"));
  els.push_back(new RRDGraphGPrint("net_trans_packets", RRDArchive::LAST,
				   "Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_trans_packets", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_trans_packets", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("net_trans_errors", 1, "FF0000", "Errors"));
  els.push_back(new RRDGraphGPrint("net_trans_errors", RRDArchive::LAST,
				   " Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_trans_errors", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("net_trans_errors", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  __net_trans_graph = new RRDGraphDefinition("network_trans", __net_rrd,
					      "Network Transmit", "",
					      defs, els);

  try {
    rrd_manager->add_graph(__net_recv_graph);
    rrd_manager->add_graph(__net_trans_graph);
  } catch (Exception &e) {
    finalize();
    throw;
  }

  std::string procprefix = PROC_CONF_PREFIX;

  try {
    std::string selfid = get_process_id("fawkes"); 
    add_process((procprefix+"fawkes").c_str(), selfid, "fawkes");
  } catch (Exception &e) {
    logger->log_warn(name(), "Failed to add process: Fawkes, exception follows");
    logger->log_warn(name(), e);
    finalize();
    throw;
  }

  Configuration::ValueIterator *i = config->search(procprefix.c_str());
  while (i->next()) {

    if (! i->is_string()) {
      logger->log_warn(name(), "Entry %s is not a string, but of type %s, "
		       "ignoring", i->path(), i->type());
      continue;
    }


    std::string name = i->get_string();
    try {
      std::string pid = get_process_id(name.c_str());
      add_process(i->path(), pid, name);
    } catch (Exception &e) {
      logger->log_warn(this->name(), "Failed to add process: %s, exception follows", name.c_str());
      logger->log_warn(this->name(), e);
      finalize();
      throw;
    }
  }

  std::string p;
  ProcessMap::iterator pi = __processes.begin();
  p = pi->second.name;
  ++pi;
  for (; pi != __processes.end(); ++pi) {
    p += ", "+pi->second.name;
  }

  

  logger->log_info(name(), "ProcRRD logging network interface %s and processes %s with a samplerate of %lu second(s)",
       __netinterface.c_str(), p.c_str(), __samplerate);

  config->add_change_handler(this);
}
示例#6
0
void
MongoRRDThread::init()
{
  __timewait = new TimeWait(clock, 10 * 1000000);

  __opcounters_graph = NULL;
  __memory_graph = NULL;
  __indexes_graph = NULL;

  std::vector<RRDDataSource> rrds;
  rrds.push_back(RRDDataSource("insert",  RRDDataSource::COUNTER));
  rrds.push_back(RRDDataSource("query",   RRDDataSource::COUNTER));
  rrds.push_back(RRDDataSource("update",  RRDDataSource::COUNTER));
  rrds.push_back(RRDDataSource("delete",  RRDDataSource::COUNTER));
  rrds.push_back(RRDDataSource("getmore", RRDDataSource::COUNTER));
  rrds.push_back(RRDDataSource("command", RRDDataSource::COUNTER));
  __opcounters_rrd = new RRDDefinition("opcounters", rrds);

  rrds.clear();
  rrds.push_back(RRDDataSource("resident", RRDDataSource::GAUGE));
  rrds.push_back(RRDDataSource("virtual", RRDDataSource::GAUGE));
  rrds.push_back(RRDDataSource("mapped", RRDDataSource::GAUGE));
  __memory_rrd = new RRDDefinition("memory", rrds);

  rrds.clear();
  rrds.push_back(RRDDataSource("accesses", RRDDataSource::COUNTER));
  rrds.push_back(RRDDataSource("hits", RRDDataSource::COUNTER));
  rrds.push_back(RRDDataSource("misses", RRDDataSource::COUNTER));
  rrds.push_back(RRDDataSource("resets", RRDDataSource::COUNTER));
  __indexes_rrd = new RRDDefinition("indexes", rrds);

  rrds.clear();
  rrds.push_back(RRDDataSource("locktime", RRDDataSource::COUNTER));
  __locks_rrd = new RRDDefinition("locks", rrds);


  try {
    rrd_manager->add_rrd(__opcounters_rrd);
    rrd_manager->add_rrd(__memory_rrd);
    rrd_manager->add_rrd(__indexes_rrd);
    rrd_manager->add_rrd(__locks_rrd);
  } catch (Exception &e) {
    finalize();
    throw;
  }


  std::vector<RRDGraphDataDefinition> defs;
  std::vector<RRDGraphElement *> els;

  defs.push_back(RRDGraphDataDefinition("insert", RRDArchive::AVERAGE,
					__opcounters_rrd));
  defs.push_back(RRDGraphDataDefinition("query", RRDArchive::AVERAGE,
					__opcounters_rrd));
  defs.push_back(RRDGraphDataDefinition("update", RRDArchive::AVERAGE,
					__opcounters_rrd));
  defs.push_back(RRDGraphDataDefinition("delete", RRDArchive::AVERAGE,
					__opcounters_rrd));
  defs.push_back(RRDGraphDataDefinition("getmore", RRDArchive::AVERAGE,
					__opcounters_rrd));
  defs.push_back(RRDGraphDataDefinition("command", RRDArchive::AVERAGE,
					__opcounters_rrd));
  
  els.push_back(new RRDGraphLine("insert", 1, "FF7200", "Inserts"));
  els.push_back(new RRDGraphGPrint("insert", RRDArchive::LAST,
				   " Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("insert", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("insert", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("query", 1, "503001", "Queries"));
  els.push_back(new RRDGraphGPrint("query", RRDArchive::LAST,
				   " Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("query", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("query", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("update", 1, "EDAC00", "Updates"));
  els.push_back(new RRDGraphGPrint("update", RRDArchive::LAST,
				   " Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("update", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("update", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("delete", 1, "506101", "Deletes"));
  els.push_back(new RRDGraphGPrint("delete", RRDArchive::LAST,
				   " Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("delete", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("delete", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("getmore", 1, "0CCCCC", "Getmores"));
  els.push_back(new RRDGraphGPrint("getmore", RRDArchive::LAST,
				   "Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("getmore", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("getmore", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("command", 1, "53CA05", "Commands"));
  els.push_back(new RRDGraphGPrint("command", RRDArchive::LAST,
				   "Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("command", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("command", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  __opcounters_graph = new RRDGraphDefinition("opcounters", __opcounters_rrd,
					      "MongoDB Op Counters", "Ops/sec",
					      defs, els);


  defs.clear(); els.clear();
  defs.push_back(RRDGraphDataDefinition("rawresident", RRDArchive::AVERAGE,
					__memory_rrd, "resident"));
  defs.push_back(RRDGraphDataDefinition("rawvirtual", RRDArchive::AVERAGE,
					__memory_rrd, "virtual"));
  defs.push_back(RRDGraphDataDefinition("rawmapped", RRDArchive::AVERAGE,
					__memory_rrd, "mapped"));
  defs.push_back(RRDGraphDataDefinition("resident", "rawresident,1048576,*"));
  defs.push_back(RRDGraphDataDefinition("virtual", "rawvirtual,1048576,*"));
  defs.push_back(RRDGraphDataDefinition("mapped", "rawmapped,1048576,*"));

  els.push_back(new RRDGraphArea("virtual", "3B7AD9", "Virtual"));
  els.push_back(new RRDGraphGPrint("virtual", RRDArchive::LAST,
				   " Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("virtual", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("virtual", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphArea("mapped", "6FD1BF", "Mapped"));
  els.push_back(new RRDGraphGPrint("mapped", RRDArchive::LAST,
				   "  Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("mapped", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("mapped", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphArea("resident", "0E6E5C", "Resident"));
  els.push_back(new RRDGraphGPrint("resident", RRDArchive::LAST,
				   "Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("resident", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("resident", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  __memory_graph = new RRDGraphDefinition("memory", __memory_rrd,
					  "MongoDB Memory Usage", "MB",
					  defs, els);

  defs.clear(); els.clear();
  defs.push_back(RRDGraphDataDefinition("accesses", RRDArchive::AVERAGE,
					__indexes_rrd));
  defs.push_back(RRDGraphDataDefinition("hits", RRDArchive::AVERAGE,
					__indexes_rrd));
  defs.push_back(RRDGraphDataDefinition("misses", RRDArchive::AVERAGE,
					__indexes_rrd));
  defs.push_back(RRDGraphDataDefinition("resets", RRDArchive::AVERAGE,
					__indexes_rrd));
  
  els.push_back(new RRDGraphLine("accesses", 1, "FF7200", "Accesses"));
  els.push_back(new RRDGraphGPrint("accesses", RRDArchive::LAST,
				   "Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("accesses", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("accesses", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("hits", 1, "503001", "Hits"));
  els.push_back(new RRDGraphGPrint("hits", RRDArchive::LAST,
				   "    Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("hits", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("hits", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("misses", 1, "EDAC00", "Misses"));
  els.push_back(new RRDGraphGPrint("misses", RRDArchive::LAST,
				   "  Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("misses", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("misses", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  els.push_back(new RRDGraphLine("resets", 1, "506101", "Resets"));
  els.push_back(new RRDGraphGPrint("resets", RRDArchive::LAST,
				   "  Current\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("resets", RRDArchive::AVERAGE,
				   "Average\\:%8.2lf %s"));
  els.push_back(new RRDGraphGPrint("resets", RRDArchive::MAX,
				   "Maximum\\:%8.2lf %s\\n"));

  __indexes_graph = new RRDGraphDefinition("indexes", __indexes_rrd,
					    "MongoDB Indexes", "",
					    defs, els);

  try {
    rrd_manager->add_graph(__opcounters_graph);
    rrd_manager->add_graph(__memory_graph);
    rrd_manager->add_graph(__indexes_graph);
  } catch (Exception &e) {
    finalize();
    throw;
  }

  // Add DB Stats
  std::string dbprefix = DB_CONF_PREFIX;

  Configuration::ValueIterator *i = config->search(dbprefix.c_str());
  while (i->next()) {

    if (! i->is_string()) {
      logger->log_warn(name(), "Entry %s is not a string, but of type %s, "
		       "ignoring", i->path(), i->type());
      continue;
    }

    std::string dbname = i->get_string();
    if (dbname.find(".") != std::string::npos) {
      logger->log_warn(name(), "Database name %s contains dot, ignoring",
		       dbname.c_str());
      continue;
    }

    try {
      add_dbstats(i->path(), dbname);
    } catch (Exception &e) {
      finalize();
      throw;
    }
  }

  config->add_change_handler(this);
}
/** Constructor.
 * @param config Fawkes configuration
 */
BlackBoardLoggerPlugin::BlackBoardLoggerPlugin(Configuration *config)
  : Plugin(config)
{
  std::set<std::string> ifaces;

  std::string prefix = "/fawkes/bblogger/";
  std::string replay_prefix = "/fawkes/bblogreplay/";

  std::string scenario = "";
  try {
    scenario = config->get_string((prefix + "scenario").c_str());
  } catch (Exception &e) {
    e.append("No scenario defined, configure %sscenario", prefix.c_str());
    throw;
  }

  /*
  bool generate_replay_config = false;
  try {
    generate_replay_config = config->get_bool((prefix + "generate_replay_config").c_str());
  } catch (Exception &e) {} // ignored, use default set above
  */

  std::string scenario_prefix = prefix + scenario + "/";
  std::string ifaces_prefix   = scenario_prefix + "interfaces/";

  std::string logdir = LOGDIR;
  bool        buffering = true;
  bool        flushing = false;
  try {
    logdir = config->get_string((scenario_prefix + "logdir").c_str());
  } catch (Exception &e) { /* ignored, use default set above */ }
  try {
    buffering = config->get_bool((scenario_prefix + "buffering").c_str());
  } catch (Exception &e) { /* ignored, use default set above */ }
  try {
    flushing = config->get_bool((scenario_prefix + "flushing").c_str());
  } catch (Exception &e) { /* ignored, use default set above */ }

  struct stat s;
  int err = stat(logdir.c_str(), &s);
  if (err != 0) {
    char buf[1024];
    Exception se ("Cannot access logdir %s (%s)",
		  logdir.c_str(), strerror_r(errno, buf, 1024));
    if (mkdir(logdir.c_str(), 0755) != 0) {
      se.append("Failed to create log directory (%s)",
		strerror_r(errno, buf, 1024));
      throw se;
    }
  } else if ( ! S_ISDIR(s.st_mode) ) {
    throw Exception("Logdir path %s is not a directory", logdir.c_str());
  }

  // We do not have the framework clock available at this point, but for the start
  // time of the log we are only interested in the system time anyway
  Time start;

  char date[21];
  Time now;
  struct tm *tmp = localtime(&(now.get_timeval()->tv_sec));
  strftime(date, 21, "%F-%H-%M-%S", tmp);
  std::string replay_cfg_prefix = replay_prefix + scenario + "-" + date + "/logs/";

  Configuration::ValueIterator *i = config->search(ifaces_prefix.c_str());
  while (i->next()) {
    std::string iface_name = std::string(i->path()).substr(ifaces_prefix.length());
    iface_name = iface_name.substr(0, iface_name.find("/"));

    //printf("Adding sync thread for peer %s\n", peer.c_str());
    BBLoggerThread *log_thread = new BBLoggerThread(i->get_string().c_str(),
						    logdir.c_str(),
						    buffering, flushing,
						    scenario.c_str(), &start);

    std::string filename = log_thread->get_filename();
    config->set_string((replay_cfg_prefix + iface_name + "/file").c_str(), filename);

    thread_list.push_back(log_thread);
  }
  delete i;

  if ( thread_list.empty() ) {
    throw Exception("No interfaces configured for logging, aborting");
  }

  BBLoggerThread *bblt = dynamic_cast<BBLoggerThread *>(thread_list.front());
  bblt->set_threadlist(thread_list);
}
示例#8
0
bool
ConfigTreeView::remove_entry(const Gtk::TreeIter& iter)
{
  bool ret_val = false;
  int result;
  Gtk::TreeModel::Row row = *iter;
  Glib::ustring type = row[m_config_record.type];
  bool is_default = row[m_config_record.is_default];

  if (type == "") //if type is empty the row is a directory -> return
    { ret_val = false; }
  else
    {
      Glib::ustring path = row[m_config_record.path];
      m_dlg_remove->init(path, is_default);

      Gtk::Window* parent = dynamic_cast<Gtk::Window*>( get_toplevel() );
      m_dlg_remove->set_transient_for(*parent);
      result = m_dlg_remove->run();

      switch (result)
	{
	case Gtk::RESPONSE_OK:
	  {
	    const char* p = path.c_str();
	    bool rem_default = m_dlg_remove->get_remove_default();
	    m_config->erase(p);
	    if (rem_default) m_config->erase_default(p);

	    Gtk::TreePath tree_path = m_config_tree->get_path(iter);
  	    m_config_tree->erase(iter);
	    m_config_tree->row_deleted(tree_path);

	    Configuration::ValueIterator* cit = m_config->search(p);
	    if (!rem_default && cit->next()) //reenter the default value
	      {
                if ( cit->is_bool() )
                  { set_value(cit->path(), cit->type(), cit->is_default(), cit->get_bool()); }
                else if ( cit->is_int() )
                  { set_value(cit->path(), cit->type(), cit->is_default(), cit->get_int()); }
                else if ( cit->is_uint() )
                  { set_value(cit->path(), cit->type(), cit->is_default(), cit->get_uint()); }
                else if ( cit->is_float() )
                  { set_value(cit->path(), cit->type(), cit->is_default(), cit->get_float()); }
                else if ( cit->is_string() )
                  { set_value(cit->path(), cit->type(), cit->is_default(), cit->get_string()); }
	      }

	    break;
	  }

	default:
	  ret_val = false;
	  break;
	}

      m_dlg_remove->hide();
    }

  return ret_val;
}
示例#9
0
void
ConfigTreeView::read_config()
{
  if ( !m_config )
    { return; }

  m_config_tree->clear();

  m_config->lock();
  Configuration::ValueIterator* cit = m_config->iterator();
  while ( cit->next() )
    {
      if ( cit->is_bool() )
	{ set_value(cit->path(), cit->type(), cit->is_default(), cit->get_bool()); }
      else if ( cit->is_int() )
	{ set_value(cit->path(), cit->type(), cit->is_default(), cit->get_int()); }
      else if ( cit->is_uint() )
	{ set_value(cit->path(), cit->type(), cit->is_default(), cit->get_uint()); }
      else if ( cit->is_float() )
	{ set_value(cit->path(), cit->type(), cit->is_default(), cit->get_float()); }
      else if ( cit->is_string() )
	{ set_value(cit->path(), cit->type(), cit->is_default(), cit->get_string()); }
    }

  delete cit;
  m_config->unlock();
}