package init

This commit is contained in:
baizg1107 2021-07-31 16:49:26 +08:00
parent 42ba7d7490
commit b9f517ce85
6 changed files with 156 additions and 0 deletions

View File

@ -0,0 +1,65 @@
From f4984952bc9259a34b93b4bdf7581c1e586e7b36 Mon Sep 17 00:00:00 2001
From: bzg1107 <preloyalwhite@163.com>
Date: Sat, 31 Jul 2021 16:36:48 +0800
Subject: [PATCH] fix promu dependence and fix not found web
---
Makefile.common | 10 ++++++----
main.go | 5 +----
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/Makefile.common b/Makefile.common
index ce80d53..d33966d 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -261,11 +261,13 @@ common-docker-manifest:
promu: $(PROMU)
$(PROMU):
- $(eval PROMU_TMP := $(shell mktemp -d))
- curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
+# $(eval PROMU_TMP := $(shell mktemp -d))
+# curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
+# mkdir -p $(FIRST_GOPATH)/bin
+# cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
+# rm -r $(PROMU_TMP)
mkdir -p $(FIRST_GOPATH)/bin
- cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
- rm -r $(PROMU_TMP)
+ cp /usr/bin/promu $(FIRST_GOPATH)/bin/promu
.PHONY: proto
proto:
diff --git a/main.go b/main.go
index 0c47d9d..bdf61e8 100644
--- a/main.go
+++ b/main.go
@@ -34,8 +34,6 @@ import (
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/route"
"github.com/prometheus/common/version"
- "github.com/prometheus/exporter-toolkit/web"
- webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
"gopkg.in/alecthomas/kingpin.v2"
dto "github.com/prometheus/client_model/go"
@@ -61,7 +59,6 @@ func (lf logFunc) Println(v ...interface{}) {
func main() {
var (
app = kingpin.New(filepath.Base(os.Args[0]), "The Pushgateway")
- webConfig = webflag.AddFlags(app)
listenAddress = app.Flag("web.listen-address", "Address to listen on for the web interface, API, and telemetry.").Default(":9091").String()
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
externalURL = app.Flag("web.external-url", "The URL under which the Pushgateway is externally reachable.").Default("").URL()
@@ -195,7 +192,7 @@ func main() {
mux.Handle(apiPath+"/v1/", http.StripPrefix(apiPath+"/v1", av1))
go closeListenerOnQuit(l, quitCh, logger)
- err = web.Serve(l, &http.Server{Addr: *listenAddress, Handler: mux}, *webConfig, logger)
+ err = (&http.Server{Addr: *listenAddress, Handler: mux}).Serve(l)
level.Error(logger).Log("msg", "HTTP server stopped", "err", err)
// To give running connections a chance to submit their payload, we wait
// for 1sec, but we don't want to wait long (e.g. until all connections
--
2.30.0

BIN
pushgateway-1.4.1.tar.gz Normal file

Binary file not shown.

1
pushgateway.default Normal file
View File

@ -0,0 +1 @@
PUSHGATEWAY_OPTS='--web.listen-address=0.0.0.0:9091'

18
pushgateway.service Normal file
View File

@ -0,0 +1,18 @@
# -*- mode: conf -*-
[Unit]
Description=Prometheus pushgateway.
Documentation=https://github.com/prometheus/pushgateway
After=network.target
[Service]
EnvironmentFile=-/etc/default/pushgateway
User=prometheus
ExecStart=/usr/bin/pushgateway \
$PUSHGATEWAY_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

72
pushgateway.spec Normal file
View File

@ -0,0 +1,72 @@
%define debug_package %{nil}
%ifarch aarch64
%global hostarch arm64
%endif
%ifarch x86_64
%global hostarch amd64
%endif
Name: pushgateway
Version: 1.4.1
Release: 1
Summary: Prometheus pushgateway.
License: ASL 2.0
URL: https://github.com/prometheus/%{name}
Source0: https://github.com/prometheus/%{name}/archive/v%{version}/%{name}-%{version}.tar.gz
Source1: %{name}.service
Source2: %{name}.default
Source3: vendor.tar.gz
Patch0: 0001-fix-promu-dependence-and-fix-not-found-web.patch
BuildRequires: golang >= 1.13
BuildRequires: promu
%{?systemd_requires}
Requires(pre): shadow-utils
%description
The Prometheus Pushgateway exists to allow ephemeral and batch jobs to expose their metrics to Prometheus.
Since these kinds of jobs may not exist long enough to be scraped, they can instead push their metrics to a Pushgateway.
The Pushgateway then exposes these metrics to Prometheus.
%prep
%autosetup -p1 -n %{name}-%{version}
%setup -T -D -a 3 -n %{name}-%{version}
%build
mkdir -p $(pwd)/bin
export GOBIN=$(pwd)/bin
go build -mod=vendor -o bin ./ ...
%install
mkdir -p %{buildroot}%{_bindir}
install -D -m 755 bin/%{name} %{buildroot}%{_bindir}/
mkdir -vp %{buildroot}%{_sharedstatedir}/prometheus
install -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
install -D -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/default/%{name}
%pre
getent group prometheus >/dev/null || groupadd -r prometheus
getent passwd prometheus >/dev/null || \
useradd -r -g prometheus -d %{_sharedstatedir}/prometheus -s /sbin/nologin \
-c "Prometheus services" prometheus
exit 0
%post
%systemd_post %{name}.service
%preun
%systemd_preun %{name}.service
%postun
%systemd_postun %{name}.service
%files
%defattr(-,root,root,-)
%{_bindir}/*
%{_unitdir}/%{name}.service
%config(noreplace) %{_sysconfdir}/default/%{name}
%dir %attr(755, prometheus, prometheus)%{_sharedstatedir}/prometheus
%changelog
* Wed Jul 14 2021 baizhonggui <baizhonggui@huawei.com> - 1.4.1-1
- Package init

BIN
vendor.tar.gz Normal file

Binary file not shown.