Need help on dynamic labels for nginx (Promtail/Loki/Regex)

Basically i was trying to create metrics from raw logs of nginx sent through promtail with below config.

http_listen_port: 9080
grpc_listen_port: 0


  • job_name: nginx_jlog
    • targets:
      • localhost
        job: onion-nginx
        mylabel: nginx-jdev
        path: /var/log/nginx/access.log

i am able to execute below querry but result is not as expected.

sum by (statuscode) (count_over_time({filename="/var/log/nginx/access.log"} |~ “HTTP/1.1” (?P\d{3}) "[$__interval]))

it gives me over all count but its not giving able to sum by status code.

Any help on this would be much appreciated!