From e1883a1c7314e11e05475e8bd6bbb017889c6ad8 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 10 Apr 2024 20:03:51 +0800 Subject: [PATCH] Fix up after rebasing on prometheus upstream --- collector/collector.go | 16 + collector/gmond.go | 124 ------ collector/textfile.go | 2 +- go.mod | 43 +- go.sum | 77 +++- node_exporter.go | 398 +++++++++--------- support-files/config/node_exporter.conf | 8 +- vendor/github.com/go-kit/kit/LICENSE | 25 -- .../github.com/mdlayher/genetlink/LICENSE.md | 10 - .../golang.org/x/sys/unix/asm_openbsd_arm.s | 56 --- vendor/golang.org/x/sys/unix/constants.go | 16 - vendor/golang.org/x/sys/unix/syscall.go | 54 --- 12 files changed, 322 insertions(+), 507 deletions(-) delete mode 100644 collector/gmond.go delete mode 100644 vendor/github.com/go-kit/kit/LICENSE delete mode 100644 vendor/github.com/mdlayher/genetlink/LICENSE.md delete mode 100644 vendor/golang.org/x/sys/unix/asm_openbsd_arm.s delete mode 100644 vendor/golang.org/x/sys/unix/constants.go delete mode 100644 vendor/golang.org/x/sys/unix/syscall.go diff --git a/collector/collector.go b/collector/collector.go index 3112c78970..c01c4986cc 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -244,3 +244,19 @@ func pushMetric(ch chan<- prometheus.Metric, fieldDesc *prometheus.Desc, name st ch <- prometheus.MustNewConstMetric(fieldDesc, valueType, fVal, labelValues...) } + +// Collectors returns a name list of registered/available collectors +func Collectors() []string { + collectors := make([]string, 0) + for k := range collectorState { + collectors = append(collectors, k) + } + return collectors +} + +// SetCollectorState sets state of a registered/available collector +func SetCollectorState(name string, state bool) { + if _, ok := collectorState[name]; ok { + collectorState[name] = &state + } +} diff --git a/collector/gmond.go b/collector/gmond.go deleted file mode 100644 index 560627511c..0000000000 --- a/collector/gmond.go +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2015 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !nogmond -// +build !nogmond - -package collector - -import ( - "bufio" - "encoding/xml" - "fmt" - "io" - "net" - "regexp" - "time" - - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/common/log" - "github.com/prometheus/node_exporter/collector/ganglia" -) - -const ( - gangliaAddress = "127.0.0.1:8649" - gangliaProto = "tcp" - gangliaTimeout = 30 * time.Second - gangliaNamespace = "ganglia" -) - -type gmondCollector struct { - metrics map[string]*prometheus.GaugeVec -} - -func init() { - registerCollector("gmond", defaultDisabled, NewGmondCollector) -} - -var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`) - -// NewGmondCollector returns a new Collector scraping ganglia. -func NewGmondCollector() (Collector, error) { - warnDeprecated("gmond") - c := gmondCollector{ - metrics: map[string]*prometheus.GaugeVec{}, - } - - return &c, nil -} - -func (c *gmondCollector) Update(ch chan<- prometheus.Metric) error { - conn, err := net.Dial(gangliaProto, gangliaAddress) - log.Debugf("gmondCollector Update") - if err != nil { - return fmt.Errorf("can't connect to gmond: %s", err) - } - conn.SetDeadline(time.Now().Add(gangliaTimeout)) - - ganglia := ganglia.Ganglia{} - decoder := xml.NewDecoder(bufio.NewReader(conn)) - decoder.CharsetReader = toUtf8 - - err = decoder.Decode(&ganglia) - if err != nil { - return fmt.Errorf("couldn't parse xml: %s", err) - } - - for _, cluster := range ganglia.Clusters { - for _, host := range cluster.Hosts { - - for _, metric := range host.Metrics { - name := illegalCharsRE.ReplaceAllString(metric.Name, "_") - - c.setMetric(name, cluster.Name, metric) - } - } - } - for _, m := range c.metrics { - m.Collect(ch) - } - return err -} - -func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric) { - if _, ok := c.metrics[name]; !ok { - var desc string - var title string - for _, element := range metric.ExtraData.ExtraElements { - switch element.Name { - case "DESC": - desc = element.Val - case "TITLE": - title = element.Val - } - if title != "" && desc != "" { - break - } - } - log.Debugf("Register %s: %s", name, desc) - c.metrics[name] = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: gangliaNamespace, - Name: name, - Help: desc, - }, - []string{"cluster"}, - ) - } - log.Debugf("Set %s{cluster=%q}: %f", name, cluster, metric.Value) - c.metrics[name].WithLabelValues(cluster).Set(metric.Value) -} - -func toUtf8(charset string, input io.Reader) (io.Reader, error) { - return input, nil //FIXME -} diff --git a/collector/textfile.go b/collector/textfile.go index 48133f7c98..41ce1a14fc 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -33,7 +33,7 @@ import ( ) var ( - textFileDirectory = kingpin.Flag("collector.textfile.directory", "Directory to read text files with metrics from.").Default("").String() + textFileDirectory = kingpin.Flag("collector.textfile.directory", "Directory to read text files with metrics from.").Default("/opt/ss/ssm-client/textfile-collector").String() mtimeDesc = prometheus.NewDesc( "node_textfile_mtime_seconds", "Unixtime mtime of textfiles successfully read.", diff --git a/go.mod b/go.mod index c1d9d85049..06589d8963 100644 --- a/go.mod +++ b/go.mod @@ -27,38 +27,55 @@ require ( github.com/prometheus/common v0.45.0 github.com/prometheus/exporter-toolkit v0.10.0 github.com/prometheus/procfs v0.12.0 + github.com/prometheus/promu v0.2.0 github.com/safchain/ethtool v0.3.0 - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 - golang.org/x/sys v0.13.0 + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 + golang.org/x/sys v0.15.0 + gopkg.in/ini.v1 v1.67.0 + gopkg.in/yaml.v2 v2.4.0 howett.net/plist v1.0.0 - github.com/prometheus/promu v0.2.0 ) require ( github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/dennwc/ioctl v1.0.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.5.9 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect - github.com/kr/text v0.2.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/mdlayher/genetlink v1.3.2 // indirect github.com/mdlayher/socket v0.4.1 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/cobra v1.8.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/viper v1.18.2 // indirect + github.com/subosito/gotenv v1.6.0 // indirect github.com/xhit/go-str2duration/v2 v2.1.0 // indirect - go.uber.org/atomic v1.7.0 // indirect - go.uber.org/multierr v1.6.0 // indirect - golang.org/x/crypto v0.14.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/oauth2 v0.12.0 // indirect - golang.org/x/sync v0.3.0 // indirect - golang.org/x/text v0.13.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + golang.org/x/crypto v0.16.0 // indirect + golang.org/x/net v0.19.0 // indirect + golang.org/x/oauth2 v0.15.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.31.0 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 327236dda6..ed09de29b3 100644 --- a/go.sum +++ b/go.sum @@ -11,15 +11,20 @@ github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cilium/ebpf v0.11.0 h1:V8gS/bTCCjX9uUnkUFUpPsksM8n1lXBAvHcpiFk1X2Y= github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 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/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dennwc/btrfs v0.0.0-20230312211831-a1f570bd01a1 h1:ue4Es4Xzz255hWQ7NAWzZxuXG+YOV7URzzusLLSe0zU= github.com/dennwc/btrfs v0.0.0-20230312211831-a1f570bd01a1/go.mod h1:MYsOV9Dgsec3FFSOjywi0QK5r6TeBbdWxdrMGtiYXHA= github.com/dennwc/ioctl v1.0.0 h1:DsWAAjIxRqNcLn9x6mwfuf2pet3iB7aK90K4tF16rLg= github.com/dennwc/ioctl v1.0.0/go.mod h1:ellh2YB5ldny99SBU/VX7Nq0xiZbHphf1DrtHxxjMk0= github.com/ema/qdisc v1.0.0 h1:EHLG08FVRbWLg8uRICa3xzC9Zm0m7HyMHfXobWFnXYg= github.com/ema/qdisc v1.0.0/go.mod h1:FhIc0fLYi7f+lK5maMsesDqwYojIOh3VfRs8EVd5YJQ= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA= @@ -36,10 +41,14 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/hashicorp/go-envparse v0.1.0 h1:bE++6bhIsNCPLvgDZkYqo3nA+/PFI51pkrHdmPSDFPY= github.com/hashicorp/go-envparse v0.1.0/go.mod h1:OHheN1GoygLlAkTlXLXvAdnXdZxy8JUweQ1rAXx1xnc= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hodgesds/perf-utils v0.7.0 h1:7KlHGMuig4FRH5fNw68PV6xLmgTe7jKs9hgAcEAbioU= github.com/hodgesds/perf-utils v0.7.0/go.mod h1:LAklqfDadNKpkxoAJNHpD5tkY0rkZEVdnCEWN5k4QJY= github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973 h1:hk4LPqXIY/c9XzRbe7dA6qQxaT6Axcbny0L/G5a4owQ= github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973/go.mod h1:PoK3ejP3LJkGTzKqRlpvCIFas3ncU02v8zzWDW+g0FY= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA= github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= @@ -49,9 +58,10 @@ github.com/jsimonetti/rtnetlink v1.3.5 h1:hVlNQNRlLDGZz31gBPicsG7Q53rnlsz1l1Ix/9 github.com/jsimonetti/rtnetlink v1.3.5/go.mod h1:0LFedyiTkebnd43tE4YAkWGIq9jQphow4CcwxaT2Y00= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lufia/iostat v1.2.1 h1:tnCdZBIglgxD47RyD55kfWQcJMGzO+1QBziSQfesf2k= github.com/lufia/iostat v1.2.1/go.mod h1:rEPNA0xXgjHQjuI5Cy05sLlS2oRcSlWHRLrvh/AQ+Pg= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-xmlrpc v0.0.3 h1:Y6WEMLEsqs3RviBrAa1/7qmbGB7DVD3brZIbqMbQdGY= github.com/mattn/go-xmlrpc v0.0.3/go.mod h1:mqc2dz7tP5x5BKlCahN/n+hs7OSZKJkS9JsHNBRlrxA= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= @@ -66,12 +76,18 @@ github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= github.com/mdlayher/wifi v0.1.0 h1:y8wYRUXwok5CtUZOXT3egghYesX0O79E3ALl+SIDm9Q= github.com/mdlayher/wifi v0.1.0/go.mod h1:+gBYnZAMcUKHSFzMJXwlz7tLsEHgwDJ9DJCefhJM+gI= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU= github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= +github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/prometheus-community/go-runit v0.1.0 h1:uTWEj/Fn2RoLdfg/etSqwzgYNOYPrARx1BHUN052tGA= github.com/prometheus-community/go-runit v0.1.0/go.mod h1:AvJ9Jo3gAFu2lbM4+qfjdpq30FfiLDJZKbQ015u08IQ= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= @@ -87,10 +103,27 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c github.com/prometheus/promu v0.2.0 h1:QKoCatPW0XeOG/9ghBv4qESc4G74NHCzuIzsm6SLVt4= github.com/prometheus/promu v0.2.0/go.mod h1:7vT+16au8n5E4UrtokdU7btmuJ1bF9df9F9s79Cgs3E= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/safchain/ethtool v0.3.0 h1:gimQJpsI6sc1yIqP/y8GYgiXn/NjgvpM0RNoWLVVmP0= github.com/safchain/ethtool v0.3.0/go.mod h1:SA9BwrgyAqNo7M+uaL6IYbxpm5wk3L7Mm6ocLW+CJUs= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973 h1:GfSdC6wKfTGcgCS7BtzF5694Amne1pGCSTY252WhlEY= github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973/go.mod h1:G81aIFAMS9ECrwBYR9YxhlPjWgrItd+Kje78O6+uqm8= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= +github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -100,20 +133,24 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= @@ -123,15 +160,15 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4= -golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ= +golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -143,8 +180,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -157,8 +194,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -173,6 +210,8 @@ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/node_exporter.go b/node_exporter.go index 238d802e31..52dd0529d1 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -14,7 +14,6 @@ package main import ( - "flag" "fmt" stdlog "log" "net/http" @@ -24,12 +23,9 @@ import ( "reflect" "runtime" "sort" - "strconv" "strings" - "github.com/prometheus/common/promlog" - "github.com/prometheus/common/promlog/flag" - + prometheusConfig "github.com/prometheus/common/config" "github.com/prometheus/common/promlog" "github.com/prometheus/common/promlog/flag" @@ -41,9 +37,9 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/version" "github.com/prometheus/exporter-toolkit/web" - "github.com/prometheus/exporter-toolkit/web/kingpinflag" - "github.com/prometheus/node_exporter/collector" + "github.com/shatteredsilicon/node_exporter/collector" "gopkg.in/ini.v1" + "gopkg.in/yaml.v2" ) // handler wraps an unfiltered http.Handler but uses a filtered handler, @@ -59,13 +55,6 @@ type handler struct { logger log.Logger } -var cfg = new(config) -var ( - configPath = flag.String("config", "/opt/ss/ssm-client/node_exporter.conf", "Path of config file") - enabledCollectors = flag.String("collectors.enabled", filterAvailableCollectors(defaultCollectors), "Comma-separated list of collectors to use.") - printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") -) - func newHandler(includeExporterMetrics bool, maxRequests int, logger log.Logger) *handler { h := &handler{ exporterMetricsRegistry: prometheus.NewRegistry(), @@ -169,30 +158,80 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { return handler, nil } +var cfg = new(config) +var setByUserMap = make(map[string]bool) + +func flagAction(flagName string) func(ctx *kingpin.ParseContext) error { + return func(ctx *kingpin.ParseContext) error { + setByUserMap[flagName] = true + return nil + } +} + +var ( + disableDefaultCollectors = kingpin.Flag( + "collector.disable-defaults", + "Set all collectors to disabled by default.", + ).Action(flagAction("collector.disable-defaults")).Bool() + maxProcs = kingpin.Flag( + "runtime.gomaxprocs", "The target number of CPUs Go will run on (GOMAXPROCS)", + ).Envar("GOMAXPROCS").Action(flagAction("runtime.gomaxprocs")).Int() + disableExporterMetrics = kingpin.Flag( + "web.disable-exporter-metrics", + "Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).", + ).Action(flagAction("web.disable-exporter-metrics")).Bool() + maxRequests = kingpin.Flag( + "web.max-requests", + "Maximum number of parallel scrape requests. Use 0 to disable.", + ).Action(flagAction("web.max-requests")).Int() + metricsPath = kingpin.Flag( + "web.telemetry-path", + "Path under which to expose metrics.", + ).Action(flagAction("web.telemetry-path")).String() + configPath = kingpin.Flag( + "config", + "Path of config file", + ).Action(flagAction("config")).Default("/opt/ss/ssm-client/node_exporter.conf").String() + listenAddress = kingpin.Flag( + "web.listen-address", + "Address on which to expose metrics and web interface.", + ).Action(flagAction("web.listen-address")).Strings() + enabledCollectors = kingpin.Flag( + "collectors.enabled", + "Comma-separated list of collectors to use.", + ).Action(flagAction("collectors.enabled")).String() + printCollectors = kingpin.Flag( + "collectors.print", + "If true, print available collectors and exit.", + ).Action(flagAction("collectors.print")).Bool() + sslCertFile = kingpin.Flag( + "web.ssl-cert-file", + "Path to SSL certificate file.", + ).Action(flagAction("web.ssl-cert-file")).Default("").String() + sslKeyFile = kingpin.Flag( + "web.ssl-key-file", + "Path to SSL key file.", + ).Action(flagAction("web.ssl-key-file")).String() + webAuthFile = kingpin.Flag( + "web.auth-file", + "Path to YAML file with server_user, server_password keys for HTTP Basic authentication.", + ).Action(flagAction("web.auth-file")).String() + webConfigFile = kingpin.Flag( + "web.config.file", + "Path to prometheus web config file (YAML).", + ).Action(flagAction("web.config.file")).String() + systemdSocket = kingpin.Flag( + "web.systemd-socket", + "Use systemd socket activation listeners instead of port listeners (Linux only).", + ).Action(flagAction("web.systemd-socket")).Bool() +) + func main() { - flag.Parse() - var ( - metricsPath = kingpin.Flag( - "web.telemetry-path", - "Path under which to expose metrics.", - ).Default("/metrics").String() - disableExporterMetrics = kingpin.Flag( - "web.disable-exporter-metrics", - "Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).", - ).Bool() - maxRequests = kingpin.Flag( - "web.max-requests", - "Maximum number of parallel scrape requests. Use 0 to disable.", - ).Default("40").Int() - disableDefaultCollectors = kingpin.Flag( - "collector.disable-defaults", - "Set all collectors to disabled by default.", - ).Default("false").Bool() - maxProcs = kingpin.Flag( - "runtime.gomaxprocs", "The target number of CPUs Go will run on (GOMAXPROCS)", - ).Envar("GOMAXPROCS").Default("1").Int() - toolkitFlags = kingpinflag.AddFlags(kingpin.CommandLine, ":9100") - ) + kingpin.Parse() + + if err := ini.MapTo(&cfg, *configPath); err != nil { + stdlog.Fatalf(fmt.Sprintf("Load config file %s failed: %s\n", *configPath, err.Error())) + } promlogConfig := &promlog.Config{} flag.AddFlags(kingpin.CommandLine, promlogConfig) @@ -200,7 +239,6 @@ func main() { kingpin.CommandLine.UsageWriter(os.Stdout) kingpin.HelpFlag.Short('h') kingpin.Parse() - logger := promlog.New(promlogConfig) if os.Getenv("ON_CONFIGURE") == "1" { err := configure() @@ -210,24 +248,14 @@ func main() { os.Exit(0) } - err := ini.MapTo(cfg, *configPath) - if err != nil { - log.Fatal(fmt.Sprintf("Load config file %s failed: %s", *configPath, err.Error())) - } - - log.Infoln("Starting node_exporter", version.Info()) - log.Infoln("Build context", version.BuildContext()) + // override flag value with config value + // if it's not set + overrideFlags() - // set flags for exporter_shared server - flag.Set("web.ssl-cert-file", lookupConfig("web.ssl-cert-file", "").(string)) - flag.Set("web.ssl-key-file", lookupConfig("web.ssl-key-file", "").(string)) - flag.Set("web.auth-file", lookupConfig("web.auth-file", "/opt/ss/ssm-client/ssm.yml").(string)) - - if lookupConfig("collectors.print", *printCollectors).(bool) { - collectorNames := make(sort.StringSlice, 0, len(collector.Factories)) - for n := range collector.Factories { - collectorNames = append(collectorNames, n) - } + if *printCollectors { + names := collector.Collectors() + collectorNames := make(sort.StringSlice, 0, len(names)) + copy(collectorNames, names) collectorNames.Sort() fmt.Printf("Available collectors:\n") for _, n := range collectorNames { @@ -235,30 +263,26 @@ func main() { } return } - collectors, err := loadCollectors(lookupConfig("collectors.enabled", *enabledCollectors).(string)) - // This instance is only used to check collector creation and logging. - nc, err := collector.NewNodeCollector() - if err != nil { - log.Fatalf("Couldn't create collector: %s", err) - } - log.Infof("Enabled collectors:") - collectors := []string{} - for n := range nc.Collectors { - collectors = append(collectors, n) - } - sort.Strings(collectors) - for _, n := range collectors { - log.Infof(" - %s", n) - } if *disableDefaultCollectors { collector.DisableDefaultCollectors() } + + if *enabledCollectors != "" { + collector.DisableDefaultCollectors() + for _, name := range strings.Split(*enabledCollectors, ",") { + collector.SetCollectorState(name, true) + } + } + + logger := promlog.New(promlogConfig) + level.Info(logger).Log("msg", "Starting node_exporter", "version", version.Info()) level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext()) if user, err := user.Current(); err == nil && user.Uid == "0" { level.Warn(logger).Log("msg", "Node Exporter is running as root user. This exporter is designed to run as unprivileged user, root is not required.") } + runtime.GOMAXPROCS(*maxProcs) level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0)) @@ -283,7 +307,49 @@ func main() { http.Handle("/", landingPage) } + if *sslCertFile != "" || *sslKeyFile != "" { + if *webConfigFile == "" { + level.Error(logger).Log("Use web.config.file flag/config to tell the location of prometheus web file") + os.Exit(1) + } + + authConfigBytes, err := os.ReadFile(*webAuthFile) + if err != nil { + level.Error(logger).Log("err", err) + os.Exit(1) + } + var authC authConfig + if err := yaml.Unmarshal(authConfigBytes, &authC); err != nil { + level.Error(logger).Log("err", err) + os.Exit(1) + } + + prometheusWebConfig := web.Config{ + Users: map[string]prometheusConfig.Secret{ + authC.ServerUser: prometheusConfig.Secret(authC.ServerPassword), + }, + } + prometheusWebConfig.TLSConfig.TLSCertPath = *sslCertFile + prometheusWebConfig.TLSConfig.TLSKeyPath = *sslKeyFile + + webConfigBytes, err := yaml.Marshal(prometheusWebConfig) + if err != nil { + level.Error(logger).Log("err", err) + os.Exit(1) + } + + if err = os.WriteFile(*webConfigFile, webConfigBytes, 0600); err != nil { + level.Error(logger).Log("err", err) + os.Exit(1) + } + } + server := &http.Server{} + toolkitFlags := &web.FlagConfig{ + WebSystemdSocket: systemdSocket, + WebListenAddresses: listenAddress, + WebConfigFile: webConfigFile, + } if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil { level.Error(logger).Log("err", err) os.Exit(1) @@ -291,16 +357,22 @@ func main() { } type config struct { - WebConfig webConfig `ini:"web"` - CollectorsConfig collectorsConfig `ini:"collectors"` + Web webConfig `ini:"web"` + Collectors collectorsConfig `ini:"collectors"` + Collector collectorConfig `ini:"collector"` + Runtime runtimeConfig `ini:"runtime"` } type webConfig struct { - ListenAddress string `ini:"listen-address"` - MetricsPath string `ini:"telemetry-path"` - SSLCertFile string `ini:"ssl-cert-file"` - SSLKeyFile string `ini:"ssl-key-file"` - AuthFile *string `ini:"auth-file"` + ListenAddress []string `ini:"listen-address"` + TelemetryPath string `ini:"telemetry-path" help:"Path under which to expose metrics."` + SSLCertFile string `ini:"ssl-cert-file"` + SSLKeyFile string `ini:"ssl-key-file"` + AuthFile string `ini:"auth-file"` + ConfigFile string `ini:"config.file"` + DisableExporterMetrics bool `ini:"disable-exporter-metrics" help:"Exclude metrics about the exporter itself (promhttp_*, process_*, go_*)."` + MaxRequests int `ini:"max-requests" help:"Maximum number of parallel scrape requests. Use 0 to disable."` + SystemdSocket bool `ini:"systemd-socket"` } type collectorsConfig struct { @@ -308,102 +380,15 @@ type collectorsConfig struct { Print bool `ini:"print"` } -// lookupConfig lookup config from flag -// or config by name, returns nil if none exists. -// name should be in this format -> '[section].[key]' -func lookupConfig(name string, defaultValue interface{}) interface{} { - flagSet, flagValue := lookupFlag(name) - if flagSet { - return flagValue - } - - section := "" - key := name - if i := strings.Index(name, "."); i > 0 { - section = name[0:i] - if len(name) > i+1 { - key = name[i+1:] - } else { - key = "" - } - } - - t := reflect.TypeOf(*cfg) - for i := 0; i < t.NumField(); i++ { - field := t.Field(i) - iniName := field.Tag.Get("ini") - matched := iniName == section - if section == "" { - matched = iniName == key - } - if !matched { - continue - } - - v := reflect.ValueOf(cfg).Elem().Field(i) - if section == "" { - return v.Interface() - } - - if !v.CanAddr() { - continue - } - - st := reflect.TypeOf(v.Interface()) - for j := 0; j < st.NumField(); j++ { - sectionField := st.Field(j) - sectionININame := sectionField.Tag.Get("ini") - if sectionININame != key { - continue - } - - if reflect.ValueOf(v.Addr().Elem().Field(j).Interface()).Kind() != reflect.Ptr { - return v.Addr().Elem().Field(j).Interface() - } - - if v.Addr().Elem().Field(j).IsNil() { - return defaultValue - } - - return v.Addr().Elem().Field(j).Elem().Interface() - } - } - - return defaultValue +type collectorConfig struct { + DisableDefaults bool `ini:"disable-defaults"` } -func lookupFlag(name string) (flagSet bool, flagValue interface{}) { - flag.Visit(func(f *flag.Flag) { - if f.Name == name { - flagSet = true - switch reflect.Indirect(reflect.ValueOf(f.Value)).Kind() { - case reflect.Bool: - flagValue = reflect.Indirect(reflect.ValueOf(f.Value)).Bool() - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - flagValue = reflect.Indirect(reflect.ValueOf(f.Value)).Int() - case reflect.Float32, reflect.Float64: - flagValue = reflect.Indirect(reflect.ValueOf(f.Value)).Float() - case reflect.String: - flagValue = reflect.Indirect(reflect.ValueOf(f.Value)).String() - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - flagValue = reflect.Indirect(reflect.ValueOf(f.Value)).Uint() - } - } - }) - - return +type runtimeConfig struct { + GoMaxProcs int `ini:"gomaxprocs"` } -func configure() error { - iniCfg, err := ini.Load(*configPath) - if err != nil { - return err - } - - if err = iniCfg.MapTo(cfg); err != nil { - return err - } - +func configVisit(visitFn func(string, string, reflect.Value)) { type item struct { value reflect.Value section string @@ -432,27 +417,35 @@ func configure() error { continue } - flagSet, flagValue := lookupFlag(fmt.Sprintf("%s.%s", section, key)) - if !flagSet { - continue - } - - if fieldValue.IsValid() && fieldValue.CanSet() { - switch fieldValue.Kind() { - case reflect.Bool: - iniCfg.Section(section).Key(key).SetValue(fmt.Sprintf("%t", flagValue.(bool))) - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - iniCfg.Section(section).Key(key).SetValue(fmt.Sprintf("%d", flagValue.(int64))) - case reflect.Float32, reflect.Float64: - iniCfg.Section(section).Key(key).SetValue(fmt.Sprintf("%f", flagValue.(float64))) - case reflect.String: - iniCfg.Section(section).Key(key).SetValue(strconv.Quote(flagValue.(string))) - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - iniCfg.Section(section).Key(key).SetValue(fmt.Sprintf("%d", flagValue.(uint64))) - } - } + visitFn(section, key, fieldValue) } } +} + +func configure() error { + iniCfg, err := ini.Load(*configPath) + if err != nil { + return err + } + + if err = iniCfg.MapTo(cfg); err != nil { + return err + } + + configVisit(func(section, key string, fieldValue reflect.Value) { + flagKey := fmt.Sprintf("%s.%s", section, key) + if section == "" { + flagKey = key + } + + setByUser := setByUserMap[flagKey] + kingpinF := kingpin.CommandLine.GetFlag(flagKey) + if !setByUser || kingpinF == nil { + return + } + + iniCfg.Section(section).Key(key).SetValue(kingpinF.Model().Value.String()) + }) if err = iniCfg.SaveTo(*configPath); err != nil { return err @@ -460,3 +453,32 @@ func configure() error { return nil } + +func overrideFlags() { + configVisit(func(section, key string, fieldValue reflect.Value) { + flagKey := fmt.Sprintf("%s.%s", section, key) + if section == "" { + flagKey = key + } + + setByUser := setByUserMap[flagKey] + kingpinF := kingpin.CommandLine.GetFlag(flagKey) + if setByUser || kingpinF == nil { + return + } + if fieldValue.Kind() == reflect.Slice { + for i := 0; i < fieldValue.Len(); i++ { + fmt.Printf("key: %s, value: %s\n", flagKey, fieldValue.Index(i).String()) + kingpinF.Model().Value.Set(fieldValue.Index(i).String()) + } + } else { + fmt.Printf("key: %s, value: %s\n", flagKey, fieldValue.String()) + kingpinF.Model().Value.Set(fieldValue.String()) + } + }) +} + +type authConfig struct { + ServerUser string `yaml:"server_user,omitempty"` + ServerPassword string `yaml:"server_password,omitempty"` +} diff --git a/support-files/config/node_exporter.conf b/support-files/config/node_exporter.conf index 7fdd80f397..2ebe004cd6 100644 --- a/support-files/config/node_exporter.conf +++ b/support-files/config/node_exporter.conf @@ -5,9 +5,15 @@ listen-address = :42000 telemetry-path = /metrics # Path to YAML file with server_user, server_password options for http basic auth (overrides HTTP_AUTH env var) auth-file = /opt/ss/ssm-client/ssm.yml +# Maximum number of parallel scrape requests. Use 0 to disable. +max-requests = 40 [collectors] # Comma-separated list of collectors to use enabled = diskstats,filefd,filesystem,loadavg,meminfo,netdev,netstat,stat,time,uname,vmstat,meminfo_numa,textfile # If true, print available collectors and exit -print = 0 \ No newline at end of file +print = 0 + +[runtime] +# The target number of CPUs Go will run on (GOMAXPROCS) +gomaxprocs = 1 \ No newline at end of file diff --git a/vendor/github.com/go-kit/kit/LICENSE b/vendor/github.com/go-kit/kit/LICENSE deleted file mode 100644 index 45b80c8b11..0000000000 --- a/vendor/github.com/go-kit/kit/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2017 Yasuhiro Matsumoto - -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 -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -<<<<<<< HEAD:vendor/github.com/sirupsen/logrus/LICENSE -======= - ->>>>>>> switch to go-kit/log (#1575):vendor/github.com/go-kit/kit/LICENSE diff --git a/vendor/github.com/mdlayher/genetlink/LICENSE.md b/vendor/github.com/mdlayher/genetlink/LICENSE.md deleted file mode 100644 index 0018ed3e55..0000000000 --- a/vendor/github.com/mdlayher/genetlink/LICENSE.md +++ /dev/null @@ -1,10 +0,0 @@ -MIT License -=========== - -Copyright (C) 2016-2019 Matt Layher - -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 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s b/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s deleted file mode 100644 index 927a69c4be..0000000000 --- a/vendor/golang.org/x/sys/unix/asm_openbsd_arm.s +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !gccgo - -#include "textflag.h" - -// -// System call support for ARM, OpenBSD -// - -// Just jump to package syscall's implementation for all these functions. -// The runtime may know about them. - -TEXT ·Syscall(SB),NOSPLIT,$0-28 - B syscall·Syscall(SB) - -TEXT ·Syscall6(SB),NOSPLIT,$0-40 - B syscall·Syscall6(SB) - -TEXT ·SyscallNoError(SB),NOSPLIT,$0-24 - BL runtime·entersyscall(SB) - MOVW trap+0(FP), R7 - MOVW a1+4(FP), R0 - MOVW a2+8(FP), R1 - MOVW a3+12(FP), R2 - MOVW $0, R3 - MOVW $0, R4 - MOVW $0, R5 - SWI $0 - MOVW R0, r1+16(FP) - MOVW $0, R0 - MOVW R0, r2+20(FP) - BL runtime·exitsyscall(SB) - RET - -TEXT ·RawSyscall(SB),NOSPLIT,$0-28 - B syscall·RawSyscall(SB) - -TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 - B syscall·RawSyscall6(SB) - -TEXT ·RawSyscallNoError(SB),NOSPLIT,$0-24 - MOVW trap+0(FP), R7 // syscall entry - MOVW a1+4(FP), R0 - MOVW a2+8(FP), R1 - MOVW a3+12(FP), R2 - SWI $0 - MOVW R0, r1+16(FP) - MOVW $0, R0 - MOVW R0, r2+20(FP) - RET - -TEXT ·seek(SB),NOSPLIT,$0-28 - B syscall·seek(SB) diff --git a/vendor/golang.org/x/sys/unix/constants.go b/vendor/golang.org/x/sys/unix/constants.go deleted file mode 100644 index bd5262fcb6..0000000000 --- a/vendor/golang.org/x/sys/unix/constants.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris -// +build generate - -package registry - -package unix - -const ( - R_OK = 0x4 - W_OK = 0x2 - X_OK = 0x1 -) diff --git a/vendor/golang.org/x/sys/unix/syscall.go b/vendor/golang.org/x/sys/unix/syscall.go deleted file mode 100644 index 8593489dc2..0000000000 --- a/vendor/golang.org/x/sys/unix/syscall.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris -// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris - -// Package unix contains an interface to the low-level operating system -// primitives. OS details vary depending on the underlying system, and -// by default, godoc will display OS-specific documentation for the current -// system. If you want godoc to display OS documentation for another -// system, set $GOOS and $GOARCH to the desired system. For example, if -// you want to view documentation for freebsd/arm on linux/amd64, set $GOOS -// to freebsd and $GOARCH to arm. -// -// The primary use of this package is inside other packages that provide a more -// portable interface to the system, such as "os", "time" and "net". Use -// those packages rather than this one if you can. -// -// For details of the functions and data types in this package consult -// the manuals for the appropriate operating system. -// -// These calls return err == nil to indicate success; otherwise -// err represents an operating system error describing the failure and -// holds a value of type syscall.Errno. -package unix // import "golang.org/x/sys/unix" - -import "strings" - -// ByteSliceFromString returns a NUL-terminated slice of bytes -// containing the text of s. If s contains a NUL byte at any -// location, it returns (nil, EINVAL). -func ByteSliceFromString(s string) ([]byte, error) { - if strings.IndexByte(s, 0) != -1 { - return nil, EINVAL - } - a := make([]byte, len(s)+1) - copy(a, s) - return a, nil -} - -// BytePtrFromString returns a pointer to a NUL-terminated array of -// bytes containing the text of s. If s contains a NUL byte at any -// location, it returns (nil, EINVAL). -func BytePtrFromString(s string) (*byte, error) { - a, err := ByteSliceFromString(s) - if err != nil { - return nil, err - } - return &a[0], nil -} - -// Single-word zero for use when we need a valid pointer to 0 bytes. -var _zero uintptr