rstatmon package

Submodules

rstatmon.application module

rstatmon.auth module

exception rstatmon.auth.LoginForm(*args, **kwargs)

Bases: flask_wtf.form.FlaskForm, wtforms.validators.ValidationError

Form class for login.

check_validate()bool

Validates the sumbmitted form.

Returns

True if the form is valid, otherwise False.

Return type

bool

password = <UnboundField(PasswordField, ('Password',), {})>
submit = <UnboundField(SubmitField, ('Login',), {})>
username = <UnboundField(StringField, ('username',), {})>
validate_password(password)

Check whether the submitted password is empty.

validate_username(username: wtforms.fields.core.StringField)

Check whether the submitted username is empty.

class rstatmon.auth.RegistrationForm(*args, **kwargs)

Bases: flask_wtf.form.FlaskForm

Form class for creating new account.

check_validate()bool

Validates the sumbmitted form.

Returns

True if the form is valid, otherwise False.

Return type

bool

confirm_password = <UnboundField(PasswordField, ('Confirm Password',), {'validators': [<wtforms.validators.DataRequired object>, <wtforms.validators.EqualTo object>]})>
password = <UnboundField(PasswordField, ('Password',), {'validators': [<wtforms.validators.Length object>]})>
submit = <UnboundField(SubmitField, ('Sign Up',), {})>
username = <UnboundField(StringField, ('Username',), {'validators': [<wtforms.validators.Length object>]})>
validate_password(password: wtforms.fields.simple.PasswordField)

Check whether the submitted password is valid.

The password must satisfy following requirements.
  • Length is between 4 and 20.

  • Contains only alphabets, numbers and symbols in ascii.

Parameters

password (StringField) – password field.

Raises

ValidationError – Field is invalid.

validate_username(username: wtforms.fields.core.StringField)

Check whether the submitted username is valid.

The username must satisfy following requirements.
  • Length is between 2 and 30.

  • Contains only alphabets, numbers and symbols in ascii.

Parameters

username (StringField) – Username field.

Raises

ValidationError – Field is invalid.

rstatmon.database module

Module for accessing to databases.

class rstatmon.database.DBInit(username: str = 'root', password: Optional[str] = None, host: str = 'localhost', port: int = 3306)

Bases: object

Initializing database to save user’s accounts.

add_admin()

Adds an admin user if not exist.

Adds the user if not exist in the table. The user is

  • Username : admin

  • Password : admin

  • User ID : 000

create_database()

Creates new database.

The database named “raspi” is created with mysql.

create_table()

Creates new table if not exist.

The table named ‘user’ to store information about user’s account is created in the database.

db_setup()
delete_database()
read_json(js: str)
class rstatmon.database.User(**kwargs)

Bases: sqlalchemy.orm.decl_api.Model, flask_login.mixins.UserMixin

get_id()
password
user_id
username
class rstatmon.database.User2(**kwargs)

Bases: sqlalchemy.orm.decl_api.Base

password
user_id
username
rstatmon.database.init_db(app)

rstatmon.db_setup module

rstatmon.db_setup.main()

rstatmon.mylogger module

class rstatmon.mylogger.MyLogger

Bases: object

Logging class with loguru module.

get_log_dst()

Determines the file to write log to.

The format of the filename is The log file is stored in the ‘data/log’ directory.

log_compress()

Compress log file to tar.gz

logger_setup()
write_log(msg: str, level: str)

Writes a message to log file.

