homebrew-core/Formula/metricbeat.rb
2017-06-02 11:43:16 -04:00

85 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/v5.4.1.tar.gz"
sha256 "1be33563960699941006fd6957bd9ddcfe923b2299a7d589b35a390d0111eb8d"
head "https://github.com/elastic/beats.git"
bottle do
cellar :any_skip_relocation
sha256 "8c347b428f4083fcaee1ff4eec3632f69fde8bad43b1697ef166987570a4f7db" => :sierra
sha256 "d9baefc1c36aad226f251cdf687b7feab144a1a0074e5f1cc785e2cd1f98e97f" => :el_capitan
sha256 "cfae33320d989cc63bac563d36bbd23d75077e5be3fa676fb948a2c2fb0d2a8f" => :yosemite
end
depends_on "go" => :build
def install
gopath = buildpath/"gopath"
(gopath/"src/github.com/elastic/beats").install Dir["{*,.git,.gitignore}"]
ENV["GOPATH"] = gopath
cd gopath/"src/github.com/elastic/beats/metricbeat" do
system "make"
libexec.install "metricbeat"
(etc/"metricbeat").install "metricbeat.yml"
(etc/"metricbeat").install "metricbeat.template.json"
(etc/"metricbeat").install "metricbeat.template-es2x.json"
end
(bin/"metricbeat").write <<-EOS.undent
#!/bin/sh
exec "#{libexec}/metricbeat" --path.config "#{etc}/metricbeat" --path.home="#{prefix}" --path.logs="#{var}/log/metricbeat" --path.data="#{opt_prefix}" "$@"
EOS
end
plist_options :manual => "metricbeat"
def plist; <<-EOS.undent
<?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/"metricbeat.yml").write <<-EOS.undent
metricbeat.modules:
- module: system
metricsets: ["load"]
period: 1s
output.file:
enabled: true
path: #{testpath}/data
filename: metricbeat
EOS
(testpath/"logs").mkpath
(testpath/"data").mkpath
metricbeat_pid = fork do
exec bin/"metricbeat", "-c", testpath/"metricbeat.yml",
"--path.data=#{testpath}/data", "--path.logs=#{testpath}/logs"
end
begin
sleep 2
assert File.exist? testpath/"data/metricbeat"
ensure
Process.kill("TERM", metricbeat_pid)
end
end
end