Tobias Klausmann
unread,Sep 14, 2023, 9:36:12 AM9/14/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
Hi!
I am trying to write Prometheus exporter for stats queried fro the Kea
DHCP server. Unfortunatly, the JSON is structured very badly if I want
to use the base library JSON Unmarshal functionality:
{
"arguments": {
"cumulative-assigned-addresses": [ [ 1, "2023-09-13 12:08:09.597483" ], ... ],
"pkt4-decline-received": [ [ 0, "2023-09-13 08:01:35.964113" ], ... ],
"subnet[1].assigned-addresses": [ [ 1, "2023-09-13 08:01:36.014127" ], ... ],
"subnet[1].cumulative-assigned-addresses": [ [ 0, "2023-09-13 08:01:36.014006" ], ... ],
"subnet[1].declined-addresses": [ [ 0, "2023-09-13 08:01:36.014069" ], ... ],
"subnet[1].reclaimed-declined-addresses": [ [ 0, "2023-09-13 08:01:36.014074" ], ... ],
"subnet[1].reclaimed-leases": [ [ 0, "2023-09-13 08:01:36.014080" ], ... ],
"subnet[1].total-addresses": [ [ 15, "2023-09-13 08:01:36.013997" ], ... ],
"subnet[1].v4-reservation-conflicts": [ [ 0, "2023-09-13 08:01:36.014010" ], ... ],
"subnet[2].assigned-addresses": [ [ 4, "2023-09-14 13:32:20.906085" ], ... ],
"subnet[2].cumulative-assigned-addresses": [ [ 4, "2023-09-14 13:32:20.906090" ], ... ],
"subnet[2].declined-addresses": [ [ 0, "2023-09-13 08:01:36.014088" ], ... ],
"subnet[2].reclaimed-declined-addresses": [ [ 0, "2023-09-13 08:01:36.014096" ], ... ],
"subnet[2].reclaimed-leases": [ [ 3, "2023-09-14 00:08:10.270122" ], ... ],
"subnet[2].total-addresses": [ [ 223, "2023-09-13 08:01:36.014015" ], ... ],
"subnet[2].v4-reservation-conflicts": [ [ 0, "2023-09-13 08:01:36.014025" ], ... ],
"subnet[3].assigned-addresses": [ [ 1, "2023-09-13 08:01:36.014135" ], ... ]
... rest of subnet[3] and more subnets
},
"result": 0
}
The int, timestamp lists are already Not Great, but I can deal with
those.
The problem is the series of subnet[x] fields. They vary depending on
how many subnets the server serves, and nothing in the JSON indicates
how many there are. And even if it did: getting the stdlib JSON
Unmarshaler to actually pick them up (without hardcoded struct tags)
seems impossible, short of essentially writing my own JSON Unmarshaler
from scratch.
So I have three questions:
1. Am I missing some wildcard-ish functionality where I can tell the
stdlib JSON Unmarshaler just make a slice out of all the JSON
elements that fit a pattern?
2. Is there a Golang JSON library that is better suited to dealing with
this?
3. What other options do I have (besides "use another
language/exporter", "make upstream produce better JSON" and "write
your own parser")?
Best & TIA,
Tobias