Creating log-based metric to count unique field values in logs

Hey guys, I have some logs stored in loki, and the log lines have the following fields / labels:

  • node_id
  • block_height
  • block_id

The logs are aggregated coming from multiple instances of a service (node_id is the instance id).

For example, if I make the following query in the log browser:

{app="execution",network="mainnet16"} | json | block_height="24439205"

then I might get the following results:

2022-02-19 17:50:37	
{"node_id":"9686399a8a5418a12e762cfaeff2ea348c2137f554560917760e0d47acf2cda4","block_id":"6eba203f896e84f07103dbbad22a99968e1c3b8763e07db759806091ad0d12c2","block_height":24439205}
2022-02-19 17:50:35	
{"node_id":"4ab025ab974e7ad7f344fbd16e5fbcb17fb8769fc8849b9d241ae518787695bd","block_id":"6eba203f896e84f07103dbbad22a99968e1c3b8763e07db759806091ad0d12c2","block_height":24439205}
2022-02-19 17:50:35	
{"node_id":"0ca407c1da940952ebcc02283b60cd97c9a008e111a48ea6cf1ce8f36f1e0153","block_id":"6eba203f896e84f07103dbbad22a99968e1c3b8763e07db759806091ad0d12c2","block_height":24439205}
2022-02-19 17:50:35	
{"node_id":"160241f88cbfaa0f361cf64adb0a1c9fc19dec1daf4b96550cd67b7a9fb26cd9","block_id":"6eba203f896e84f07103dbbad22a99968e1c3b8763e07db759806091ad0d12c2","block_height":24439205}

I’d like to achieve the following:

  • For a given block_height, compute the number of distinct block_id values. In the example above, the value would be 1 because all four log lines have the same block_id value.
  • Create a dashboard for this value, where block_height is on the x-axis, and the value as computed above is the y-axis.

Can anyone point me in the right direction on how to do this, or know if this is even possible? At the moment, I’m just trying to simply compute the number of distinct block_id values for a single block_height, and I can’t seem to even get that working. Thank you very much for the help.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.