Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webserver): add Prometheus #189

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ var serveCmd = &cobra.Command{

if config.Webserver.Enable {
log.Infof("starting webserver on %s", config.Webserver.Bind)
srv := webserver.New(config.Webserver.Bind, config.Webserver.Webroot)
srv := webserver.New(config.Webserver, nodes)
go webserver.Start(srv)
defer srv.Close()
} else if prom := config.Webserver.Prometheus; prom != nil && prom.Enable {
log.Error("to enable prometheus exporter, please enable webserver ")
}

if config.Respondd.Enable {
Expand Down
10 changes: 10 additions & 0 deletions config_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ enable = false
bind = "127.0.0.1:8080"
webroot = "/var/www/html/meshviewer"

[webserver.prometheus]
# need webserver
enable = false
disable_labels = [
# "hostname",
# "owner",
# "location",
]



[nodes]
# Cache file
Expand Down
1 change: 1 addition & 0 deletions database/influxdb/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (conn *Connection) InsertLink(link *runtime.Link, t time.Time) {
tags.SetString("source.addr", link.SourceAddress)
tags.SetString("target.id", link.TargetID)
tags.SetString("target.addr", link.TargetAddress)
tags.SetString("type", link.Type.String())
if link.SourceHostname != "" {
tags.SetString("source.hostname", link.SourceHostname)
}
Expand Down
4 changes: 4 additions & 0 deletions database/influxdb/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestToInflux(t *testing.T) {
assert := assert.New(t)

node := &runtime.Node{
Online: true,
Statistics: &data.Statistics{
NodeID: "deadbeef",
LoadAverage: 0.5,
Expand Down Expand Up @@ -105,6 +106,7 @@ func TestToInflux(t *testing.T) {
}

neighbour := &runtime.Node{
Online: true,
Nodeinfo: &data.Nodeinfo{
NodeID: "foobar",
Network: data.Network{
Expand Down Expand Up @@ -132,6 +134,7 @@ func TestToInflux(t *testing.T) {

// do not add a empty statistics of a node
droppednode := &runtime.Node{
Online: true,
Nodeinfo: &data.Nodeinfo{
NodeID: "notfound",
Network: data.Network{
Expand Down Expand Up @@ -184,6 +187,7 @@ func TestToInflux(t *testing.T) {
"source.addr": "a-interface-mac",
"target.id": "foobar",
"target.addr": "BAFF1E5",
"type": "vpn",
}, tags)
assert.EqualValues(80, fields["tq"])

Expand Down
3 changes: 2 additions & 1 deletion database/influxdb2/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func (conn *Connection) InsertLink(link *runtime.Link, t time.Time) {
AddTag("source.id", link.SourceID).
AddTag("source.addr", link.SourceAddress).
AddTag("target.id", link.TargetID).
AddTag("target.addr", link.TargetAddress)
AddTag("target.addr", link.TargetAddress).
AddTag("type", link.Type.String())
if link.SourceHostname != "" {
p.AddTag("source.hostname", link.SourceHostname)
}
Expand Down
97 changes: 25 additions & 72 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,99 +1,52 @@
module github.com/FreifunkBremen/yanic

go 1.21
go 1.22

toolchain go1.22.3

require (
github.com/BurntSushi/toml v1.3.2
github.com/BurntSushi/toml v1.4.0
github.com/NYTimes/gziphandler v1.1.1
github.com/bdlm/log v0.1.20
github.com/bdlm/std v1.0.1
github.com/fgrosse/graphigo v0.0.0-20151222101953-5770fe631d9a
github.com/influxdata/influxdb-client-go/v2 v2.12.3
github.com/influxdata/influxdb-client-go/v2 v2.13.0
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c
github.com/paulmach/go.geojson v1.5.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.16.0
golang.org/x/sys v0.15.0
github.com/prometheus/client_golang v1.19.1
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.17.1
golang.org/x/sys v0.22.0
)

require (
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
github.com/CloudyKit/jet/v6 v6.2.0 // indirect
github.com/Joker/jade v1.1.3 // indirect
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/bytedance/sonic v1.10.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deepmap/oapi-codegen v1.15.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/flosch/pongo2/v4 v4.0.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.4 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gomarkdown/markdown v0.0.0-20230916125811-7478c230c7cd // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf // indirect
github.com/iris-contrib/schema v0.0.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kataras/blocks v0.0.7 // indirect
github.com/kataras/golog v0.1.9 // indirect
github.com/kataras/iris/v12 v12.2.6-0.20230908161203-24ba4e8933b9 // indirect
github.com/kataras/pio v0.0.12 // indirect
github.com/kataras/sitemap v0.0.6 // indirect
github.com/kataras/tunnel v0.0.4 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/labstack/echo/v4 v4.11.1 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/microcosm-cc/bluemonday v1.0.25 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.19.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tdewolff/minify/v2 v2.12.9 // indirect
github.com/tdewolff/parse/v2 v2.6.8 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yosssi/ace v0.0.5 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/term v0.22.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/fgrosse/graphigo.v2 v2.0.0-20151220153422-55a0a92a7030 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading