Skip to content

Commit 0875500

Browse files
Novgorodov Igor, PMK-TV-OPNovgorodov Igor, PMK-TV-OP
authored andcommitted
Add makefile & init scripts
1 parent 282b544 commit 0875500

File tree

5 files changed

+83
-5
lines changed

5 files changed

+83
-5
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
nginx-prometheus*
1+
nginx-prometheus
2+
!deploy/*
23
country.mmdb
34
vendor*
5+
*.rpm
6+
*.deb

Makefile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
NAME := nginx-prometheus
2+
MAINTAINER:= Igor Novgorodov <[email protected]>
3+
DESCRIPTION := Service for exporting Nginx metrics to Prometheus
4+
LICENSE := MPLv2
5+
6+
GO ?= go
7+
VERSION := $(shell cat VERSION)
8+
OUT := .out
9+
PACKAGE := github.com/blind-oracle/$(NAME)
10+
11+
all: build
12+
13+
build:
14+
rm -rf $(OUT)
15+
mkdir -p $(OUT)/root/etc/$(NAME)
16+
go test ./...
17+
GOARCH=amd64 GOOS=linux $(GO) build -o $(OUT) -ldflags "-s -w -X main.version=$(VERSION)"
18+
19+
deb:
20+
make build
21+
make build-deb ARCH=amd64
22+
23+
rpm:
24+
make build
25+
make build-rpm ARCH=amd64
26+
27+
build-deb:
28+
fpm -s dir -t deb -n $(NAME) -v $(VERSION) \
29+
--deb-priority optional \
30+
--category admin \
31+
--force \
32+
--url https://$(PACKAGE) \
33+
--description "$(DESCRIPTION)" \
34+
-m "$(MAINTAINER)" \
35+
--license "$(LICENSE)" \
36+
-a $(ARCH) \
37+
$(OUT)/$(NAME)=/usr/bin/$(NAME) \
38+
deploy/$(NAME).service=/usr/lib/systemd/system/$(NAME).service \
39+
deploy/$(NAME)=/etc/default/$(NAME) \
40+
$(OUT)/root/=/
41+
42+
build-rpm:
43+
fpm -s dir -t rpm -n $(NAME) -v $(VERSION) \
44+
--force \
45+
--rpm-compression bzip2 \
46+
--rpm-os linux \
47+
--url https://$(PACKAGE) \
48+
--description "$(DESCRIPTION)" \
49+
-m "$(MAINTAINER)" \
50+
--license "$(LICENSE)" \
51+
-a $(ARCH) \
52+
--config-files /etc/$(NAME)/$(NAME).toml \
53+
$(OUT)/$(NAME)=/usr/bin/$(NAME) \
54+
deploy/$(NAME).service=/usr/lib/systemd/system/$(NAME).service \
55+
deploy/$(NAME)=/etc/default/$(NAME) \
56+
$(OUT)/root/=/

deploy/nginx-prometheus

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LISTEN_SYSLOG="0.0.0.0:1514"
2+
LISTEN_HTTP="0.0.0.0:11080"
3+
GEOIP_DB="-"
4+
URI_PREFIXES="-"

deploy/nginx-prometheus.service

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=Service for exporting Nginx metrics to Prometheus
3+
Documentation=https://github.com/blind-oracle/nginx-prometheus
4+
After=network.target
5+
6+
[Service]
7+
EnvironmentFile=/etc/default/nginx-prometheus
8+
Type=simple
9+
PermissionsStartOnly=true
10+
ExecStart=/usr/bin/nginx-prometheus -listenHTTP ${LISTEN_HTTP} -listenSyslog ${LISTEN_SYSLOG} -geoipCountryDB ${GEOIP_DB} -uriPrefixFile ${URI_PREFIXES}
11+
Restart=on-failure
12+
KillMode=control-group
13+
14+
[Install]
15+
WantedBy=multi-user.target

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ func main() {
6969

7070
flag.StringVar(&listenSyslog, "listenSyslog", "0.0.0.0:1514", "ip:port to listen for syslog messages")
7171
flag.StringVar(&listenHTTP, "listenHTTP", "0.0.0.0:11080", "ip:port to listen for http requests")
72-
flag.StringVar(&uriPrefixFile, "uriPrefixFile", "", "file with allowed URI prefixes - one per line. If not specified - no per-URI stats gathered")
73-
flag.StringVar(&geoipCountryDB, "geoipCountryDB", "", "path to MaxMind GeoIP country DB. If not specified - no lookups performed")
72+
flag.StringVar(&uriPrefixFile, "uriPrefixFile", "-", "file with allowed URI prefixes - one per line. If not specified - no per-URI stats gathered")
73+
flag.StringVar(&geoipCountryDB, "geoipCountryDB", "-", "path to MaxMind GeoIP country DB. If not specified - no lookups performed")
7474
flag.BoolVar(&debug, "debug", false, "Enable debug")
7575
flag.Parse()
7676

77-
if uriPrefixFile != "" {
77+
if uriPrefixFile != "-" {
7878
if uriTree, err = uriLoad(uriPrefixFile); err != nil {
7979
log.Fatalf("Unable to load URIs: %s", err)
8080
}
8181

8282
log.Printf("URI prefixes loaded: %d", uriTree.Len())
8383
}
8484

85-
if geoipCountryDB != "" {
85+
if geoipCountryDB != "-" {
8686
if geoipDB, err = geoip.New(geoipCountryDB); err != nil {
8787
log.Fatalf("Unable to load GeoIP database: %s", err)
8888
}

0 commit comments

Comments
 (0)