ADCT Python
Python client API implementation for publishing ADCT data
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Attributes | List of all members
adctk.ldms_publisher.LDMSSystemPublisher Class Reference

Publish data via file to ldmsd_stream_publish once via process recreated at each call. More...

Inheritance diagram for adctk.ldms_publisher.LDMSSystemPublisher:
Inheritance graph
[legend]
Collaboration diagram for adctk.ldms_publisher.LDMSSystemPublisher:
Collaboration graph
[legend]

Public Member Functions

 __init__ (self)
 
int config (self, **kwargs)
 Configure the plugin with the options given.
 
- Public Member Functions inherited from adctk.ldms_publisher.LDMSPipePublisher
int initialize (self)
 Set up any resources needed for reuse in publish().
 
 publish (self, builder.Builder b)
 
 finalize (self)
 Clean up any resources set up in initialize (files, pipes, etc).
 
- Public Member Functions inherited from adctk.publisher.Publisher
str name (self)
 Get the name which a factory or error message should use.
 
str version (self)
 
dict[str, str] get_option_defaults (self)
 
None pause (self)
 Cause publish calls to be ignored until resume is called.
 
None resume (self)
 Cancel an prior calls to pause.
 
int publish_str (self, str json_string)
 
int publish_obj (self, obj)
 

Public Attributes

 defaults
 
 dir_
 
 port
 
 auth
 
 stream
 
 host
 
- Public Attributes inherited from adctk.ldms_publisher.LDMSPipePublisher
 plugin_prefix
 
 defaults
 
 prog
 
 port
 
 auth
 
 stream
 
 host
 
 timeout
 
 mode
 
 state
 
- Public Attributes inherited from adctk.publisher.Publisher
 defaults
 
 plugin_prefix
 
 paused
 
 state
 
 mode
 

Protected Member Functions

int _post (self, str msg)
 
- Protected Member Functions inherited from adctk.publisher.Publisher
str _get (self, dict[str, str] opts, str field)
 
bool _get_bool (self, dict[str, str] opts, str field)
 

Static Protected Attributes

str _name = "ldms-system-stream"
 
str _version = "1.0.0"
 
- Static Protected Attributes inherited from adctk.ldms_publisher.LDMSPipePublisher
str _name = "ldms-pipe-stream"
 
str _version = "1.0.0"
 
- Static Protected Attributes inherited from adctk.publisher.Publisher
str _name = "unknown"
 
str _version = "0.0.0"
 

Additional Inherited Members

- Static Public Member Functions inherited from adctk.publisher.Publisher
tuple[float] get_timeout_defaults ()
 Get the adc server connect and response timeouts defined in the environment ADC_SERVER_CONNECT_TIMEOUT and ADC_SERVER_POST_TIMEOUT as a tuple or default values if not defined.
 
str get_url_default ()
 Get the alleged adc server url base from environment ADC_SERVER_URL or the default if it is not present.
 
str get_port_default ()
 Get the adc server port number to use if it is properly defined in the environment ADC_SERVER_PORT or the default if it is not.
 
- Static Public Attributes inherited from adctk.publisher.Publisher
 API_VERSION = adc_version.AdcVersion()._dict()
 

Detailed Description

Publish data via file to ldmsd_stream_publish once via process recreated at each call.

Environment Variables

Constructor & Destructor Documentation

◆ __init__()

adctk.ldms_publisher.LDMSSystemPublisher.__init__ (   self)

Reimplemented from adctk.ldms_publisher.LDMSPipePublisher.

146 def __init__(self):
147 super().__init__()
148 self.defaults = _defaults_system
149 self.dir_: str = None
150

Member Function Documentation

◆ _post()

int adctk.ldms_publisher.LDMSSystemPublisher._post (   self,
str   msg 
)
protected

Reimplemented from adctk.ldms_publisher.LDMSPipePublisher.

155 def _post(self, msg:str ) ->int:
156 if not self.dir_:
157 self.initialize()
158 f = None
159 try:
160 f, filepath = tempfile.mkstemp( prefix="adctk-json-system-stream-msg-", dir=self.dir_ )
161 f.write(msg)
162 f.close()
163 cmd = [self.prog,
164 "-t", "json",
165 "-x", "sock",
166 "-p", self.port,
167 "-a", self.auth,
168 "-s", self.stream,
169 "-h", self.host,
170 "-f", filepath
171 ]
172 log.logger.info("LDMSSystem-publisher command: %s", cmd)
173 with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
174 stdout, stderr = process.communicate(timeout=self.timeout)
175 output_string = stdout.decode("utf-8")
176 error_string = stderr.decode("utf-8")
177 log.logger.debug("Output: %s", output_string)
178 log.logger.debug("Error: (may be empty): %s", error_string)
179 ret = process.wait()
180 if ret != 0:
181 log.logger.warning("LDMSSystem-publisher: publish process failed "\
182 "with error: %s", ret)
183 except subprocess.TimeoutExpired:
184 log.logger.warning("LDMSSystem-publisher: timeout expired")
185 if f:
186 os.unlink(filepath)
187

◆ config()

int adctk.ldms_publisher.LDMSSystemPublisher.config (   self,
**  kwargs 
)

Configure the plugin with the options given.

For plugin QQQ, Environment variables ADC_QQQ_PLUGIN_<key> will override the plugin default for any key not defined in kwargs. Here QQQ is plugin.name().upper(). Generic options:

Parameters
kwargsIf env_prefix is included in kwargs, replaces plugin environment variables with those which are prefixed using env_prefix.
env_prefixTypically, env_prefix is set to "PPP_ADC_QQQ_PLUGIN_" if application PPP wants to override the defaults of adctk plugin QQQ. Here QQQ is plugin.name().upper(). If no prefixed version of the variable is present, the plugin default is used. kwargs takes precedence over environment variables. Plugin defaults are used if not overridden by kwargs or an environment variable.
Returns
int non-zero if configuration cannot be completed using the arguments, environment, and default.

Reimplemented from adctk.ldms_publisher.LDMSPipePublisher.

151 def config(self, **kwargs) -> int:
152 self.dir_ = self._get(kwargs, "DIRECTORY")
153 return super().config(**kwargs)
154

Member Data Documentation

◆ _name

str adctk.ldms_publisher.LDMSSystemPublisher._name = "ldms-system-stream"
staticprotected

◆ _version

str adctk.ldms_publisher.LDMSSystemPublisher._version = "1.0.0"
staticprotected

◆ auth

adctk.ldms_publisher.LDMSSystemPublisher.auth

◆ defaults

adctk.ldms_publisher.LDMSSystemPublisher.defaults

◆ dir_

adctk.ldms_publisher.LDMSSystemPublisher.dir_

◆ host

adctk.ldms_publisher.LDMSSystemPublisher.host

◆ port

adctk.ldms_publisher.LDMSSystemPublisher.port

◆ stream

adctk.ldms_publisher.LDMSSystemPublisher.stream

The documentation for this class was generated from the following file: