113 lines
3.6 KiB
Ruby
113 lines
3.6 KiB
Ruby
class Grafana < Formula
|
|
desc "Gorgeous metric visualizations and dashboards for timeseries databases"
|
|
homepage "https://grafana.com"
|
|
url "https://github.com/grafana/grafana/archive/refs/tags/v9.3.2.tar.gz"
|
|
sha256 "9ec5af34c98c6c7cfa4816a4f82a2e5e8d693530fb6bb406748c06033e3b6ec7"
|
|
license "AGPL-3.0-only"
|
|
head "https://github.com/grafana/grafana.git", branch: "main"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, arm64_ventura: "e33f4e8861bb8bb8fe5253bd567eeb590287904e2ab258e749d84a9500f64a20"
|
|
sha256 cellar: :any_skip_relocation, arm64_monterey: "5f87d25ed25a4804f776ac3acfcb5324c38831bc486a59dca47c1c23df4e1ae9"
|
|
sha256 cellar: :any_skip_relocation, arm64_big_sur: "e20d9986b5f0ac7bd33870372c46633ad4b751ccac4944864f857278e65cd2b4"
|
|
sha256 cellar: :any_skip_relocation, ventura: "ca90b74b017fce31e2f3ac57f7cae01245f8ff6da4facfac421d060ee0dcf53f"
|
|
sha256 cellar: :any_skip_relocation, monterey: "a0386ff68652d144633cd5e43a122b724dac09107e659a834faadb55a6b76d94"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "6caea72fcae81e7c7e21a3610d30e1bb99d3e6a4cc78af7a7ea023b75b9456eb"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "6a5ffddafa00e72ce0d47529bd738be00404991b24363afbd3a612cb591de042"
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "node" => :build
|
|
depends_on "yarn" => :build
|
|
|
|
uses_from_macos "zlib"
|
|
|
|
on_linux do
|
|
depends_on "fontconfig"
|
|
depends_on "freetype"
|
|
end
|
|
|
|
def install
|
|
ENV["NODE_OPTIONS"] = "--max-old-space-size=8000"
|
|
system "make", "gen-go"
|
|
system "go", "run", "build.go", "build"
|
|
|
|
system "yarn", "install"
|
|
system "yarn", "build"
|
|
|
|
os = OS.kernel_name.downcase
|
|
arch = Hardware::CPU.intel? ? "amd64" : Hardware::CPU.arch.to_s
|
|
bin.install "bin/#{os}-#{arch}/grafana-cli"
|
|
bin.install "bin/#{os}-#{arch}/grafana-server"
|
|
|
|
(etc/"grafana").mkpath
|
|
cp "conf/sample.ini", "conf/grafana.ini.example"
|
|
etc.install "conf/sample.ini" => "grafana/grafana.ini"
|
|
etc.install "conf/grafana.ini.example" => "grafana/grafana.ini.example"
|
|
pkgshare.install "conf", "public", "tools"
|
|
end
|
|
|
|
def post_install
|
|
(var/"log/grafana").mkpath
|
|
(var/"lib/grafana/plugins").mkpath
|
|
end
|
|
|
|
service do
|
|
run [opt_bin/"grafana-server",
|
|
"--config", etc/"grafana/grafana.ini",
|
|
"--homepath", opt_pkgshare,
|
|
"--packaging=brew",
|
|
"cfg:default.paths.logs=#{var}/log/grafana",
|
|
"cfg:default.paths.data=#{var}/lib/grafana",
|
|
"cfg:default.paths.plugins=#{var}/lib/grafana/plugins"]
|
|
keep_alive true
|
|
error_log_path var/"log/grafana-stderr.log"
|
|
log_path var/"log/grafana-stdout.log"
|
|
working_dir var/"lib/grafana"
|
|
end
|
|
|
|
test do
|
|
require "pty"
|
|
require "timeout"
|
|
|
|
# first test
|
|
system bin/"grafana-server", "-v"
|
|
|
|
# avoid stepping on anything that may be present in this directory
|
|
tdir = File.join(Dir.pwd, "grafana-test")
|
|
Dir.mkdir(tdir)
|
|
logdir = File.join(tdir, "log")
|
|
datadir = File.join(tdir, "data")
|
|
plugdir = File.join(tdir, "plugins")
|
|
[logdir, datadir, plugdir].each do |d|
|
|
Dir.mkdir(d)
|
|
end
|
|
Dir.chdir(pkgshare)
|
|
|
|
res = PTY.spawn(bin/"grafana-server",
|
|
"cfg:default.paths.logs=#{logdir}",
|
|
"cfg:default.paths.data=#{datadir}",
|
|
"cfg:default.paths.plugins=#{plugdir}",
|
|
"cfg:default.server.http_port=50100")
|
|
r = res[0]
|
|
w = res[1]
|
|
pid = res[2]
|
|
|
|
listening = Timeout.timeout(10) do
|
|
li = false
|
|
r.each do |l|
|
|
if /HTTP Server Listen/.match?(l)
|
|
li = true
|
|
break
|
|
end
|
|
end
|
|
li
|
|
end
|
|
|
|
Process.kill("TERM", pid)
|
|
w.close
|
|
r.close
|
|
listening
|
|
end
|
|
end
|