To add a Loki report in Grafana, as for example having a count of the different http_user_agents that have logged in, you can use the following query:
count by (http_agent) (rate({namespace="ingress-nginx",stream="stdout"} |= "https://domain.name.com/session/new" |~ "GET\\s/\\s" | pattern "<ip> - - [<timestamp>] \"<method> <path> <version>\" <result> <_> \"<url>\" \"<http_agent>\" <_>" [$__interval]))
You select the source (Loki) and then use the {namespace=”ingress-nginx”,stream=”stdout”} to get the log files from Nginx.
Then you can filter by two conditions:
- the instance login
|= "https://domain.name.com/session/new"
and
- use the regular expression to only select the GET / calls
|~ "GET\\s/\\s"
Then you can use the pattern parser for the log file in order to get the label
pattern "<ip> - - [<timestamp>] \"<method> <path> <version>\" <result> <_> \"<url>\" \"<http_agent>\" <_>"
<_> is used if we are not interested in getting the field, so everything after http_agent is not analyzed in this case.
Finally use the
count by(http_agent)
to get the data (note that you also need to use the rate with the [$__interval])