homebrew-core/Formula/metricbeat.rb
2019-12-28 16:05:10 +01:00

120 lines
3.8 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.git",
:tag => "v6.8.5",
:revision => "22b590e4e8dbb91bdcfe8689e59dcb04447eeef6"
revision 1
head "https://github.com/elastic/beats.git"
bottle do
cellar :any_skip_relocation
sha256 "a7e57e0a45c199988abf82d7fefc1e0e29dfec3d36fc404c3f66f1589a9959e0" => :catalina
sha256 "e2e5a236ae0051987d1e15907525ff035cbe93fd7a1f83cdc2157d1bdabc7fb8" => :mojave
sha256 "6466e3abe58c3648d841a06ea1e11bd27af6ce38c568af4d9046701a30200d9d" => :high_sierra
end
depends_on "go" => :build
# https://github.com/elastic/beats/pull/14798
uses_from_macos "python@2" => :build # does not support Python 3
# Newer virtualenvs are not compatible with Python 2.7.10 on high sierra, use an old version
resource "virtualenv" do
url "https://files.pythonhosted.org/packages/d4/0c/9840c08189e030873387a73b90ada981885010dd9aea134d6de30cd24cb8/virtualenv-15.1.0.tar.gz"
sha256 "02f8102c2436bb03b3ee6dede1919d1dac8a427541652e5ec95171ec8adbc93a"
end
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_create_path "PYTHONPATH", buildpath/"vendor/lib/python2.7/site-packages"
resource("virtualenv").stage do
system "python", *Language::Python.setup_install_args(buildpath/"vendor")
end
ENV.prepend_path "PATH", buildpath/"vendor/bin" # for virtualenv
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 "Makefile", "collect: assets collect-docs configs kibana imports",
"collect: assets configs kibana imports"
system "make", "mage"
# prevent downloading binary wheels during python setup
system "make", "PIP_INSTALL_COMMANDS=--no-binary :all", "python-env"
system "mage", "-v", "build"
system "mage", "-v", "update"
(etc/"metricbeat").install Dir["metricbeat.*", "fields.yml", "modules.d"]
(libexec/"bin").install "metricbeat"
prefix.install "_meta/kibana.generated"
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
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