mirror of
https://git.freebsd.org/ports.git
synced 2025-07-18 17:59:20 -04:00
- Merge in metric handling patches from upstream
- Bump PORTREVISION
This commit is contained in:
parent
2da2d29922
commit
a3db24329f
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=496269
3 changed files with 157 additions and 13 deletions
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue