homebrew-core/Formula/node_exporter.rb

66 lines
2.2 KiB
Ruby

class NodeExporter < Formula
desc "Prometheus exporter for machine metrics"
homepage "https://prometheus.io/"
url "https://github.com/prometheus/node_exporter/archive/v0.16.0.tar.gz"
sha256 "2ed1c1c199e047b1524b49a6662d5969936e81520d6613b8b68cc3effda450cf"
bottle do
cellar :any_skip_relocation
sha256 "73a63fee885b246f401e3bb5f2ba2ef151a0d445d2c5be3480eb5ad7e34c5150" => :high_sierra
sha256 "a2f81f31c72150cff3ce0442ae63e783b4c8d9ea6b04cce353caed36f373c464" => :sierra
sha256 "43917856258a8a777b2632921070b002853b266438495320ca20d5eda6a95809" => :el_capitan
end
depends_on "go" => :build
def install
ENV["GOPATH"] = buildpath
(buildpath/"src/github.com/prometheus").mkpath
ln_s buildpath, "src/github.com/prometheus/node_exporter"
system "go", "build", "-o", bin/"node_exporter", "-ldflags",
"-X github.com/prometheus/node_exporter/vendor/github.com/prometheus/common/version.Version=#{version}",
"github.com/prometheus/node_exporter"
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>sh</string>
<string>-c</string>
<string>#{opt_bin}/node_exporter $(&lt; #{etc}/node_exporter.args)</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
output = shell_output("#{bin}/node_exporter --version 2>&1")
assert_match version.to_s, output
begin
pid = fork { exec bin/"node_exporter" }
sleep 2
assert_match "# HELP", shell_output("curl -s localhost:9100/metrics")
ensure
Process.kill("SIGINT", pid)
Process.wait(pid)
end
end
end