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.6.2.tar.gz" sha256 "72e247d6ec3586883cd58bc6465d18b7eb0857763ff422259205abf090557e45" head "https://github.com/elastic/beats.git" bottle do sha256 "b943cac4bf5057a5a80e58a8bf3006d650f10864170d493faa57cf8c10360906" => :high_sierra sha256 "a8ee72df2282fcc124a3c3797b90bad75c4e33a770e3cf338f6931c2c8fee591" => :sierra sha256 "924986fc31044f67754ac5a249f791249f962a53df2e7b4dbfaebf080b69cf96" => :el_capitan 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.full.yml" (etc/"metricbeat").install "metricbeat.yml" (etc/"metricbeat").install "metricbeat.template.json" (etc/"metricbeat").install "metricbeat.template-es2x.json" (etc/"metricbeat").install "metricbeat.template-es6x.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 Label #{plist_name} Program #{opt_bin}/metricbeat RunAtLoad 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_predicate testpath/"data/metricbeat", :exist? ensure Process.kill("TERM", metricbeat_pid) end end end