@@ -35,19 +35,24 @@ namespace IO
3535 {
3636 if (PQstatus (con) != CONNECTION_OK)
3737 {
38+ stats.connected = 0 ;
3839 Warning () << " DBMS: Connection to PostgreSQL lost. Attempting to reset..." ;
3940 PQreset (con);
4041
4142 if (PQstatus (con) != CONNECTION_OK)
4243 {
4344 Error () << " DBMS: Could not reset connection. Aborting post." ;
4445 conn_fails++;
46+ stats.connect_fail ++;
4547 return ;
4648 }
4749 else
4850 {
4951 Warning () << " DBMS: Connection successfully reset." ;
5052 conn_fails = 0 ;
53+ stats.connected = 1 ;
54+ stats.connect_ok ++;
55+ stats.reconnects ++;
5156 }
5257 }
5358
@@ -92,7 +97,11 @@ namespace IO
9297 7 , nullptr , params, nullptr , nullptr , 0 );
9398
9499 if (PQresultStatus (res) == PGRES_TUPLES_OK && PQntuples (res) > 0 )
100+ {
95101 msg_id = PQgetvalue (res, 0 , 0 );
102+ for (const char *p : params)
103+ stats.bytes_out += strlen (p);
104+ }
96105 else
97106 {
98107 Error () << " DBMS: ais_message insert failed: " << PQerrorMessage (con);
@@ -122,6 +131,10 @@ namespace IO
122131 Error () << " DBMS: ais_nmea insert failed: " << PQerrorMessage (con);
123132 ok = false ;
124133 }
134+ else
135+ {
136+ stats.bytes_out += nmea.length ();
137+ }
125138 PQclear (res);
126139 if (!ok)
127140 break ;
@@ -169,8 +182,8 @@ namespace IO
169182 }
170183 }
171184
172- // 4. Vessel upsert
173- if (ok && VD)
185+ // 4. Vessel upsert (requires identifiable mmsi)
186+ if (ok && VD && entry. mmsi != " 0 " )
174187 ok = execVessel (entry, msg_id_ptr);
175188
176189 // 5. Property inserts
@@ -375,9 +388,14 @@ namespace IO
375388 con = PQconnectdb (conn_string.c_str ());
376389
377390 if (con == nullptr || PQstatus (con) != CONNECTION_OK)
391+ {
392+ stats.connect_fail ++;
378393 throw std::runtime_error (" DBMS: cannot open database :" + std::string (PQerrorMessage (con)));
394+ }
379395
380396 conn_fails = 0 ;
397+ stats.connected = 1 ;
398+ stats.connect_ok ++;
381399
382400 PGresult *res = PQexec (con, " SELECT key_id, key_str FROM ais_keys" );
383401 if (PQresultStatus (res) != PGRES_TUPLES_OK)
0 commit comments