Closed Vinalti closed 1 year ago
the way I see it we have many keys classified in categories , and they all are shown like that :
<key>{<content>} <value>
example:
monitor_status{monitor_name="router",monitor_type="http",monitor_url="https://192.168.0.1/",monitor_hostname="null",monitor_port="null"} 1
# ^key ^content ^value
Also the content
is optional.
monitor_
process_
nodejs_
app_
app_version
http_
expressjs_
each group of line is preceded by description with the following keys:
# HELP <key> <description>
# TYPE <key> <type>
I would think we can split the key with the first _
in order to group them by categories.
I think the output could be an object like that:
{
"monitors": [
{
"key": "<key>",
"description": "<description>",
"type": "<type>",
"content": [
{
"value": "<value>"
#... (Content of the dict)
}
]
}
]
}
I dont think it makes sense to parse the metrics directly in this python module.
The python module prometheus-client
that you mentioned above contains a parser that does just that.
So if you need this data, you can install the library and parse the metric string. This way, there is no need to add another dependency for a feature that is probably not used very often.
But what probably makes sense is to add a method that returns the metrics string. Something like that:
def metrics(self, api_key: str) -> dict:
r = requests.get(f"{self.url}/metrics", auth=("user", api_key))
return r.text
Summary
The endpoint
/metrics
allow authentication with API key and provide most metrics. It can be useful to retrieve status of monitoring and kuma server in one go.It is a polling endpoint and therefore it doesn't use the
SocketIO
protocol but a simpleHTTP GET
request is enough.The only drawback is that this endpoint provide data in a specific format for
Prometheus
, so a good parsing will be required to extract the values.I propose to add that to the next main release.
Checklist
/metrics
Syntax
_source_
It would seem that it's made to be parsed in Golang, also, a go package already exists for that. I am not sure if we could use that as a "library" or middleware to extract the data.
Alternatively, the prometheus syntax is based on EBNF language. EBNF parsers exists in different languages so we could use that as well.
Ressources