Skip to content

Commit

Permalink
Merge pull request #84 from prometheus-community/superq/toolkit
Browse files Browse the repository at this point in the history
Update exporter-toolkit
  • Loading branch information
SuperQ authored May 15, 2023
2 parents b79ef20 + bb53345 commit edbdeb7
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 756 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
version: 2.1

orbs:
prometheus: prometheus/prometheus@0.16.0
prometheus: prometheus/prometheus@0.17.1

executors:
# Whenever the Go version is updated here, .promu.yml should
# also be updated.
golang:
docker:
- image: cimg/go:1.18
- image: cimg/go:1.20

jobs:
test:
Expand All @@ -23,7 +23,7 @@ jobs:

codespell:
docker:
- image: cimg/python:3.10
- image: cimg/python:3.11

steps:
- checkout
Expand All @@ -32,7 +32,7 @@ jobs:

build:
machine:
image: ubuntu-2004:current
image: ubuntu-2204:current

environment:
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.18-base
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- name: install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.18.x
go-version: 1.20.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@v3.2.0
uses: golangci/golangci-lint-action@v3.4.0
with:
version: v1.45.2
version: v1.51.2
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, .travis.yml and
# .circle/config.yml should also be updated.
version: 1.18
version: 1.20
repository:
path: github.com/prometheus-community/systemd_exporter
build:
Expand Down
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
module github.com/prometheus-community/systemd_exporter

go 1.17
go 1.19

require (
github.com/alecthomas/kingpin/v2 v2.3.2
github.com/coreos/go-systemd/v22 v22.5.0
github.com/go-kit/log v0.2.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.37.0
github.com/prometheus/exporter-toolkit v0.8.2
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10
gopkg.in/alecthomas/kingpin.v2 v2.2.6
github.com/prometheus/common v0.42.0
github.com/prometheus/exporter-toolkit v0.10.0
golang.org/x/sys v0.7.0
)

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
748 changes: 31 additions & 717 deletions go.sum

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
_ "net/http/pprof"
"os"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log/level"
"github.com/prometheus-community/systemd_exporter/systemd"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
"gopkg.in/alecthomas/kingpin.v2"
)

func main() {
Expand Down Expand Up @@ -88,18 +88,25 @@ func main() {
}

http.Handle(*metricsPath, handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(`<html>
<head><title>Systemd Exporter</title></head>
<body>
<h1>Systemd Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
if *metricsPath != "/" && *metricsPath != "" {
landingConfig := web.LandingConfig{
Name: "systemd Exporter",
Description: "Prometheus Exporter for systemd",
Version: version.Info(),
Links: []web.LandingLinks{
{
Address: *metricsPath,
Text: "Metrics",
},
},
}
landingPage, err := web.NewLandingPage(landingConfig)
if err != nil {
level.Error(logger).Log("msg", "Couldn't write response", "err", err)
level.Error(logger).Log("err", err)
os.Exit(1)
}
})
http.Handle("/", landingPage)
}

srv := &http.Server{}
if err := web.ListenAndServe(srv, toolkitFlags, logger); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions systemd/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"bufio"
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -196,8 +195,8 @@ func (c *CPUAcct) UsageAllNanosecs() uint64 {
return nanoseconds
}

// ReadFileNoStat uses ioutil.ReadAll to read contents of entire file.
// This is similar to ioutil.ReadFile but without the call to os.Stat, because
// ReadFileNoStat uses io.ReadAll to read contents of entire file.
// This is similar to os.ReadFile but without the call to os.Stat, because
// many files in /proc and /sys report incorrect file sizes (either 0 or 4096).
// Reads a max file size of 512kB. For files larger than this, a scanner
// should be used.
Expand All @@ -212,7 +211,7 @@ func ReadFileNoStat(filename string) ([]byte, error) {
defer f.Close()

reader := io.LimitReader(f, maxBufferSize)
return ioutil.ReadAll(reader)
return io.ReadAll(reader)
}

// NewCPUAcct will locate and read the kernel's cpu accounting info for
Expand Down
4 changes: 2 additions & 2 deletions systemd/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
"sync"
"time"

kingpin "github.com/alecthomas/kingpin/v2"
"github.com/coreos/go-systemd/v22/dbus"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

const namespace = "systemd"
Expand Down Expand Up @@ -159,7 +159,7 @@ func NewCollector(logger log.Logger) (*Collector, error) {
"Total number of refused socket connections", []string{"name"}, nil)

// We could add a cpu label, but IMO that could cause a cardinality explosion. We already export
// two modes per unit (user/system), and on a modest 4 core machine adding a cpu label would cause us to export 8 metics
// two modes per unit (user/system), and on a modest 4 core machine adding a cpu label would cause us to export 8 metrics
// e.g. (2 modes * 4 cores) per enabled unit
unitCPUTotal := prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "unit_cpu_seconds_total"),
Expand Down

0 comments on commit edbdeb7

Please sign in to comment.