homebrew-core/Formula/telegraf.rb

69 lines
2.3 KiB
Ruby

class Telegraf < Formula
desc "Server-level metric gathering agent for InfluxDB"
homepage "https://influxdata.com"
url "https://github.com/influxdata/telegraf/archive/v1.14.5.tar.gz"
sha256 "66a02a8d9afe5621bb65297f74b9f2d62fbe28415771ac1dea0a13950642684c"
head "https://github.com/influxdata/telegraf.git"
bottle do
cellar :any_skip_relocation
sha256 "9931b7eb17c4ac0ba66474638a341aa12ac0c7370c96ac24a7bd63113ecfb844" => :catalina
sha256 "ac1edb9be60b7306c23a8d119bb217c0095304cfda4e85c9c655dcc08dae8d11" => :mojave
sha256 "1a8b3d364fb5f8b70f481f38834d791ceff57884d55d25f065e4da0a5b043494" => :high_sierra
end
depends_on "go" => :build
def install
system "go", "build", *std_go_args, "-ldflags", "-X main.version=#{version}", "./cmd/telegraf"
etc.install "etc/telegraf.conf" => "telegraf.conf"
end
def post_install
# Create directory for additional user configurations
(etc/"telegraf.d").mkpath
end
plist_options :manual => "telegraf -config #{HOMEBREW_PREFIX}/etc/telegraf.conf"
def plist
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/telegraf</string>
<string>-config</string>
<string>#{etc}/telegraf.conf</string>
<string>-config-directory</string>
<string>#{etc}/telegraf.d</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{var}/log/telegraf.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/telegraf.log</string>
</dict>
</plist>
EOS
end
test do
(testpath/"config.toml").write shell_output("#{bin}/telegraf -sample-config")
system "#{bin}/telegraf", "-config", testpath/"config.toml", "-test",
"-input-filter", "cpu:mem"
end
end