Basic alloy log config

Hi everyone.

I’m trying to set my alloy agent to use a couple of pipelines to send logs to my LOKY in Grafana Cloud.

My first Pipeline (that collects logs from /var/log/*) works well but I can’t find the way to make the second pipeline work. This second pipeline should just collect logs from /log/milog.log, a simple file I’ve created)

This is my current config:

local.file_match “logs_default_varlogs” {
path_targets = [{
address = “localhost”,
path = “/var/log/*”,
instance = “ansible01”,
job = “varlogs”,
}]
}

loki.source.file “logs_default_varlogs” {
targets = local.file_match.logs_default_varlogs.targets
forward_to = [loki.write.logs_default.receiver]
}

loki.write “logs_default” {
endpoint {
url = “https://logs-prod-008.grafana.net/loki/api/v1/push

  basic_auth {
  	username = "123456"
  	password = "mypassword"
  }

}
external_labels = {}
}

local.file_match “tmplogs” {
path_targets = [{“path” = “/log/*”}]
}

loki.source.file “local_files” {
targets = local.file_match.tmplogs.targets
forward_to = [loki.write.local_loki.receiver]
}

loki.write “local_loki” {
endpoint {
url = “https://logs-prod-008.grafana.net/loki/api/v1/push

            basic_auth {
                    username = "123456"
                    password = "mypassword"
            }
    }
    external_labels = {}

}

As I said the ‘logs_default_varlogs’ works well but my alloy is not collecting data from the /log/mylog.log file

I have make sure the file has read rights.

Any idea where can be the problem?

Thank you in advance and regards.

Your configuration look good to me. Check your alloy UI and see if tmplogs is in the pipeline.

How often does /log/mylog.log change?

1 Like

Thx a lot Tony.
I didn’t know of the existence of that IA, really useful.I took a look to see that everything looked well. Which made me think that maybe the problem was the log in the second pipeline.

You asked me how often the log in the second pipeline was changing, and true is :smile: that it only changed when I added info on it manually. That question you made make me think that maybe that was the problem.

I tried this, instead of pointing to /log/mylog, I pointed to /etc/alloy/alloy.log (I guess this is a bad practice, but for testing purposes did the trick), and it worked xD

local.file_match "tmplogs" {
        path_targets = [{
                __address__ = "localhost",
                __path__    = "/etc/alloy/*log",
                instance    = "ansible01",
                job         = "varlogs",
        }]
}

Now, I can see in grafana that the log in the second pipeline has being collected

So, thank you very much Sir for your time and help. Really appreciate it :slight_smile:

Alloy keeps a state of the file it has scraped from, and this can lead to misconception when testing a configuration thinking that it doesn’t work, when it’s simply that the same file had already been processed.

1 Like