78 const std::map< const string, const string > plugin_ldms_message_publish_config_defaults =
89 inline static const char *plugin_prefix =
"ADC_LDMS_MESSAGE_PUBLISH_PLUGIN_";
92 const std::vector<string> tags;
105 if (mode != pi_config)
107 uid_t ui = geteuid();
108 fdir = dir +
string(
"/") + std::to_string(ui);
115 std::stringstream ss(sdebug);
121 std::cout<<
"ldms_message_publish plugin configured" <<std::endl;
127 const string get(
const std::map< string, string >& m,
130 auto it = m.find(field);
134 string en =
string(env_prefix) += field;
135 char *ec = getenv(en.c_str());
137 return plugin_ldms_message_publish_config_defaults.at(field);
143 string get_temp_file_name() {
144 string tplt = fdir +
"/json-lsp-msg-XXXXXX";
145 char * cstr =
new char [tplt.length()+1];
146 std::strcpy (cstr, tplt.c_str());
147 int fd = mkstemp(cstr);
155 std::cout<<
"mkstemp failed" <<std::endl;
162 int ldms_message_publish_send(
string& f)
164 string qcmd =
"(" + prog +
172 "> /dev/null 2>&1 ; /bin/rm -f " + f +
") &";
173 int err2 = std::system(qcmd.c_str());
175 std::cout << f << std::endl;
176 std::cout << err2 << std::endl;
183 state(ok), paused(
false), mode(pi_config) {}
190 if (mode != pi_pub_or_final)
195 string fname = get_temp_file_name();
197 std::cout <<
"name: " << fname <<std::endl;
200 std::ofstream out(fname);
202 out << b->serialize() << std::endl;
205 std::cout <<
"'ldms_message_publish' wrote" << std::endl;
208 ldms_message_publish_send(fname);
211 std::cout <<
"failed write" << std::endl;
215 std::filesystem::remove(fname);
216 std::cout <<
"failed open " <<fname<< std::endl;
220 int config(
const std::map< std::string, std::string >& m) {
221 return config(m, plugin_prefix);
225 string d = get(m,
"DIRECTORY", env_prefix);
226 string host = get(m,
"HOST", env_prefix);
227 string port = get(m,
"PORT", env_prefix);
228 string prog = get(m,
"PROG", env_prefix);
229 string auth = get(m,
"AUTH", env_prefix);
230 string channel = get(m,
"CHANNEL", env_prefix);
231 string sdebug = get(m,
"DEBUG", env_prefix);
232 return config(d, host, port, prog, auth, channel, sdebug);
236 return plugin_ldms_message_publish_config_defaults;
240 std::map <string, string >m;
244 if (mode != pi_init) {
247 if ( state == err ) {
248 std::cout <<
"ldms_message_publish plugin initialize found pre-existing error" << std::endl;
252 std::filesystem::create_directories(fdir, ec);
253 if (ec.value() != 0 && ec.value() != EEXIST ) {
255 std::cout <<
"unable to create scratch directory for plugin 'ldms_message_publish'; "
256 << fdir <<
" : " << ec.message() << std::endl;
260 std::cout <<
"created " << fdir <<std::endl;
262 mode = pi_pub_or_final;
268 if (mode == pi_pub_or_final) {
274 std::cout <<
"ldms_message_publish plugin finalize on non-running plugin" << std::endl;
288 return "ldms_message_publish";
297 std::cout <<
"Destructing ldms_message_publish_plugin" << std::endl;
ldms_message_publish utility publisher_api implementation. This plugin generates a scratch file (in-m...
int initialize()
Ready the plugin to publish following the configuration options set or defaulted.
const std::map< const std::string, const std::string > & get_option_defaults()
Look up the settable options and their defaults.
void resume()
Resume publishing Duplicate calls are allowed.
int publish(std::shared_ptr< builder_api > b)
Publish the content of the builder.
void pause()
Pause publishing until a call to resume. Duplicate calls are allowed.
static const char * adc_ldms_message_publish_plugin_port_default
port for message connections; ldmsd listeners must match. Overridden with env("ADC_LDMS_MESSAGE_PUBLI...
static const char * adc_ldms_message_publish_plugin_host_default
host for message connections; ldmsd must be listening on the host. Overridden with env("ADC_LDMS_MESS...
ldms_message_publish_plugin()
int config(const std::map< std::string, std::string > &m, string_view env_prefix)
Configure the plugin with the options given and the corresponding environment variables.
string_view version() const
static const char * adc_ldms_message_publish_plugin_affinity_default
affinity for spawned processes; defaults to all If not all, it should be a range list of cpu numbers,...
void finalize()
Stop publishing and release any resources held for managing publication.
~ldms_message_publish_plugin()
static const char * adc_ldms_message_publish_plugin_channel_default
channel of the ADC messages published LDMS aggregators must be subscribed to this name....
static const char * adc_ldms_message_publish_plugin_prog_default
full path to ldms_message_publish utility This program should be world accessible....
static const char * adc_ldms_message_publish_plugin_directory_default
scratch directory for ldms_message_publish utility messages This directory must be globally writable ...
static const char * adc_ldms_message_publish_plugin_debug_default
ADC ldms-message plugin enable debug messages; (default "0": none) Overridden with env("ADC_LDMS_MESS...
int config(const std::map< std::string, std::string > &m)
Configure the plugin with the options given.
static const char * adc_ldms_message_publish_plugin_auth_default
authentication method for ldms message connections; ldmsd listeners must match. Overridden with env("...
Publisher plugin interface.
std::string_view string_view