homebrew-core/Formula/metricbeat.rb

99 lines
2.9 KiB
Ruby

class Metricbeat < Formula
desc "Collect metrics from your systems and services"
homepage "https://www.elastic.co/beats/metricbeat"
url "https://github.com/elastic/beats.git",
tag: "v7.11.1",
revision: "9b2fecb327a29fe8d0477074d8a2e42a3fabbc4b"
license "Apache-2.0"
head "https://github.com/elastic/beats.git"
bottle do
sha256 cellar: :any_skip_relocation, big_sur: "9e99e90816cc09a45adb89f887f168984c034669c7c081c8458b038170bf97e5"
sha256 cellar: :any_skip_relocation, catalina: "3a703e236b9fc0ce489071ab9364e2ba6699211f4875213bb7b5265bbb4789e5"
sha256 cellar: :any_skip_relocation, mojave: "5b77542a42ed0232f77af3bbb9ea32c4d920f66d5e9a3d09b0c17f9669d86332"
end
depends_on "go" => :build
depends_on "python@3.9" => :build
def install
# remove non open source files
rm_rf "x-pack"
ENV["GOPATH"] = buildpath
(buildpath/"src/github.com/elastic/beats").install buildpath.children
ENV.prepend_path "PATH", buildpath/"bin" # for mage (build tool)
cd "src/github.com/elastic/beats/metricbeat" do
# don't build docs because it would fail creating the combined OSS/x-pack
# docs and we aren't installing them anyway
inreplace "magefile.go", "mg.Deps(CollectDocs, FieldsDocs)", ""
system "make", "mage"
system "mage", "-v", "build"
ENV.deparallelize
system "mage", "-v", "update"
(etc/"metricbeat").install Dir["metricbeat.*", "fields.yml", "modules.d"]
(libexec/"bin").install "metricbeat"
prefix.install "build/kibana"
end
prefix.install_metafiles buildpath/"src/github.com/elastic/beats"
(bin/"metricbeat").write <<~EOS
#!/bin/sh
exec #{libexec}/bin/metricbeat \
--path.config #{etc}/metricbeat \
--path.data #{var}/lib/metricbeat \
--path.home #{prefix} \
--path.logs #{var}/log/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
fork do
exec bin/"metricbeat", "-path.config", testpath/"config", "-path.data",
testpath/"data"
end
sleep 30
assert_predicate testpath/"data/metricbeat", :exist?
end
end