Skip to main content

Historical Alarm Storage

Purpose

This target writes alarm activation and recovery records at or above a selected level to a database. Use the stored records for historical alarm queries and reports.

Configure forwarding group ranges, offline cache, and runtime state through Data Forwarding. This page covers only the alarm table, level filter, dual-database mirror, and debug panels specific to historical alarms.

Open the plugin

Open Development Configuration → Data Forwarding and:

  1. Save the forwarding-group variable range.
  2. Add a target, choose Historical Alarm Storage, and fill in the basic target information.
  3. Open Target properties and configure the relational database, table, retention, time zone, and minimum alarm level.
  4. Optionally select a saved Historical alarm table script or enable the relational dual-database mirror. These modes are mutually exclusive.
  5. Save and enable the target, then activate and recover an approved test alarm.

Basic target information

SettingDefaultConfiguration
Group-Select a saved forwarding group.
Target name-Required and unique within the group.
EnableEnabledDisable to stop alarm-table initialization and writes.
Log levelInfoTemporarily use Debug for database or alarm-write diagnostics.
Start timeout60 secondsValid range is 1 to 3600 seconds.

Target properties

SettingDefaultConfiguration
Database typeSqlServerSupports SqlServer, MySql, Sqlite, and PostgreSql.
Split-table strategyNo splitRelational databases can split by day, week, month, quarter, year, or a custom split service.
Connection stringDevelopment SQL Server exampleReplace with the actual endpoint, database, account, and password; the account needs create, query, insert, and delete permissions.
Historical alarm tablehistoryAlarmTable storing alarm activation and recovery records. Use a separate name for each target when appropriate.
Retention days3650Positive integer; values below 1 are normalized to 1. Cleanup uses alarm EventTime.
Historical alarm table scriptEmptySelect a saved Dynamic SQL expression. The script owns table creation, writes, and cleanup; empty uses the standard table.
Time-zone offset+08:00Enter a fixed offset such as +08:00 or -05:00; empty means UTC. Use the same convention when querying.
Minimum alarm level0Stores only alarms where AlarmLevel >= this value; lower-level alarms and recoveries are ignored.
Dual-database mirrorDisabledRelational standard tables only; fill a different physical backup database.

Relational connection strings

DatabaseExample
SQL ServerServer=127.0.0.1,1433;Database=thingsgateway_alarm;User Id=history_user;Password=<password>;TrustServerCertificate=True;
MySQLServer=127.0.0.1;Port=3306;Database=thingsgateway_alarm;Uid=history_user;Pwd=<password>;
SQLiteData Source=DB/alarm.db;journal mode=WAL
PostgreSQLHost=127.0.0.1;Port=5432;Database=thingsgateway_alarm;Username=history_user;Password=<password>;

Dual-database mirroring supports SQL Server, MySQL, SQLite, and PostgreSQL. The primary and backup must be different physical databases, and Historical alarm table script must be empty. The automatic check, automatic fill, and capacity fields are the same as Historical Data Storage.

Target-variable properties

This plugin has no target-variable properties. Alarm inclusion is controlled only by the forwarding-group range and Minimum alarm level.

Cache and capacity

SettingDefaultConfiguration
Enable failed-write retry cacheDisabledEnable to retain alarms when the database is unavailable and replay them after recovery.
Cache file maximum rows262144Maximum CacheDB outbox alarm rows.
Upload chunk size2000Maximum alarms per write or replay batch.
Memory queue limit100000Maximum in-memory alarm records.
Filter offline dataDisabledThe property is exposed by the common target, but alarm acceptance is controlled by group range and minimum alarm level.
Upload concurrency1Default serial write; increase only after database load testing.

Target debug

Open Development Configuration → Data Forwarding, select the forwarding group and target, and open Debug.

FeaturePurpose
Forwarding pipelineShows the forwarding group range and alarm data entering the target.
Cache outboxShows pending alarms, retained retries, and the latest error.

Forwarding pipeline

Historical Alarm Storage forwarding pipeline

Use the pipeline to confirm the forwarding group range, target state, and alarm data entering the target.

Cache outbox

Historical Alarm Storage cache outbox

The cache outbox shows the alarm queue, CacheDB pending rows, retained retries, and latest error. When offline cache is enabled, pending alarms are written after the database recovers.

Verify the target

  1. Enable the forwarding group and target, then confirm that the target is online.
  2. Use an approved test variable to activate and recover an alarm at or above Minimum alarm level.
  3. Query the historical alarm table and confirm that both activation and recovery records were written.

Troubleshooting

SymptomCheck
Alarm is not storedThe alarm was activated, its level meets the minimum, and the target is online.
Target does not startDatabase connection, table name, split-table strategy, and account permissions.
Alarms are not written after recoveryOffline cache setting, cache outbox, and target log.
Dual-database mirror cannot startThe primary and backup are different, both database types are supported, and the historical alarm table script is empty.