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.2.0.tar.gz" sha256 "f4cf4dee93ae5803d7c07573e96f73ee421cf9f3154615c9c518137c1956feab" head "https://github.com/elastic/beats.git" bottle do cellar :any_skip_relocation sha256 "45759c5a7981523ac15dd78f2a63b68ac1431fb2c2084463a55a23a1269c59db" => :high_sierra sha256 "7d9ad800f09d924d61472df8bfc3b9b2e3296c951a5dff43f013fc98f0c19af9" => :sierra sha256 "210c3c3fc18292566904fe2af1839270cbf3e72db419eb195c3ae338fbdfefbf" => :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 Label #{plist_name} Program #{opt_bin}/metricbeat RunAtLoad 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