83 lines
2.6 KiB
Ruby
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.1.tar.gz"
|
|
sha256 "5ab9ffe10c8768f98c75cc2c02b82f488c2da531b5976552ca778a43a4f118df"
|
|
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: "9667e4236b0afadd58eb02047ef4be19a5a9265cea49a89ddd794a29adefbe6e"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "2b6527d04527d0900000b41ed501eed11d9b3cfec65328efa7f48427ce197c24"
|
|
sha256 cellar: :any_skip_relocation, catalina: "b50bdef7eb4fbf4d963d3b57879be5b97094e68c9d7372ec3103da246b21ff9e"
|
|
sha256 cellar: :any_skip_relocation, mojave: "04e225d74595e2ecef0d5aefb24edd32171a6368b2bdc22957dab43f46925d3d"
|
|
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
|