diff -Nru prometheus-squid-exporter-1.4+ds/collector/client.go prometheus-squid-exporter-1.8.2+ds/collector/client.go --- prometheus-squid-exporter-1.4+ds/collector/client.go 2018-11-05 19:41:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/collector/client.go 2020-01-09 12:57:19.000000000 +0000 @@ -59,6 +59,14 @@ r, err := get(conn, "counters", c.basicAuthString) + if err != nil { + return nil, err + } + + if r.StatusCode != 200 { + return nil, fmt.Errorf("Non success code %d while fetching metrics", r.StatusCode) + } + var counters types.Counters // TODO: Move to another func diff -Nru prometheus-squid-exporter-1.4+ds/collector/counters.go prometheus-squid-exporter-1.8.2+ds/collector/counters.go --- prometheus-squid-exporter-1.4+ds/collector/counters.go 2018-11-05 19:41:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/collector/counters.go 2020-01-09 12:57:19.000000000 +0000 @@ -42,12 +42,12 @@ {"server.other", "kbytes_in", "kbytes_total", "The total number of server other kbytes received"}, {"server.other", "kbytes_out", "kbytes_total", "The total number of server other kbytes transferred"}, - {"swap", "ins", "total", "The total number of server other requests"}, - {"swap", "outs", "total", "The total number of server other errors"}, - {"swap", "files_cleaned", "total", "The total number of server other kbytes received"}, + {"swap", "ins", "total", "The number of objects read from disk"}, + {"swap", "outs", "total", "The number of objects saved to disk"}, + {"swap", "files_cleaned", "total", "The number of orphaned cache files removed by the periodic cleanup procedure"}, } -func generateSquidCounters() descMap { +func generateSquidCounters(labels []string) descMap { counters := descMap{} for i := range squidCounters { @@ -57,7 +57,7 @@ prometheus.BuildFQName(namespace, strings.Replace(counter.Section, ".", "_", -1), fmt.Sprintf("%s_%s", counter.Counter, counter.Suffix)), counter.Description, - []string{}, nil, + labels, nil, ) } diff -Nru prometheus-squid-exporter-1.4+ds/collector/metrics.go prometheus-squid-exporter-1.8.2+ds/collector/metrics.go --- prometheus-squid-exporter-1.4+ds/collector/metrics.go 2018-11-05 19:41:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/collector/metrics.go 2020-01-09 12:57:19.000000000 +0000 @@ -4,6 +4,7 @@ "log" "time" + "github.com/boynux/squid-exporter/config" "github.com/prometheus/client_golang/prometheus" ) @@ -25,11 +26,13 @@ hostname string port int + labels config.Labels up *prometheus.GaugeVec } /*New initializes a new exporter */ -func New(hostname string, port int, login string, password string) *Exporter { +func New(hostname string, port int, login string, password string, labels config.Labels) *Exporter { + counters = generateSquidCounters(labels.Keys) c := NewCacheObjectClient(hostname, port, login, password) return &Exporter{ @@ -38,6 +41,7 @@ hostname, port, + labels, prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Name: "up", @@ -65,7 +69,7 @@ e.up.With(prometheus.Labels{"host": e.hostname}).Set(1) for i := range insts { if d, ok := counters[insts[i].Key]; ok { - c <- prometheus.MustNewConstMetric(d, prometheus.CounterValue, insts[i].Value) + c <- prometheus.MustNewConstMetric(d, prometheus.CounterValue, insts[i].Value, e.labels.Values...) } } } else { @@ -75,6 +79,3 @@ e.up.Collect(c) } -func init() { - counters = generateSquidCounters() -} diff -Nru prometheus-squid-exporter-1.4+ds/config/config.go prometheus-squid-exporter-1.8.2+ds/config/config.go --- prometheus-squid-exporter-1.4+ds/config/config.go 1970-01-01 00:00:00.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/config/config.go 2020-01-09 12:57:19.000000000 +0000 @@ -0,0 +1,126 @@ +package config + +import ( + "fmt" + "flag" + "log" + "os" + "strconv" + "strings" +) + +const ( + defaultListenAddress = "127.0.0.1:9301" + defaultListenPort = 9301 + defaultMetricsPath = "/metrics" + defaultSquidHostname = "localhost" + defaultSquidPort = 3128 +) + +const ( + squidExporterListenKey = "SQUID_EXPORTER_LISTEN" + squidExporterMetricsPathKey = "SQUID_EXPORTER_METRICS_PATH" + squidHostnameKey = "SQUID_HOSTNAME" + squidPortKey = "SQUID_PORT" + squidLoginKey = "SQUID_LOGIN" + squidPasswordKey = "SQUID_PASSWORD" +) + +var ( + VersionFlag *bool +) + +type Labels struct { + Keys []string + Values []string +} + + +/*Config configurations for exporter */ +type Config struct { + ListenAddress string + ListenPort int + MetricPath string + Labels Labels + + SquidHostname string + SquidPort int + Login string + Password string +} + +/*NewConfig creates a new config object from command line args */ +func NewConfig() *Config { + c := &Config{} + + flag.StringVar(&c.ListenAddress, "listen", + loadEnvStringVar(squidExporterListenKey, defaultListenAddress), "Address and Port to bind exporter, in host:port format") + flag.StringVar(&c.MetricPath, "metrics-path", + loadEnvStringVar(squidExporterMetricsPathKey, defaultMetricsPath), "Metrics path to expose prometheus metrics") + + flag.Var(&c.Labels, "label", "Custom metrics to attach to metrics, use -label multiple times for each additional label") + + flag.StringVar(&c.SquidHostname, "squid-hostname", + loadEnvStringVar(squidHostnameKey, defaultSquidHostname), "Squid hostname") + flag.IntVar(&c.SquidPort, "squid-port", + loadEnvIntVar(squidPortKey, defaultSquidPort), "Squid port to read metrics") + + flag.StringVar(&c.Login, "squid-login", loadEnvStringVar(squidLoginKey, ""), "Login to squid service") + flag.StringVar(&c.Password, "squid-password", loadEnvStringVar(squidPasswordKey, ""), "Password to squid service") + + VersionFlag = flag.Bool("version", false, "Print the version and exit") + + flag.Parse() + + return c +} + +func loadEnvStringVar(key, def string) string { + val := os.Getenv(key) + if val == "" { + return def + } + + return val +} + +func loadEnvIntVar(key string, def int) int { + valStr := os.Getenv(key) + if valStr != "" { + val, err := strconv.ParseInt(valStr, 0, 32) + if err == nil { + return int(val) + } + + log.Printf("Error parsing %s='%s'. Integer value expected", key, valStr) + } + + return def +} + +func (l *Labels) String() string { + var lbls []string + for i := range l.Keys { + lbls = append(lbls, l.Keys[i] + "=" + l.Values[i]) + } + + return strings.Join(lbls, ", ") +} + +func (l *Labels) Set(value string) error { + args := strings.Split(value, "=") + + if len(args) != 2 || len(args[1]) < 1 { + return fmt.Errorf("Label must be in 'key=value' format") + } + + for _, key := range l.Keys { + if key == args[0] { + return fmt.Errorf("Labels must be distinct, found duplicated key %s", args[0]) + } + } + l.Keys = append(l.Keys, args[0]) + l.Values = append(l.Values, args[1]) + + return nil +} diff -Nru prometheus-squid-exporter-1.4+ds/config.go prometheus-squid-exporter-1.8.2+ds/config.go --- prometheus-squid-exporter-1.4+ds/config.go 2018-11-05 19:41:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/config.go 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -package main - -import ( - "flag" -) - -const ( - defaultListenAddress = "127.0.0.1:9301" - defaultListenPort = 9301 - defaultMetricsPath = "/metrics" - defaultSquidHostname = "localhost" - defaultSquidPort = 3128 -) - -var ( - versionFlag *bool -) - -/*Config configurations for exporter */ -type Config struct { - ListenAddress string - ListenPort int - MetricPath string - - SquidHostname string - SquidPort int - Login string - Password string -} - -/*NewConfig creates a new config object from command line args */ -func NewConfig() *Config { - c := &Config{} - - flag.StringVar(&c.ListenAddress, "listen", defaultListenAddress, "Address and Port to bind exporter, in host:port format") - flag.StringVar(&c.MetricPath, "metrics-path", defaultMetricsPath, "Metrics path to expose prometheus metrics") - - flag.StringVar(&c.SquidHostname, "squid-hostname", defaultSquidHostname, "Squid hostname") - flag.IntVar(&c.SquidPort, "squid-port", defaultSquidPort, "Squid port to read metrics") - - flag.StringVar(&c.Login, "squid-login", "", "Login to squid service") - flag.StringVar(&c.Password, "squid-password", "", "Password to squid service") - versionFlag = flag.Bool("version", false, "Print the version and exit") - - flag.Parse() - - return c -} diff -Nru prometheus-squid-exporter-1.4+ds/debian/changelog prometheus-squid-exporter-1.8.2+ds/debian/changelog --- prometheus-squid-exporter-1.4+ds/debian/changelog 2019-01-23 11:01:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/debian/changelog 2020-01-09 18:06:28.000000000 +0000 @@ -1,3 +1,17 @@ +prometheus-squid-exporter (1.8.2+ds-1) unstable; urgency=medium + + [ Daniel Swarbrick ] + * New upstream release. + * Bump Standards-Version (debhelper-compat = 12). + * Refresh patches. + * d/copyright: fix excluded files wildcard + + [ Martina Ferrari ] + * Automated cme fixes. + * Add myself to uploaders. + + -- Martina Ferrari Thu, 09 Jan 2020 18:06:28 +0000 + prometheus-squid-exporter (1.4+ds-1) unstable; urgency=medium * Initial release. Closes: #920258. diff -Nru prometheus-squid-exporter-1.4+ds/debian/compat prometheus-squid-exporter-1.8.2+ds/debian/compat --- prometheus-squid-exporter-1.4+ds/debian/compat 2019-01-23 11:01:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -11 diff -Nru prometheus-squid-exporter-1.4+ds/debian/control prometheus-squid-exporter-1.8.2+ds/debian/control --- prometheus-squid-exporter-1.4+ds/debian/control 2019-01-23 11:01:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/debian/control 2020-01-09 18:06:28.000000000 +0000 @@ -1,14 +1,16 @@ Source: prometheus-squid-exporter Maintainer: Debian Go Packaging Team -Uploaders: Daniel Swarbrick +Uploaders: Daniel Swarbrick , + Martina Ferrari , Section: net +Testsuite: autopkgtest-pkg-go Priority: optional -Build-Depends: debhelper (>= 11), +Build-Depends: debhelper-compat (= 12), dh-golang, golang-github-prometheus-client-golang-dev, golang-github-prometheus-common-dev, - golang-go -Standards-Version: 4.3.0 + golang-go, +Standards-Version: 4.4.1 Vcs-Browser: https://salsa.debian.org/go-team/packages/prometheus-squid-exporter Vcs-Git: https://salsa.debian.org/go-team/packages/prometheus-squid-exporter.git Homepage: https://github.com/boynux/squid-exporter @@ -16,8 +18,9 @@ Package: prometheus-squid-exporter Architecture: any -Depends: ${misc:Depends}, ${shlibs:Depends} -Built-Using: ${misc:Built-Using} +Depends: ${misc:Depends}, + ${shlibs:Depends}, +Built-Using: ${misc:Built-Using}, Description: Prometheus exporter for Squid proxy servers Prometheus exporter which connects to a Squid proxy server's cache manager API and exposes metrics such as: diff -Nru prometheus-squid-exporter-1.4+ds/debian/copyright prometheus-squid-exporter-1.8.2+ds/debian/copyright --- prometheus-squid-exporter-1.4+ds/debian/copyright 2019-01-23 11:01:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/debian/copyright 2020-01-09 18:06:28.000000000 +0000 @@ -2,17 +2,17 @@ Upstream-Name: github.com/boynux/squid-exporter Source: https://github.com/boynux/squid-exporter Files-Excluded: - vendor + vendor/* Files: * Copyright: 2017 Mohammad Arab -License: MIT +License: Expat Files: debian/* Copyright: 2019 1&1 IONOS Cloud GmbH -License: MIT +License: Expat -License: MIT +License: Expat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff -Nru prometheus-squid-exporter-1.4+ds/debian/gbp.conf prometheus-squid-exporter-1.8.2+ds/debian/gbp.conf --- prometheus-squid-exporter-1.4+ds/debian/gbp.conf 2019-01-23 11:01:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/debian/gbp.conf 2020-01-09 18:06:28.000000000 +0000 @@ -1,5 +1,5 @@ [DEFAULT] -debian-branch = debian/master +debian-branch = debian/sid [buildpackage] dist = DEP14 diff -Nru prometheus-squid-exporter-1.4+ds/debian/patches/01-default_settings.patch prometheus-squid-exporter-1.8.2+ds/debian/patches/01-default_settings.patch --- prometheus-squid-exporter-1.4+ds/debian/patches/01-default_settings.patch 2019-01-23 11:01:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/debian/patches/01-default_settings.patch 2020-01-09 18:06:28.000000000 +0000 @@ -1,8 +1,8 @@ Description: Set default listen address to be reachable via network. Author: Daniel Swarbrick ---- a/config.go -+++ b/config.go -@@ -5,7 +5,7 @@ +--- a/config/config.go ++++ b/config/config.go +@@ -10,7 +10,7 @@ ) const ( diff -Nru prometheus-squid-exporter-1.4+ds/Dockerfile prometheus-squid-exporter-1.8.2+ds/Dockerfile --- prometheus-squid-exporter-1.4+ds/Dockerfile 2018-11-05 19:41:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/Dockerfile 2020-01-09 12:57:19.000000000 +0000 @@ -9,6 +9,9 @@ FROM scratch COPY --from=builder /go/bin/squid-exporter /usr/local/bin/squid-exporter +# Allow /etc/hosts to be used for DNS +COPY --from=builder /etc/nsswitch.conf /etc/nsswitch.conf + EXPOSE 9301 ENTRYPOINT ["/usr/local/bin/squid-exporter"] diff -Nru prometheus-squid-exporter-1.4+ds/go.mod prometheus-squid-exporter-1.8.2+ds/go.mod --- prometheus-squid-exporter-1.4+ds/go.mod 1970-01-01 00:00:00.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/go.mod 2020-01-09 12:57:19.000000000 +0000 @@ -0,0 +1,10 @@ +module github.com/boynux/squid-exporter + +go 1.12 + +require ( + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/prometheus/client_golang v1.1.0 + github.com/prometheus/common v0.6.0 +) diff -Nru prometheus-squid-exporter-1.4+ds/go.sum prometheus-squid-exporter-1.8.2+ds/go.sum --- prometheus-squid-exporter-1.4+ds/go.sum 1970-01-01 00:00:00.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/go.sum 2020-01-09 12:57:19.000000000 +0000 @@ -0,0 +1,68 @@ +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/boynux/squid-exporter v0.0.0-20171021195124-6dcf7c016995/go.mod h1:VSICGV4XC8I2AsWmKFRAxYOYNc/GxKAVkARON6FaD68= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= +github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= +github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= +github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdOCQUEXhbk/P4A9WmJq0= +golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff -Nru prometheus-squid-exporter-1.4+ds/main.go prometheus-squid-exporter-1.8.2+ds/main.go --- prometheus-squid-exporter-1.4+ds/main.go 2018-11-05 19:41:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/main.go 2020-01-09 12:57:19.000000000 +0000 @@ -7,7 +7,9 @@ "os" "github.com/boynux/squid-exporter/collector" + "github.com/boynux/squid-exporter/config" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/version" ) @@ -24,22 +26,22 @@ } func main() { - config := NewConfig() - if *versionFlag { + cfg := config.NewConfig() + if *config.VersionFlag { log.Println(version.Print("squid_exporter")) os.Exit(0) } - log.Println("Scraping metrics from", fmt.Sprintf("%s:%d", config.SquidHostname, config.SquidPort)) - e := collector.New(config.SquidHostname, config.SquidPort, config.Login, config.Password) + log.Println("Scraping metrics from", fmt.Sprintf("%s:%d", cfg.SquidHostname, cfg.SquidPort)) + e := collector.New(cfg.SquidHostname, cfg.SquidPort, cfg.Login, cfg.Password, cfg.Labels) prometheus.MustRegister(e) // Serve metrics - http.Handle(config.MetricPath, prometheus.Handler()) + http.Handle(cfg.MetricPath, promhttp.Handler()) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(indexContent)) }) - log.Println("Listening on", fmt.Sprintf("%s", config.ListenAddress)) - log.Fatal(http.ListenAndServe(fmt.Sprintf("%s", config.ListenAddress), nil)) + log.Println("Listening on", fmt.Sprintf("%s", cfg.ListenAddress)) + log.Fatal(http.ListenAndServe(fmt.Sprintf("%s", cfg.ListenAddress), nil)) } diff -Nru prometheus-squid-exporter-1.4+ds/prometheus/prometheus.yml prometheus-squid-exporter-1.8.2+ds/prometheus/prometheus.yml --- prometheus-squid-exporter-1.4+ds/prometheus/prometheus.yml 1970-01-01 00:00:00.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/prometheus/prometheus.yml 2020-01-09 12:57:19.000000000 +0000 @@ -0,0 +1,29 @@ +# my global config +global: + scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. + # scrape_timeout is set to the global default (10s). + +# Alertmanager configuration +alerting: + alertmanagers: + - static_configs: + - targets: + # - alertmanager:9093 + +# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. +rule_files: + # - "first_rules.yml" + # - "second_rules.yml" + +# A scrape configuration containing exactly one endpoint to scrape: +# Here it's Prometheus itself. +scrape_configs: + # The job name is added as a label `job=` to any timeseries scraped from this config. + - job_name: 'squid' + + # metrics_path defaults to '/metrics' + # scheme defaults to 'http' + + static_configs: + - targets: ['localhost:9301'] diff -Nru prometheus-squid-exporter-1.4+ds/README.md prometheus-squid-exporter-1.8.2+ds/README.md --- prometheus-squid-exporter-1.4+ds/README.md 2018-11-05 19:41:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/README.md 2020-01-09 12:57:19.000000000 +0000 @@ -1,5 +1,6 @@ [![Build Status](https://travis-ci.org/boynux/squid-exporter.svg?branch=master)](https://travis-ci.org/boynux/squid-exporter) [![Go Report Card](https://goreportcard.com/badge/github.com/boynux/squid-exporter)](https://goreportcard.com/report/github.com/boynux/squid-exporter) +[![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/boynux/squid-exporter) Squid Prometheus exporter -------------------------- @@ -8,13 +9,19 @@ **NOTE**: From release 1.0 metric names and some parameters has changed. Make sure you check the docs and update your deployments accordingly! +New +----- + +* Using environment variables to configure the exporter +* Adding custom labels to metrics + Usage: ------ Simple usage: squid-exporter -squid-hostname "localhost" -squid-port 3128 -Configure Prometheus to scrape metrics from `localhost:9301/metrics` +[Configure Prometheus](https://github.com/boynux/squid-exporter/blob/master/prometheus/prometheus.yml) to scrape metrics from `localhost:9301/metrics` - job_name: squid # squid-exporter is installed, grab stats about the local @@ -22,10 +29,20 @@ target_groups: - targets: ['localhost:9301'] -To get all the parameteres +To get all the parameteres, command line arguments always override default and environment variables configs: - squid-exprter -help + squid-exporter -help +The following environment variables can be used to override default parameters: + +``` +SQUID_EXPORTER_LISTEN +SQUID_EXPORTER_METRICS_PATH +SQUID_HOSTNAME +SQUID_PORT +SQUID_LOGIN +SQUID_PASSWORD +``` Usage with docker: ------ @@ -37,6 +54,10 @@ docker run -p 9301:9301 -d boynux/squid-exporter -squid-hostname "192.168.0.2" -squid-port 3128 -listen ":9301" +With environment variables + + docker run -p 9301:9301 -d -e SQUID_PORT="3128" -e SQUID_HOSTNAME="192.168.0.2" -e SQUID_EXPORTER_LISTEN=":9301" boynux/squid-exporter + Build: -------- @@ -69,6 +90,19 @@ - [ ] Other metrics - [x] Squid Authentication (Basic Auth) +FAQ: +-------- + +- Q: Metrics are not reported by exporter +- A: That usually means the exporter cannot reach squid server or the config manager permissions are not set corretly. To debug and mitigate: + - First make sure the exporter service can reach to squid server IP Address (you can use telnet to test that) + - Make sure you allow exporter to query the squid server in config you will need something like this (`172.20.0.0/16` is the network for exporter, you can also use a single IP if needed): + ``` + #http_access allow manager localhost + acl prometheus src 172.20.0.0/16 + http_access allow manager prometheus + ``` + Contribution: ------------- diff -Nru prometheus-squid-exporter-1.4+ds/VERSION prometheus-squid-exporter-1.8.2+ds/VERSION --- prometheus-squid-exporter-1.4+ds/VERSION 2018-11-05 19:41:45.000000000 +0000 +++ prometheus-squid-exporter-1.8.2+ds/VERSION 2020-01-09 12:57:19.000000000 +0000 @@ -1 +1 @@ -1.4 +1.8