smax-postgres v0.9
PostgreSQL / TimescaleDB logger for SMA-X
Loading...
Searching...
No Matches
logger-config.c File Reference

Macros

#define _GNU_SOURCE
 C source code standard.
 
#define LOOKUP_INITIAL_CAPACITY   65536
 Initial hashtable capacity.
 
#define MIN_AGE   ( 1 * DAY )
 (s) Provide slow updates for unchanging variable at least this long
 
#define MIN_SIZE   8
 (bytes) Always log variable up to this size, no matter
 

Functions

logger_propertiesgetLogProperties (const char *id)
 
int getMaxLogSize ()
 
int getSampleCount (const Variable *u)
 
const char * getSMAXServerAddress ()
 
int getSnapshotInterval ()
 
const char * getSQLAuth ()
 
const char * getSQLDatabaseName ()
 
const char * getSQLServerAddress ()
 
const char * getSQLUserName ()
 
int getUpdateInterval ()
 
boolean isLogging (const char *id, double updateTime)
 
boolean isUseHyperTables ()
 
int parseConfig (const char *filename)
 
int setSMAXServerAddress (const char *addr)
 
int setSQLAuth (const char *passwd)
 
int setSQLDatabaseName (const char *name)
 
int setSQLServerAddress (const char *addr)
 
int setSQLUserName (const char *name)
 
void setUseHyperTables (boolean value)
 

Detailed Description

Date
Created on Nov 1, 2023
Author
Attila Kovacs

Configuration support for smaxLogger.

Function Documentation

◆ getLogProperties()

logger_properties * getLogProperties ( const char *  id)

Returns the currently configured logging properties for an SMA-X variable.

Parameters
idThe aggregate name/ID of the SMA-X variable
Returns
Pointer to the logging properties data structure, or NULL if there isn't one or if the id was NULL (errno will be set to EINVAL in case of the latter).

◆ getMaxLogSize()

int getMaxLogSize ( )

Returns the maximum byte size for automatically logged variables, in their binary storage format. For variables that are sampled at some interval

Returns
(bytes)

◆ getSampleCount()

int getSampleCount ( const Variable u)

Returns the number of samples that should be logged into the SQL database for a given SMA-X variable, which may be different from the element count of the variable by a configured downsampling factor.

Parameters
uPointer to the variable's data structure
Returns
the number of samples that should be stored in the SQL database, or 0 if the argument was NULL.

References Variable::field, Variable::sampling, and xGetFieldCount().

◆ getSMAXServerAddress()

const char * getSMAXServerAddress ( )

Returns the SMA-X server host name or IP address.

Returns
the host name or IP address of the SMA-X server
See also
setSMAXServerAddress()

References SMAX_DEFAULT_HOSTNAME.

◆ getSnapshotInterval()

int getSnapshotInterval ( )

Returns the currently configured snapshot interval. Snapshots will be taken in the regular update cycle, whenever the time since the last snapshot equals or exceeds the set interval. For example, if the update interval is '2m', and the snapshot interval is '11m', then snapshots will be generated at every 6th update cycle, that is at every 12 minutes.

Returns
(s) the currently configured snapshot interval. Values <=0 indicate that snapshots are disabled.
See also
getUpdateUniterval()

◆ getSQLAuth()

const char * getSQLAuth ( )

Returns the SQL database password to use when connecting to the database.

Returns
The password to use for logging into the SQL database, or NULL to use passwordless login
See also
setSQLAuth()

◆ getSQLDatabaseName()

const char * getSQLDatabaseName ( )

Returns the SQL database to use when connecting to the database.

Returns
The database name to select for logging into the SQL server
See also
setSQLDatabaseName()

References DEFAULT_SQL_DB.

◆ getSQLServerAddress()

const char * getSQLServerAddress ( )

Returns the SQL server host name or IP address.

Returns
the host name or IP address of the SQL server
See also
setSQLServerAddress()

