Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ The following metrics are available:

* **`nostr_client_messages_total{verb}`** - Total number of messages received from clients, broken down by verb (EVENT, REQ, CLOSE, NEG-OPEN, NEG-MSG, NEG-CLOSE)
* **`nostr_relay_messages_total{verb}`** - Total number of messages sent to clients, broken down by verb (EVENT, OK, EOSE, NOTICE, NEG-MSG, NEG-ERR)
* **`nostr_events_total{kind}`** - Total number of events processed, broken down by event kind (0, 1, 3, 4, etc.)
* **`nostr_events_total{kind}`** - Total number of events persisted to the DB, broken down by event kind (0, 1, 3, 4, etc.). Rejected and duplicate events are not counted here; see `strfry_write_rejected_total`, `strfry_write_dups_total` and `strfry_invalid_events_total`

To scrape these metrics with Prometheus, add a job to your `prometheus.yml`:

Expand Down
5 changes: 5 additions & 0 deletions src/PrometheusMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class PrometheusMetrics {
// Write path performance metrics
Counter writtenEventsTotal;
Counter rejectedEventsTotal;
Counter invalidEventsTotal; // EVENT messages that failed validation before reaching the writer
Counter dupEventsTotal;
Counter writeTimeUs; // total microseconds spent in write transactions
Gauge lastWriteBatchSize;
Expand Down Expand Up @@ -152,6 +153,10 @@ class PrometheusMetrics {
out << "# TYPE strfry_write_rejected_total counter\n";
out << "strfry_write_rejected_total " << rejectedEventsTotal.get() << "\n";

out << "# HELP strfry_invalid_events_total Total EVENT messages rejected before the write path because they failed validation\n";
out << "# TYPE strfry_invalid_events_total counter\n";
out << "strfry_invalid_events_total " << invalidEventsTotal.get() << "\n";

out << "# HELP strfry_write_dups_total Total duplicate events skipped\n";
out << "# TYPE strfry_write_dups_total counter\n";
out << "strfry_write_dups_total " << dupEventsTotal.get() << "\n";
Expand Down
1 change: 1 addition & 0 deletions src/apps/relay/RelayIngester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void RelayServer::runIngester(ThreadPool<MsgIngester>::Thread &thr) {
try {
ingesterProcessEvent(txn, rsctx, msg->connId, msg->ipAddr, arr[1], writerMsgs);
} catch (std::exception &e) {
PrometheusMetrics::getInstance().invalidEventsTotal.inc();
sendOKResponse(msg->connId, arr[1].is_object() && arr[1].at("id").is_string() ? arr[1].at("id").get_string() : "?",
false, std::string("invalid: ") + e.what());
if (cfg().relay__logging__invalidEvents) LI << "Rejected invalid event: " << e.what();
Expand Down