The message is written to the file determined in the ‘get_log_dst`. The logging level shows the importtance of the message and is classfied by as follows.

  • info : Information

  • success: Operation success such as login and logout

  • error: Operation failure such as login and logout

Parameters
  • msg (str)) – A message to write

  • level (str) – Logging level

rstatmon.passhash module

rstatmon.passhash.init_bcrypt(app)

rstatmon.routes module

rstatmon.rstatmon module

rstatmon.statdata module

Module for accuiring statistical data

class rstatmon.statdata.Hardware

Bases: object

Class about hardware information.

get_boot_time()str

Gets the time when the system booted.

Returns

The time system bboted in the format of %Y-%m-%d %H:%M:%S

Return type

str

get_disk()float

Gets free space under the root direcotory ‘/’ in unit of GB.

Returns

Disk space

Return type

float

get_hard_info()dict

Gets the list of the hardware information.

Returns

The hardware information.

Return type

dict

get_kernel()str

Gets kernel information.

Returns

kernel

Return type

str

get_memory()float

Gets memory size in unit of GB

Returns

Memory size

Return type

float

get_model()str

Gets a model of the hardware

Note

This method is valid for only raspberry pi OS.

Returns

String showing the model.

get_operating_time()float

Gets the operating time in unit of hour.

Returns

The operating time.

Return type

float

get_os()str

Gets OS

Returns

OS

Return type

str

class rstatmon.statdata.StatData(debug: bool = False)

Bases: object

check_duration(value: int)bool
check_input_params(data: dict, graph: str)Tuple[bool, str]
check_yaxes(value: Union[int, float], graph: str)bool
data_with_log(dst: pathlib.Path)
digit_format(lst: list)list
exist_logs()list
get_alldata()dict
get_core_freq()str

Gets the VC4 scaler cores frequency of the clock.

Returns

The VC4 scaler cores frequency

Return type

str

get_cpu_freq()str

Gets the CPU frequency of the clock.

Returns

The CPU frequency

Return type

str

get_cpu_memory()str

Gets the size of the memory currently allocated to the cpu.

Returns

The memory size

Return type

str

get_cpu_temperature()str

Gets the CPU temperature.

Returns

The CPU temperature

Return type

str

get_cpu_usage()dict

Gets the current cpu usage.

Returns

The usage of each cpu.

Return type

dict

get_csv()pathlib.Path
get_date(path: str, ret_date: bool = False)str

Converts string showing the specified date into abs path if exists.

The path should be in the format of yyyymmdd.

Parameters

path (str) – [description]

Returns

[description]

Return type

str

get_dummydata()dict
get_gpu_memory()str

Gets the size of the memory currently allocated to the gpu.

Returns

The memory size

Return type

str

get_loadavg()dict

Gets load average.

Returns

The load averages of 1, 5, 15 minutes.

Return type

dict

get_sampling_rate(num: str, unit: str)str

Parses the string for data resampling.

The input string showing the time rate is parsed to get the string specified with the resample method in pandas. The parsed string is splited into num and str, showing the time and unit respectively. Finally,

Parameters

rate (str) – [description]

Returns

[description]

Return type

str

Examples

>> parser_sample_rate(“1hour”) >> “1h”

read_log(path: str, rate: str)dict
time_relation(t1: str, t2: str)bool
time_validate(start: str, end: str)bool

Check if the input string is valid.

Returns true if the time is HH::MM, otherwise false.

Parameters

t (str) – [description]

Returns

[description]

Return type

bool

rstatmon.statdata.routine(debug: bool = False)

rstatmon.usermodel module

class rstatmon.usermodel.JinjaTemplate(data: dict)

Bases: object

load_body()
load_template(body: dict)
make_template()
parse_dict()
parse_int(data)
remove_model()
writer(data: str)
class rstatmon.usermodel.UserModel

Bases: object

Handles user-defined model described in python scripts.

delete_model(src: str)

Delete python file corresponding to model in the dst dir.

Parameters

src (str) – File name of python to delete

execute(pyfile: str)

Execute model file.

Parameters

pyfile (str) – The model file.

get_current_model()str

Gets a file name corresponding to the model.

Returns

The file name in the format of abs path.

Return type

str

get_value()
import_models()list
register_model(src: str)

Register a specified model as new one.

Parameters

src (str) – The file path to register.

remove_current_model()
set_current_model(model: Union[pathlib.Path, str])
update_json()

Update model json

Json consists of key and value. In case of “test.py” model, key and value are as follows respectively. test : test.py

validate_model(path: pathlib.Path)bool

Module contents