References DEFAULT_SQL_SERVER.

◆ getSQLUserName()

const char * getSQLUserName ( )

Returns the SQL user name to use when connecting to the database.

Returns
The username to use for logging into the SQL database
See also
setSQLUserName()

References DEFAULT_SQL_USER.

◆ getUpdateInterval()

int getUpdateInterval ( )

Returns the currently configured update interval.

Returns
(s) the currently configured snapshot interval. Values <=0 indicate that snapshots are disabled.
See also
getUpdateUniterval()

◆ isLogging()

boolean isLogging ( const char *  id,
double  updateTime 
)

Checks if a given variable is to be logged into the SQL database

Parameters
idThe aggregate name/ID of the SMA-X variable
updateTime(s) UNIX timestamp when the variable was last updated in the SMA-X database.
Returns
TRUE (1) if the variable should be logged into the SQL database, or else FALSE (0)

References logger_properties::exclude, FALSE, logger_properties::force, getLogProperties(), LOOKUP_INITIAL_CAPACITY, and TRUE.

◆ isUseHyperTables()

boolean isUseHyperTables ( )

Checks whether to use TimescaleDB hypertables. TimescaleDB is available for PostgreSQL only, so the setting will not affect other database backends.

Returns
TRUE (1) if to create hypertables for new variables, if possible, or else FALSE (0).
See also
setUseHyperTables()

◆ parseConfig()

int parseConfig ( const char *  filename)

Pases settings from a specified configuration file

Parameters
filenamethe file name / path of the configuration to load.
Returns
0 if successful, or else -1 (errno will indicate the type of error).

References dprintf, FALSE, MIN_AGE, MIN_SIZE, MINUTE, setSMAXServerAddress(), setSQLAuth(), setSQLDatabaseName(), setSQLServerAddress(), setSQLUserName(), TRUE, and X_SEP.

◆ setSMAXServerAddress()

int setSMAXServerAddress ( const char *  addr)

Sets the SMA-X server address or IP.

Parameters
addrThe host name or IP address of the SMA-X server
Returns
0 if successful, or else -1 if the name is NULL (errno will be set to EINVAL)
See also
getSMAXServerAddress()

◆ setSQLAuth()

int setSQLAuth ( const char *  passwd)

Sets the SQL database password to use when connecting to the database.

Parameters
passwdThe SQL database password to use
Returns
0
See also
getSQLAuth()
setSQLDatabaseName()
setSQLUserName()
setSQLServerAddress()

◆ setSQLDatabaseName()

int setSQLDatabaseName ( const char *  name)

Sets the SQL database name to select when connecting to the SQL server.

Parameters
nameThe SQL database name
Returns
0 if successful, or else -1 if the name is NULL (errno will be set to EINVAL)
See also
getSQLDatabaseName()
setSQLUserName()
setSQLAuth()
setSQLServerAddress()

◆ setSQLServerAddress()

int setSQLServerAddress ( const char *  addr)

Sets the SQL server address or IP.

Parameters
addrThe host name or IP address of the SQL server
Returns
0 if successful, or else -1 if the name is NULL (errno will be set to EINVAL)
See also
getSQLServerAddress()
setSQLDatabaseName()
setSQLUserName()
setSQLAuth()

◆ setSQLUserName()

int setSQLUserName ( const char *  name)

Sets the SQL user name to use when connecting to the database.

Parameters
nameThe SQL database user name
Returns
0 if successful, or else -1 if the name is NULL (errno will be set to EINVAL)
See also
getSQLUserName()
setSQLDatabaseName()
setSQLAuth()
setSQLServerAddress()

◆ setUseHyperTables()

void setUseHyperTables ( boolean  value)

Sets whether to use TimescaleDB hypertables extension. TimescaleDB is available for PostgreSQL only, so the setting will not affect other database backends.

Parameters
valueTRUE (non-zero) to enable TimescaleDB hypertables.
See also
isUseHyperTables()