From owner-svn-ports-head@freebsd.org Tue Mar 19 16:07:59 2019 Return-Path: Delivered-To: svn-ports-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ECED9155462D; Tue, 19 Mar 2019 16:07:58 +0000 (UTC) (envelope-from zi@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 937A28AF7D; Tue, 19 Mar 2019 16:07:58 +0000 (UTC) (envelope-from zi@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 651A3B863; Tue, 19 Mar 2019 16:07:58 +0000 (UTC) (envelope-from zi@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x2JG7wsf009705; Tue, 19 Mar 2019 16:07:58 GMT (envelope-from zi@FreeBSD.org) Received: (from zi@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x2JG7vfr009701; Tue, 19 Mar 2019 16:07:57 GMT (envelope-from zi@FreeBSD.org) Message-Id: <201903191607.x2JG7vfr009701@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: zi set sender to zi@FreeBSD.org using -f From: Ryan Steinmetz Date: Tue, 19 Mar 2019 16:07:57 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r496269 - in head/net-mgmt/nsd_exporter: . files X-SVN-Group: ports-head X-SVN-Commit-Author: zi X-SVN-Commit-Paths: in head/net-mgmt/nsd_exporter: . files X-SVN-Commit-Revision: 496269 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 937A28AF7D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.94)[-0.941,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Mar 2019 16:07:59 -0000 Author: zi Date: Tue Mar 19 16:07:57 2019 New Revision: 496269 URL: https://svnweb.freebsd.org/changeset/ports/496269 Log: - Merge in metric handling patches from upstream - Bump PORTREVISION Modified: head/net-mgmt/nsd_exporter/Makefile head/net-mgmt/nsd_exporter/distinfo head/net-mgmt/nsd_exporter/files/patch-nsd__exporter.go Modified: head/net-mgmt/nsd_exporter/Makefile ============================================================================== --- head/net-mgmt/nsd_exporter/Makefile Tue Mar 19 16:04:10 2019 (r496268) +++ head/net-mgmt/nsd_exporter/Makefile Tue Mar 19 16:07:57 2019 (r496269) @@ -3,7 +3,7 @@ PORTNAME= nsd_exporter PORTVERSION= 0.1.0 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= net-mgmt MAINTAINER= zi@FreeBSD.org @@ -34,6 +34,7 @@ USE_RC_SUBR= nsd_exporter post-patch: ${REINPLACE_CMD} -e 's|"/etc|"${LOCALBASE}/etc|g' ${WRKSRC_go_nsdctl}/nsdctl.go + ${REINPLACE_CMD} -e 's|"/etc|"${LOCALBASE}/etc|g' ${WRKSRC}/nsd_exporter.go pre-build: ${MKDIR} ${GO_WRKDIR_SRC}/github.com/prometheus ${GO_WRKDIR_SRC}/gopkg.in \ Modified: head/net-mgmt/nsd_exporter/distinfo ============================================================================== --- head/net-mgmt/nsd_exporter/distinfo Tue Mar 19 16:04:10 2019 (r496268) +++ head/net-mgmt/nsd_exporter/distinfo Tue Mar 19 16:07:57 2019 (r496269) @@ -1,4 +1,4 @@ -TIMESTAMP = 1551277938 +TIMESTAMP = 1553011211 SHA256 (optix2000-nsd_exporter-0.1.0_GH0.tar.gz) = 7fb9fae9f434e904e79eceaef9e5640e8be66d57384f87a9a6a85ab663dcf51c SIZE (optix2000-nsd_exporter-0.1.0_GH0.tar.gz) = 8144 SHA256 (prometheus-client_golang-v0.8.0_GH0.tar.gz) = 88b0040393276116f848de5bdd636717d339667273cfc45a4edda40b5e5682bd Modified: head/net-mgmt/nsd_exporter/files/patch-nsd__exporter.go ============================================================================== --- head/net-mgmt/nsd_exporter/files/patch-nsd__exporter.go Tue Mar 19 16:04:10 2019 (r496268) +++ head/net-mgmt/nsd_exporter/files/patch-nsd__exporter.go Tue Mar 19 16:07:57 2019 (r496269) @@ -1,15 +1,14 @@ --- nsd_exporter.go.orig 2018-02-08 23:45:14 UTC +++ nsd_exporter.go -@@ -19,7 +19,7 @@ import ( - var listenAddr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.") - var metricPath = flag.String("metric-path", "/metrics", "The path to export Prometheus metrocs to.") - var metricConfigPath = flag.String("metric-config", "", "Mapping file for metrics. Defaults to built in file for NSD 4.1.x. This allows you to add or change any metrics that this scrapes") --var nsdConfig = flag.String("config-file", "/etc/nsd/nsd.conf", "Configuration file for nsd/unbound to autodetect configuration from. Defaults to /etc/nsd/nsd.conf. Mutually exclusive with -nsd-address, -cert, -key and -ca") -+var nsdConfig = flag.String("config-file", "/usr/local/etc/nsd/nsd.conf", "Configuration file for nsd/unbound to autodetect configuration from. Defaults to /usr/local/etc/nsd/nsd.conf. Mutually exclusive with -nsd-address, -cert, -key and -ca") - var nsdType = flag.String("type", "nsd", "What nsd-like daemon to scrape (nsd or unbound). Defaults to nsd") - var cert = flag.String("cert", "", "Client cert file location. Mutually exclusive with -config-file.") - var key = flag.String("key", "", "Client key file location. Mutually exclusive with -config-file.") -@@ -58,7 +58,7 @@ func (c *NSDCollector) Collect(ch chan<- +@@ -5,6 +5,7 @@ package main + import ( + "bufio" + "flag" ++ "fmt" + "log" + "net/http" + "strconv" +@@ -58,10 +59,20 @@ func (c *NSDCollector) Collect(ch chan<- s := bufio.NewScanner(r) for s.Scan() { line := strings.Split(s.Text(), "=") @@ -17,4 +16,148 @@ + metricName := strings.TrimSpace(line[0]) m, ok := c.metrics[metricName] if !ok { - log.Println("Unknown Metric ", metricName, ". Skipping.") +- log.Println("Unknown Metric ", metricName, ". Skipping.") ++ log.Println("New metric " + metricName + " found. Refreshing.") ++ // Try to update the metrics list ++ err = c.updateMetric(s.Text()) ++ if err != nil { ++ log.Println(err.Error()) ++ } ++ // Refetch metric ++ m, ok = c.metrics[metricName] ++ if !ok { ++ log.Println("Metric " + metricName + "not configured. Skipping") ++ } + continue + } + value, err := strconv.ParseFloat(line[1], 64) +@@ -84,7 +95,57 @@ func (c *NSDCollector) Collect(ch chan<- + + } + +-func (c *NSDCollector) updateMetricsList() error { ++func (c *NSDCollector) updateMetric(s string) error { ++ // Assume line is in "metric=#" format ++ line := strings.Split(s, "=") ++ metricName := strings.TrimSpace(line[0]) ++ ++ _, exists := c.metrics[metricName] ++ if !exists { ++ metricConf, ok := metricConfiguration.Metrics[metricName] ++ if ok { ++ promName := nsdToProm.Replace(line[0]) ++ c.metrics[metricName] = &promMetric{ ++ desc: prometheus.NewDesc( ++ prometheus.BuildFQName(*nsdType, "", promName), ++ metricConf.Help, ++ nil, ++ nil, ++ ), ++ valueType: metricConf.Type, ++ } ++ } else { // Try labeled metric ++ for _, v := range metricConfiguration.LabelMetrics { ++ labels := v.Regex.FindStringSubmatch(metricName) ++ if labels != nil { ++ var promName string ++ if v.Name != "" { ++ promName = v.Name ++ } else { ++ promName = nsdToProm.Replace(line[0]) ++ } ++ c.metrics[metricName] = &promMetric{ ++ desc: prometheus.NewDesc( ++ prometheus.BuildFQName(*nsdType, "", promName), ++ v.Help, ++ v.Labels, ++ nil, ++ ), ++ valueType: v.Type, ++ labels: labels[1:len(labels)], ++ } ++ // python "for-else" ++ goto Found ++ } ++ } ++ return fmt.Errorf("Metric ", metricName, " not found in config.") ++ Found: ++ } ++ } ++ return nil ++} ++ ++func (c *NSDCollector) initMetricsList() error { + r, err := c.client.Command("stats_noreset") + if err != nil { + log.Println(err) +@@ -98,49 +159,9 @@ func (c *NSDCollector) updateMetricsList + // Grab metrics + s := bufio.NewScanner(r) + for s.Scan() { +- // Assume line is in "metric=#" format +- line := strings.Split(s.Text(), "=") +- metricName := line[0] +- +- _, exists := c.metrics[metricName] +- if !exists { +- metricConf, ok := metricConfiguration.Metrics[metricName] +- if ok { +- promName := nsdToProm.Replace(line[0]) +- c.metrics[metricName] = &promMetric{ +- desc: prometheus.NewDesc( +- prometheus.BuildFQName(*nsdType, "", promName), +- metricConf.Help, +- nil, +- nil, +- ), +- valueType: metricConf.Type, +- } +- } else { // Try labeled metric +- for _, v := range metricConfiguration.LabelMetrics { +- // TODO: Move this to Collect(), to catch any metrics that are created at runtime +- // Unfortunately prom needs all metrics defined at the beginning +- labels := v.Regex.FindStringSubmatch(metricName) +- if labels != nil { +- var promName string +- if v.Name != "" { +- promName = v.Name +- } else { +- promName = nsdToProm.Replace(line[0]) +- } +- c.metrics[metricName] = &promMetric{ +- desc: prometheus.NewDesc( +- prometheus.BuildFQName(*nsdType, "", promName), +- v.Help, +- v.Labels, +- nil, +- ), +- valueType: v.Type, +- labels: labels[1:len(labels)], +- } +- } +- } +- } ++ err = c.updateMetric(s.Text()) ++ if err != nil { ++ log.Println(err.Error(), "Skipping.") + } + } + return s.Err() +@@ -156,7 +177,7 @@ func NewNSDCollector(nsdType string, hos + client: client, + } + +- err = collector.updateMetricsList() ++ err = collector.initMetricsList() + if err != nil { + log.Println(err) + return nil, err +@@ -174,7 +195,7 @@ func NewNSDCollectorFromConfig(path stri + client: client, + } + +- err = collector.updateMetricsList() ++ err = collector.initMetricsList() + if err != nil { + log.Println(err) + return nil, err