class Prometheus < Formula desc "Service monitoring system and time series database" homepage "https://prometheus.io/" url "https://github.com/prometheus/prometheus/archive/v2.13.1.tar.gz" sha256 "5624c16728679362cfa46b76ec1d247018106989f2260d35583c42c49c5142b5" bottle do cellar :any_skip_relocation rebuild 1 sha256 "3e2f6180a0594933ac5eeb1f5574d9f07a45479b556702a426697ffa507328fd" => :catalina sha256 "7a0549df192cd2b4c23a7322ff2d8096eb19774027f028cbeef5363fb5718862" => :mojave sha256 "a68c839c3b0d5d63e768ab069f72b7a4d1c32b385d4d448a3de444b5044e95c3" => :high_sierra end depends_on "go" => :build def install mkdir_p buildpath/"src/github.com/prometheus" ln_sf buildpath, buildpath/"src/github.com/prometheus/prometheus" system "make", "build" bin.install %w[promtool prometheus] libexec.install %w[consoles console_libraries] end def post_install (etc/"prometheus.args").write <<~EOS --config.file #{etc}/prometheus.yml --web.listen-address=127.0.0.1:9090 --storage.tsdb.path #{var}/prometheus EOS (etc/"prometheus.yml").write <<~EOS global: scrape_interval: 15s scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"] EOS end def caveats; <<~EOS When used with `brew services`, prometheus' configuration is stored as command line flags in #{etc}/prometheus.args Configuration for prometheus is located in the #{etc}/prometheus.yml file. EOS end plist_options :manual => "prometheus" def plist; <<~EOS Label #{plist_name} ProgramArguments sh -c #{opt_bin}/prometheus $(< #{etc}/prometheus.args) RunAtLoad KeepAlive StandardErrorPath #{var}/log/prometheus.err.log StandardOutPath #{var}/log/prometheus.log EOS end test do (testpath/"rules.example").write <<~EOS groups: - name: http rules: - record: job:http_inprogress_requests:sum expr: sum(http_inprogress_requests) by (job) EOS system "#{bin}/promtool", "check", "rules", testpath/"rules.example" end end