json_exporter
json_exporter copied to clipboard
Reading logs from root level
Hello Geeks, We have our logs in following format (It is actually access log generate by https://traefik.io/).
`{"FirstKey":"100.244.3.1:33610","SecondKey":"10.100.3.1","ClientPort":"33610","ClientUsername":"-","DownstreamContentSize":2,"DownstreamStatus":200,"Duration":181433,"OriginContentSize":2,"OriginDuration":32322,"OriginStatus":200,"Overhead":149111,"RequestAddr":"10.100.3.116:5555","RequestContentSize":0,"RequestCount":1,"RequestHost":"10.100.3.116","RequestMethod":"GET","RequestPath":"/ping","RequestPort":"5555","RequestProtocol":"HTTP/1.1","RequestScheme":"http","RetryAttempts":0,"RouterName":"ping@internal","StartLocal":"2021-09-06T14:47:45.666034993Z","StartUTC":"2021-09-06T14:47:45.666034993Z","entryPointName":"ping","level":"info","msg":"","request_Connection":"close","request_User-Agent":"REDACTED","request_X-Forwarded-Host":"10.100.3.116:5555","time":"2021-09-06T14:47:45Z"}
{"FirstKey":"10.244.4.135:58614","SecondKey":"10.244.4.135","ClientPort":"58614","ClientUsername":"-","DownstreamContentSize":1718,"DownstreamStatus":200,"Duration":1600717,"OriginContentSize":1718,"OriginDuration":1492774,"OriginStatus":200,"Overhead":107943,"RequestAddr":"10.100.3.116:8082","RequestContentSize":0,"RequestCount":2,"RequestHost":"10.244.3.123","RequestMethod":"GET","RequestPath":"/metrics","RequestPort":"8888","RequestProtocol":"HTTP/1.1","RequestScheme":"http","RetryAttempts":0,"RouterName":"prometheus@internal","StartLocal":"2021-09-06T14:47:47.692249511Z","StartUTC":"2021-09-06T14:47:47.692249511Z","downstream_Content-Encoding":"gzip","entryPointName":"metrics","level":"info","msg":"","origin_Content-Encoding":"gzip","request_User-Agent":"REDACTED","request_X-Forwarded-Host":"10.244.3.116:8888","request_X-Prometheus-Scrape-Timeout-Seconds":"10.000000","time":"2021-09-06T14:47:47Z"}`
When we are trying to parse it for creating metrics, it is not working. It is failing with following issue
level=error msg="Failed to extract json objects for metric" err="invalid character '{' after top-level value" metric="Desc{fqName: \"unity_active\", help: \"unity\", constLabels: {}, variableLabels: [status environment]}"
If it is single JSON object, it works. But not for multiple JSON objects.
Can you please help!
A better solution for log parsing would be https://github.com/fstab/grok_exporter.
As for this issue, there is insufficient information: there is no config, or information about what metrics you are trying to extract and how.