homebrew-core/Formula/metricbeat.rb

91 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.1.tar.gz"
sha256 "c69f0047644be919e42a1d8fa3383c894ca8e054d5b6f727f161ed4ce497ca84"
head "https://github.com/elastic/beats.git"
bottle do
cellar :any_skip_relocation
sha256 "b50ee235102314b37b2fd08b00814817eed5e3b2a19512cb8e97df7605089d1c" => :high_sierra
sha256 "ea766e2c02145d7c32520cd2a86fff59cf3a7e0127341578509d74f4165133e8" => :sierra
sha256 "b7efcc70568e0da390264398b1050dfa852147cc63406c247045cd5715aa3085" => :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