You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Introduce simple metrics for payjoin-directory #735
I was wondering about the timeframe for maintaining this count, It might be helpful to quantify payjoin activity within a specific time period for more meaningful analysis.
Then with the data-dog agent installed on the server , we can collect the logs .
We could also post the data directly to the data-dog api which does not involve installing an agent on the server . Do you have a different approach in mind ?
I don't think we actually need to use datadog, that's probably overkill, but was providing it as an example of how event tracking is done in mainstream software. We can write our own simple counter.
Do you think metrics-exporter-prometheus crate and Metrics crate is enough for this . We definitely need to view this metrics else we wouldn't have a reason to store them . Prometheus seems to be the best way to collect this metrics , as metrics would be stored in memory and someone running a directory server woudn't need to install any third party software . i really want to work on this .
Prometheus sounds good to me and was also suggested in #471. Dan was able to produce a chart of sessions per day using our existing logs. @DanGould can you share how you did it and whether it makes sense to pursue this further or close this issue?
I wrote a python script to regex for timestamps and handle_v2 debug logs that contain shortIDs, then counting only unique shortIDs. This definitely should be baked in further. I want a dashboard where I can look at granular data by the day and soon enough by the hour
I wrote a python script to regex for timestamps and handle_v2 debug logs that contain shortIDs, then counting only unique shortIDs. This definitely should be baked in further. I want a dashboard where I can look at granular data by the day and soon enough by the hour
I found that Grafana works well with Prometheus for creating dashboards. We would need to host it ourselves.
Inspired by the discussion here, I played around with creating a simple nix flake which spins up Prometheus and Grafana exposing metrics for payjoin-directory by simply running nix develop.
The rationale as stated here is to make it as simple as possible for people to run a monitor-able payjoin-directory (and eventually ohttp-relay), while also solving our own problem.
Prometheus requires a /metrics endpoint to be exposed which payjoin-directory doesn't yet have, so just for the proof of concept in the meantime and since it's probably also useful to have, I used node_exporter which gives info about the underlying host machine.
@thebrandonlucas This is really nice! However, we still need to consider integrating metrics into the payjoin-directory crate. Specifically, we want to track how many sessions are opened and closed over time — something we can visualize on a dashboard like this one.
Since you're also interested in this, I’ll briefly outline my intended implementation so I can get your thoughts or suggestions. Tracking session openings is straightforward — a session opens when a sender posts a PSBT to the directory.
The tricky part is session closing. Ideally, a session closes when the sender broadcasts the transaction containing both their inputs and the receiver’s. However, since we may not have that visibility, we can approximate it by using the expiration time of the corresponding channel ID in Redis. Once the session expires there, we can consider it closed.
This is just the starting point — I believe over time, we’ll want to gather more detailed metrics, both beyond session open/close counts and with more granularity around session lifecycles.
The tricky part is session closing. Ideally, a session closes when the sender broadcasts the transaction containing both their inputs and the receiver’s. However, since we may not have that visibility, we can approximate it by using the expiration time of the corresponding channel ID in Redis. Once the session expires there, we can consider it closed.
IMO start with just the basics like counting the # of requests, focusing on the metrics endpoint and how to expose it. not sure if we want these metrics to be public, i think given the nature of the service we might consider making them available, but the metrics endpoint should be collected through a control plane network not a data plane in order to be useful in case of a DoS attack (even if the metrics endpoint is OK to publish on both)
later we can estimate session counts by using hyperloglog estimation of the # of unique shortids that were written to and the shortids that were read from, and just assume a shortid that was read from corresponds to a half session that is "closed", and estimate number of closed sessions by just dividing that in 2. further subdividing these estimates by response code (202 vs. 200 for GET) would also be useful for estimating session stats.
however, by design we don't have any visibility into session expiry or state, only messages with short IDs and payloads that are indistinguishable from randomness.
This is just the starting point — I believe over time, we’ll want to gather more detailed metrics, both beyond session open/close counts and with more granularity around session lifecycles.
see #775 (at the bottom) for additional metrics ideas, but IMO that can be done in followup work (i.e. first get metrics gathering working, both in the code and on the operational side), then iterate on specifically what metrics we want to keep track of)
Activity
zealsham commentedon Jun 4, 2025
I was wondering about the timeframe for maintaining this count, It might be helpful to quantify payjoin activity within a specific time period for more meaningful analysis.
spacebear21 commentedon Jun 4, 2025
I think the most straightforward solution would be to maintain a log of datapoints with a value and a timestamp - these points can then be grouped by whatever timeframe is preferred. Datadog does this: https://docs.datadoghq.com/metrics/
zealsham commentedon Jun 7, 2025
Thinking about this , We can do this in two ways , maybe others can offer more insight on which way is better . We could do something like
Then with the data-dog agent installed on the server , we can collect the logs .
We could also post the data directly to the data-dog api which does not involve installing an agent on the server . Do you have a different approach in mind ?
spacebear21 commentedon Jun 7, 2025
I don't think we actually need to use datadog, that's probably overkill, but was providing it as an example of how event tracking is done in mainstream software. We can write our own simple counter.
zealsham commentedon Jun 9, 2025
Do you think metrics-exporter-prometheus crate and Metrics crate is enough for this . We definitely need to view this metrics else we wouldn't have a reason to store them . Prometheus seems to be the best way to collect this metrics , as metrics would be stored in memory and someone running a directory server woudn't need to install any third party software . i really want to work on this .
spacebear21 commentedon Jun 9, 2025
Prometheus sounds good to me and was also suggested in #471. Dan was able to produce a chart of sessions per day using our existing logs. @DanGould can you share how you did it and whether it makes sense to pursue this further or close this issue?
DanGould commentedon Jun 9, 2025
I wrote a python script to regex for timestamps and handle_v2 debug logs that contain shortIDs, then counting only unique shortIDs. This definitely should be baked in further. I want a dashboard where I can look at granular data by the day and soon enough by the hour
arminsabouri commentedon Jun 10, 2025
I found that Grafana works well with Prometheus for creating dashboards. We would need to host it ourselves.
thebrandonlucas commentedon Jun 15, 2025
Inspired by the discussion here, I played around with creating a simple nix flake which spins up Prometheus and Grafana exposing metrics for
payjoin-directoryby simply runningnix develop.The rationale as stated here is to make it as simple as possible for people to run a monitor-able
payjoin-directory(and eventuallyohttp-relay), while also solving our own problem.Prometheus requires a
/metricsendpoint to be exposed whichpayjoin-directorydoesn't yet have, so just for the proof of concept in the meantime and since it's probably also useful to have, I usednode_exporterwhich gives info about the underlying host machine.https://github.com/thebrandonlucas/payjoin-directory-flake
Some screenshots of Prometheus and the

