send once at the very end of the send process. do not send every 5 seconds as current omf_translator is not a long running process but rather a short lived one
@@ -58,6 +58,7 @@ import aiopg
import aiopg.sa
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import JSONB
+from foglamp import statistics
# Module information
__author__ = "${FULL_NAME}"
@@ -66,7 +67,7 @@ __license__ = "Apache 2.0"
__version__ = "${VERSION}"
# FIXME: we need to [SHOULD] move this to defaults.py! unless this also needs to be read from database
-_DB_URL = 'postgresql://foglamp:foglamp@localhost:5432/foglamp'
+_DB_URL = 'postgresql:///foglamp'
"""DB references"""
_LOG_SCREEN = True
@@ -146,6 +147,9 @@ _sensor_name_type = {}
_pg_conn = ""
_pg_cur = ""
+# statistics
+_num_sent = 0
+_num_unsent = 0
def initialize_plugin():
"""Initializes the OMF plugin for the sending of blocks of readings to the PI Connector.
@@ -178,7 +182,7 @@ def initialize_plugin():
try:
# URL
- _server_name = "WIN-4M7ODKB0RH2"
+ _server_name = "192.168.0.221"
_relay_url = "http://" + _server_name + ":8118/ingress/messages"
# OMF types definition - xxx
@@ -870,6 +874,7 @@ async def send_info_to_omf():
global _type_sensor_id
global _type_measurement_id
+ global _num_sent
info_handled = False
db_row = ""
@@ -918,7 +923,7 @@ async def send_info_to_omf():
# Loads data into OMF
values = create_data_values_stream_message(_measurement_id, db_row)
send_omf_message_to_end_point("Data", values)
-
+ _num_sent += 1
info_handled = True
message = "### completed ##################################################"
@@ -936,6 +941,13 @@ async def send_info_to_omf():
_log.error(message)
raise Exception(message)
+async def _update_statistics():
+ global _num_readings
+ global _num_discarded_readings
+ await statistics.update_statistics_value('SENT', _num_sent)
+ _num_readings = 0
+ await statistics.update_statistics_value('UNSENT', _num_unsent)
+ _num_discarded_readings = 0
if __name__ == "__main__":
@@ -952,5 +964,6 @@ if __name__ == "__main__":
omf_types_creation()
asyncio.get_event_loop().run_until_complete(send_info_to_omf())
+ asyncio.get_event_loop().run_until_complete(_update_statistics())
debug_msg_write("INFO", _message_list["i000003"])
