Grafana Alloy: Grok Exporter Type functionality

Hello,

I am trying to find out if the Grafana Alloy Agent has some type of functionality that can replication Grok Exporter. In an older system we use Grok Exporter to transform Application log files to metrics and we’d like to have something similar in another system. At the moment it would just be very simple metrics regarding the log level, info, warn, error etc. I have seen that this probably could be done with Grafana Loki but we want to avoid the introduction of another component. We could just use Grok Exporter but again we’d like to avoid the installation of yet another agent. We are running in an AWS environment and using Amazon Managed Prometheus/Grafana. Does anyone have any insight here?

Regards,

Rhys

I haven’t tried to do this, so I could be entirely wrong here, but loki.process has a metrics block, that can be used to expose metrics at Alloy’s default listener port at /metrics. You should be able to then configure Alloy to scrape from itself and then forward from there. See loki.process | Grafana Alloy documentation

Thanks for the tip Tony. I will check it out.

Rhys

Hi Tony,

Just a quick update but you were right!I’ve included a simplified example below but basically this tails a log file, runs a regex against each line, and populates metrics as appropriate. These are then available on the default /metrics endpoint…

// tail a file
local.file_match "testlog" {
        path_targets = [{ "__path__" = "/var/log/someapp.log" }]
}

// link with with a loki processing pipeline
loki.source.file "linklogandlokiprocess" {
        targets = local.file_match.testlog.targets
        forward_to = [loki.process.testprocess.receiver]
}

// loki processesing pipeline
loki.process "testprocess" {
        forward_to = null

        stage.regex {
                expression = "^.* (?P<log_level>ERROR|INFO|WARN) .*$"
        }

        stage.metrics {
                metric.counter {
                        name = "log_lines_total"
                        description = "Total number of log lines"
                        prefix = "TEST_"
                        match_all = true
                        action = "inc"
                }
                metric.counter {
                        name = "log_lines_info"
                        description = "Info log lines"
                        source = "log_level"
                        value = "INFO"
                        action = "inc"
                }
        }
}

Cheers,

Rhys

Hello,
Amazon Managed Prometheus/Grafana, you can achieve similar functionality to Grok Exporter by leveraging Grafana Loki. It allows you to transform application log files into metrics without introducing additional components like Grok Exporter.