diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7e8e21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +dist \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ad7f5dd --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +APPLICATION_NAME := prometheus-libvirt-exporter +APPLICATION_VERSION := $(shell cat VERSION) + +LDFLAGS := -X $(APPLICATION_NAME)/meta.Version=$(APPLICATION_VERSION) + +GO_BUILD := go build -v -ldflags "$(LDFLAGS)" + +PATH := $(PWD)/build/dependencies:$(PATH) + +TEMPDIR := $(shell mktemp -d) + +all: build + +build_linux: + env GOOS=linux GOARCH=amd64 GO111MODULE=on $(GO_BUILD) -o build/prometheus-libvirt-exporter ./prometheus-libvirt-exporter.go + +build: + $(GO_BUILD) -o build/prometheus-libvirt-exporter ./prometheus-libvirt-exporter.go + +clean: + go clean -v . + rm -rf build + +FPM-exists: + @fpm -v || \ + (echo >&2 "FPM must be installed on the system. See https://github.com/jordansissel/fpm"; false) + +deb: FPM-exists build_linux + mkdir -p dist/$(APPLICATION_VERSION)/ + cd dist/$(APPLICATION_VERSION)/ && \ + fpm -s dir \ + -t deb \ + -n prometheus-libvirt-exporter \ + -v $(APPLICATION_VERSION) \ + --url="https://github.com/zhangjianweibj/prometheus-libvirt-exporter" \ + --description "Prometheus-libvirt-exporter service (host and vm metrics exposed for prometheus, written in Go with pluggable metric collectors)" \ + --deb-priority optional \ + --workdir $(TEMPDIR) \ + --architecture amd64 \ + ../../build/prometheus-libvirt-exporter=/usr/bin/prometheus-libvirt-exporter \ + ../../debian/prometheus-libvirt-exporter.service=/etc/systemd/system/prometheus-libvirt-exporter.service \ + ../../debian/prometheus-libvirt-exporter.upstart=/etc/init/prometheus-libvirt-exporter.conf \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..b123147 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.1 \ No newline at end of file diff --git a/debian/prometheus-libvirt-exporter.service b/debian/prometheus-libvirt-exporter.service new file mode 100644 index 0000000..d601d95 --- /dev/null +++ b/debian/prometheus-libvirt-exporter.service @@ -0,0 +1,13 @@ +[Unit] +Description=Prometheus-libvirt-exporter service (host and vm metrics exposed for prometheus, written in Go with pluggable metric collectors) +Requires=network-online.target +After=network-online.target + +[Service] +ExecStart=/usr/bin/prometheus-libvirt-exporter -web.listen-address ":9180" +ExecReload=/bin/kill -HUP $MAINPID +Restart=on-failure +KillSignal=SIGINT + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/debian/prometheus-libvirt-exporter.upstart b/debian/prometheus-libvirt-exporter.upstart new file mode 100644 index 0000000..3056872 --- /dev/null +++ b/debian/prometheus-libvirt-exporter.upstart @@ -0,0 +1,15 @@ +description "Prometheus-libvirt-exporter service (host and vm metrics exposed for prometheus, written in Go with pluggable metric collectors)" + +start on runlevel [2345] +stop on runlevel [!2345] + +respawn + +script + echo $$ > /var/run/prometheus-libvirt-exporter.pid + exec prometheus-libvirt-exporter -web.listen-address ":9180" +end script + +post-stop script + rm -f /var/run/prometheus-libvirt-exporter.pid +end script \ No newline at end of file