node_exporterdashboard:zealsham commentedon Jun 16, 2025
@thebrandonlucas This is really nice! However, we still need to consider integrating metrics into the payjoin-directory crate. Specifically, we want to track how many sessions are opened and closed over time — something we can visualize on a dashboard like this one.
Since you're also interested in this, I’ll briefly outline my intended implementation so I can get your thoughts or suggestions. Tracking session openings is straightforward — a session opens when a sender posts a PSBT to the directory.
The tricky part is session closing. Ideally, a session closes when the sender broadcasts the transaction containing both their inputs and the receiver’s. However, since we may not have that visibility, we can approximate it by using the expiration time of the corresponding channel ID in Redis. Once the session expires there, we can consider it closed.
This is just the starting point — I believe over time, we’ll want to gather more detailed metrics, both beyond session open/close counts and with more granularity around session lifecycles.
nothingmuch commentedon Jun 16, 2025
IMO start with just the basics like counting the # of requests, focusing on the metrics endpoint and how to expose it. not sure if we want these metrics to be public, i think given the nature of the service we might consider making them available, but the metrics endpoint should be collected through a control plane network not a data plane in order to be useful in case of a DoS attack (even if the metrics endpoint is OK to publish on both)
later we can estimate session counts by using hyperloglog estimation of the # of unique shortids that were written to and the shortids that were read from, and just assume a shortid that was read from corresponds to a half session that is "closed", and estimate number of closed sessions by just dividing that in 2. further subdividing these estimates by response code (202 vs. 200 for GET) would also be useful for estimating session stats.
however, by design we don't have any visibility into session expiry or state, only messages with short IDs and payloads that are indistinguishable from randomness.
see #775 (at the bottom) for additional metrics ideas, but IMO that can be done in followup work (i.e. first get metrics gathering working, both in the code and on the operational side), then iterate on specifically what metrics we want to keep track of)
spacebear21 commentedon Aug 27, 2025
Simple metrics (total connections count) were introduced in #848, closing this issue.