homebrew-core/Formula/metricbeat.rb
2018-01-30 15:01:28 -08:00

90 lines
2.5 KiB
Ruby

class Metricbeat < Formula
desc "Collect metrics from your systems and services"
homepage "https://www.elastic.co/products/beats/metricbeat"
url "https://github.com/elastic/beats/archive/v6.1.3.tar.gz"
sha256 "5a21ce1eca7eab2b8214b54a7f4690cd557cd05073119f861025330e1b4006a3"
head "https://github.com/elastic/beats.git"
bottle do
cellar :any_skip_relocation
sha256 "7854c93f88d75ae5e9345deb8e0797982a09a3c8c798ddf6545073fd35280292" => :high_sierra
sha256 "ee01c1c79c40a894d248b2e7679a24162a60eda1dd54647e563e6a88042084f6" => :sierra
sha256 "025fc812d0a0c3dce0ee189a1238be3ec586e8dab76acbcbb893fa9f4ae28598" => :el_capitan
end
depends_on "go" => :build
def install
ENV["GOPATH"] = buildpath
(buildpath/"src/github.com/elastic/beats").install buildpath.children
cd "src/github.com/elastic/beats/metricbeat" do
system "make"
system "make", "kibana"
(libexec/"bin").install "metricbeat"
libexec.install "_meta/kibana"
(etc/"metricbeat").install Dir["metricbeat*.yml"]
prefix.install_metafiles
end
(bin/"metricbeat").write <<~EOS
#!/bin/sh
exec "#{libexec}/bin/metricbeat" \
--path.config "#{etc}/metricbeat" \
--path.home="#{prefix}" \
--path.logs="#{var}/log/metricbeat" \
--path.data="#{var}/lib/metricbeat" \
"$@"
EOS
end
plist_options :manual => "metricbeat"
def plist; <<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//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>Program</key>
<string>#{opt_bin}/metricbeat</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOS
end
test do
(testpath/"config/metricbeat.yml").write <<~EOS
metricbeat.modules:
- module: system
metricsets: ["load"]
period: 1s
output.file:
enabled: true
path: #{testpath}/data
filename: metricbeat
EOS
(testpath/"logs").mkpath
(testpath/"data").mkpath
pid = fork do
exec bin/"metricbeat", "-path.config", testpath/"config", "-path.data",
testpath/"data"
end
begin
sleep 30
assert_predicate testpath/"data/metricbeat", :exist?
ensure
Process.kill "SIGINT", pid
Process.wait pid
end
end
end