I have a file on a Linux filesystem that contains a timestamp. I would like to take that timestamp and create a metric with it that can then be used in Grafana.
Is it possible to create a static metric with Alloy? And then have that metric use the timestamp as a label or even the value?
This is what I have been trying so far:
local.file "update_timestamp" {
filename = "/var/log/update-timestamp"
}
prometheus.scrape "update_timestamp" {
targets = [{
"__address__" = "alloy.internal:12345",
"timestamp" = local.file.update_timestamp.content,
"__fake_name__" = "placeholder",
}]
forward_to = [prometheus.relabel.update_timestamp.receiver]
}
prometheus.relabel "update_timestamp" {
rule {
source_labels = ["__fake_name__"]
regex = "placeholder"
action = "keep"
}
rule {
source_labels = ["timestamp"]
regex = "([0-9]+)"
target_label = "__value__"
replacement = "$1"
}
rule {
target_label = "__name__"
replacement = "update_timestamp"
}
forward_to = [prometheus.remote_write.default.receiver]
}
Alloy debug shows all the metrics with the timestamp
label, for example:
{
__name__="alloy_build_info",
branch="HEAD",
goarch="amd64",
goos="linux",
goversion="go1.24.3",
instance="alloy.internal:12345",
job="update_timestamp",
revision="d3d7931",
tags="netgo,builtinassets,promtail_journal_enabled",
timestamp="{false 1749749967\n}",
version="v1.9.1"
} => {}
But there is but no new metric that I can filter on. So it appears that the relabel never happens.
Is what I am trying to do even possible?