homebrew-core/Formula/metricbeat.rb
2017-12-14 22:39:42 +01: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.0.tar.gz"
sha256 "1dc37aa296a96d3ced69d0b31815e08a1985aaf2f02113889465502bb02478ac"
head "https://github.com/elastic/beats.git"
bottle do
cellar :any_skip_relocation
sha256 "8f41fc3bf924e3cd3dce5793a571de2a9d82ee146f6cb82116093a8320de6237" => :high_sierra
sha256 "42838878d1e5fbf9243c049c4be0879d565326f846d21ed0abc08a3661abd96f" => :sierra
sha256 "2b17231f8607747c70b69fc55233807ccc8bccd38af6335f17b99a9e39ae5c24" => :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