homebrew-core/Formula/node_exporter.rb

83 lines
2.6 KiB
Ruby

class NodeExporter < Formula
desc "Prometheus exporter for machine metrics"
homepage "https://prometheus.io/"
url "https://github.com/prometheus/node_exporter/archive/v1.1.2.tar.gz"
sha256 "edb40c783bd5767f174b916c89a768496ccae0f74811ba1d03c57c32cd250bbd"
license "Apache-2.0"
head "https://github.com/prometheus/node_exporter.git"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "7726f4bfaf5eba298d186458d82a1f0d12a52b504166dd7c654e2809f25f1c05"
sha256 cellar: :any_skip_relocation, big_sur: "7324925afff81538c8d2b2449f6912d4d3d1f96296351ebe717cc9c1152b1fa0"
sha256 cellar: :any_skip_relocation, catalina: "d4c48a7a7718fd39b7695a81bbe9364c94ec99d2a5d2d341493b71ddcf3e7405"
sha256 cellar: :any_skip_relocation, mojave: "9562cf856db0b8259c81319b2d942f376de96bf7d51e17442b853bad4f11e0d2"
end
depends_on "go" => :build
def install
ldflags = %W[
-X github.com/prometheus/common/version.Version=#{version}
-X github.com/prometheus/common/version.BuildUser=Homebrew
]
system "go", "build", "-ldflags", ldflags.join(" "), "-trimpath",
"-o", bin/"node_exporter"
prefix.install_metafiles
touch etc/"node_exporter.args"
(bin/"node_exporter_brew_services").write <<~EOS
#!/bin/bash
exec #{bin}/node_exporter $(<#{etc}/node_exporter.args)
EOS
end
def caveats
<<~EOS
When run from `brew services`, `node_exporter` is run from
`node_exporter_brew_services` and uses the flags in:
#{etc}/node_exporter.args
EOS
end
plist_options manual: "node_exporter"
def plist
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/node_exporter_brew_services</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>StandardErrorPath</key>
<string>#{var}/log/node_exporter.err.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/node_exporter.log</string>
</dict>
</plist>
EOS
end
test do
assert_match "node_exporter", shell_output("#{bin}/node_exporter --version 2>&1")
fork { exec bin/"node_exporter" }
sleep 2
assert_match "# HELP", shell_output("curl -s localhost:9100/metrics")
end
end