homebrew-core/Formula/node_exporter.rb

77 lines
2.4 KiB
Ruby

class NodeExporter < Formula
desc "Prometheus exporter for machine metrics"
homepage "https://prometheus.io/"
url "https://github.com/prometheus/node_exporter/archive/v1.0.1.tar.gz"
sha256 "a841bf3e236376840be9e1d8e6c4a38196be6f3957b0982d1c7970a5e416b0ad"
head "https://github.com/prometheus/node_exporter.git"
bottle do
cellar :any_skip_relocation
sha256 "7b68d39007278906d3a749370131c4ee7026f410350c48de3f65eeb4bd0c9310" => :catalina
sha256 "1ff2d6c27e863565b9b6415ee406d8f2585366c855f7ff9d64577043dec78b7e" => :mojave
sha256 "3d902e39d3d2be664928596a6a1af176af4a73194d3714341c6e365be3894d86" => :high_sierra
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