From 15b1e44b3080f7541f00593993853a7890d78a62 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 3 Aug 2020 07:40:54 -0600 Subject: [PATCH] promethues-sql-exporter: new aport --- sr.ht/prometheus-sql-exporter/APKBUILD | 52 +++++++++++++++++++ .../prometheus-sql-exporter.confd | 5 ++ .../prometheus-sql-exporter.initd | 14 +++++ .../prometheus-sql-exporter.pre-install | 4 ++ .../prometheus-sql-exporter/sql_exporter.yml | 25 +++++++++ 5 files changed, 100 insertions(+) create mode 100644 sr.ht/prometheus-sql-exporter/APKBUILD create mode 100644 sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.confd create mode 100644 sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.initd create mode 100644 sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.pre-install create mode 100644 sr.ht/prometheus-sql-exporter/sql_exporter.yml diff --git a/sr.ht/prometheus-sql-exporter/APKBUILD b/sr.ht/prometheus-sql-exporter/APKBUILD new file mode 100644 index 0000000..9c97435 --- /dev/null +++ b/sr.ht/prometheus-sql-exporter/APKBUILD @@ -0,0 +1,52 @@ +# Maintainer: Drew DeVault +pkgname=prometheus-sql-exporter +pkgver=0.5 +pkgrel=0 +pkgdesc="Database agnostic SQL exporter for Prometheus" +url="https://github.com/free/sql_exporter" +arch="all" +license="MIT" +install="prometheus-sql-exporter.pre-install" +makedepends="go" +source=" + $pkgname-$pkgver.tar.gz::https://github.com/free/sql_exporter/archive/$pkgver.tar.gz + prometheus-sql-exporter.initd + prometheus-sql-exporter.confd + sql_exporter.yml +" +subpackages="$pkgname-openrc" +builddir="$srcdir/sql_exporter-$pkgver" + +build() { + go mod init github.com/free/sql_exporter + go mod vendor + go build \ + -trimpath \ + -mod=vendor \ + -ldflags "-extldflags $LDFLAGS" \ + -tags netgo,builtinassets \ + ./cmd/sql_exporter +} + +check() { + go test ./... +} + +package() { + mkdir -p "$pkgdir"/usr/bin + mkdir -p "$pkgdir"/etc/init.d + mkdir -p "$pkgdir"/etc/conf.d + mkdir -p "$pkgdir"/etc/prometheus + install -Dm755 sql_exporter "$pkgdir"/usr/bin/prometheus_sql_exporter + install -Dm755 "$srcdir"/prometheus-sql-exporter.initd \ + "$pkgdir"/etc/init.d/prometheus-sql-exporter + install -Dm644 "$srcdir"/prometheus-sql-exporter.confd \ + "$pkgdir"/etc/conf.d/prometheus-sql-exporter + install -Dm644 "$srcdir"/sql_exporter.yml \ + "$pkgdir"/etc/prometheus/sql_exporter.yml +} + +sha512sums="0c260bd1f6716e1b2d8fdc9be511533279eca102e7117d71c123457aeb63613804e0762f83e6231cad94b31a63d07ad29c56d96dbeae07a3f07f1a2d28d6d7c9 prometheus-sql-exporter-0.5.tar.gz +b4c7e2229777e46fad3f30f342fd13cf3c2628a3845bc89fb8d4df9f1e058533c7344a053e5ca581edc065bdc59fed88d57787d8e2bcf9fe1b8741b2394e66a2 prometheus-sql-exporter.initd +a7d40104e925be144f9dd36e59659b0bdc1577cd433adc31a4d971fc1486c62f8485cd7b1b2d169ab01ab9e8252d89bdad70fa5a73e17b5db47b0c62f9dffe8f prometheus-sql-exporter.confd +981b612fda17d10ded35b072eec627be429900128225f464c81bb253a73bf1f024afbff5ef138e4130163819d35874d1e80c3fffd781709bb75eb8cb7f8362de sql_exporter.yml" diff --git a/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.confd b/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.confd new file mode 100644 index 0000000..1a1bede --- /dev/null +++ b/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.confd @@ -0,0 +1,5 @@ +prometheus_sql_exporter_web_listen_address=127.0.0.1:9399 +prometheus_sql_exporter_config_file=/etc/prometheus/sql_exporter.yml + +output_log=/var/log/prometheus-sql-exporter.log +error_log=/var/log/prometheus-sql-exporter.log diff --git a/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.initd b/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.initd new file mode 100644 index 0000000..6d9a0c0 --- /dev/null +++ b/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.initd @@ -0,0 +1,14 @@ +#!/sbin/openrc-run +name="prometheus-sql-exporter" +description="Prometheus SQL monitoring daemon" +supervisor=supervise-daemon +command=/usr/bin/prometheus_sql_exporter +command_args="--web.listen-address=$prometheus_sql_exporter_web_listen_address \ + --config.file=$prometheus_sql_exporter_config_file" + +start_pre() { + [ -n "$output_log" ] && checkpath -f "$output_log" \ + -m 644 -o prometheus:prometheus || true + [ -n "$error_log" ] && checkpath -f "$error_log" \ + -m 644 -o prometheus:prometheus || true +} diff --git a/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.pre-install b/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.pre-install new file mode 100644 index 0000000..004fd0b --- /dev/null +++ b/sr.ht/prometheus-sql-exporter/prometheus-sql-exporter.pre-install @@ -0,0 +1,4 @@ +#!/bin/sh +grep '^prometheus:' /etc/group >/dev/null || addgroup -S prometheus 2>/dev/null +grep '^prometheus:' /etc/passwd >/dev/null || adduser -SDh/var/lib/prometheus \ + -s/sbin/nologin -Gprometheus -gprometheus prometheus prometheus 2>/dev/null diff --git a/sr.ht/prometheus-sql-exporter/sql_exporter.yml b/sr.ht/prometheus-sql-exporter/sql_exporter.yml new file mode 100644 index 0000000..1e18864 --- /dev/null +++ b/sr.ht/prometheus-sql-exporter/sql_exporter.yml @@ -0,0 +1,25 @@ +# Global defaults. +global: + # Subtracted from Prometheus' scrape_timeout to give us some headroom and prevent Prometheus from timing out first. + scrape_timeout_offset: 500ms + # Minimum interval between collector runs: by default (0s) collectors are executed on every scrape. + min_interval: 0s + # Maximum number of open connections to any one target. Metric queries will run concurrently on multiple connections, + # as will concurrent scrapes. + max_connections: 3 + # Maximum number of idle connections to any one target. Unless you use very long collection intervals, this should + # always be the same as max_connections. + max_idle_connections: 3 + +# The target to monitor and the collectors to execute on it. +target: + # Data source name always has a URI schema that matches the driver name. In some cases (e.g. MySQL) + # the schema gets dropped or replaced to match the driver expected DSN format. + data_source_name: 'sqlserver://prom_user:prom_password@dbserver1.example.com:1433' + + # Collectors (referenced by name) to execute on the target. + collectors: [mssql_standard] + +# Collector files specifies a list of globs. One collector definition is read from each matching file. +collector_files: + - "*.collector.yml" -- 2.45.2