Skip to content

Commit

Permalink
Merge pull request #28 from dgl/prom-endpoint
Browse files Browse the repository at this point in the history
Add Prometheus monitoring endpoint
  • Loading branch information
alban authored Apr 26, 2023
2 parents 5a6a549 + 0b9eccc commit 7a1914b
Show file tree
Hide file tree
Showing 424 changed files with 50,820 additions and 4,807 deletions.
21 changes: 21 additions & 0 deletions cmd/seccompagent/seccompagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"flag"
"fmt"
"net/http"
"os"
"strings"
"text/template"
Expand All @@ -28,11 +29,14 @@ import (
"github.com/kinvolk/seccompagent/pkg/agent"
"github.com/kinvolk/seccompagent/pkg/handlers"
"github.com/kinvolk/seccompagent/pkg/handlers/falco"
prometheus_handler "github.com/kinvolk/seccompagent/pkg/handlers/prometheus"
"github.com/kinvolk/seccompagent/pkg/kuberesolver"
"github.com/kinvolk/seccompagent/pkg/nsenter"
"github.com/kinvolk/seccompagent/pkg/registry"

"github.com/opencontainers/runtime-spec/specs-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
Expand All @@ -41,12 +45,14 @@ var (
socketFile string
resolverParam string
logflags string
metricsBindAddress string
)

func init() {
flag.StringVar(&socketFile, "socketfile", "/run/seccomp-agent.socket", "Socket file")
flag.StringVar(&resolverParam, "resolver", "", "Container resolver to use [none, demo-basic, kubernetes]")
flag.StringVar(&logflags, "log", "info", "log level [trace,debug,info,warn,error,fatal,color,nocolor,json]")
flag.StringVar(&metricsBindAddress, "metrics-bind-address", "", "[host]:port to listen on for monitoring, empty means no monitoring port")
}

func main() {
Expand All @@ -73,6 +79,19 @@ func main() {
panic(errors.New("invalid command"))
}

if metricsBindAddress != "" {
reg := prometheus.DefaultRegisterer
reg.MustRegister(prometheus.NewBuildInfoCollector())
http.Handle("/metrics", promhttp.Handler())

go func() {
err := http.ListenAndServe(metricsBindAddress, nil)
if err != nil {
log.Fatal(err)
}
}()
}

var resolver registry.ResolverFunc

switch resolverParam {
Expand Down Expand Up @@ -123,6 +142,8 @@ func main() {
switch middleware {
case "falco":
r.MiddlewareHandlers = append(r.MiddlewareHandlers, falco.NotifyFalco(podCtx))
case "prometheus":
r.MiddlewareHandlers = append(r.MiddlewareHandlers, prometheus_handler.UpdateMetrics(podCtx))
default:
log.WithFields(log.Fields{
"pod": podCtx,
Expand Down
21 changes: 14 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ require (
github.com/inspektor-gadget/inspektor-gadget v0.12.1
github.com/opencontainers/runc v1.1.0
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/prometheus/client_golang v1.15.0
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921
github.com/sirupsen/logrus v1.8.1
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec
golang.org/x/sys v0.6.0
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
google.golang.org/protobuf v1.30.0
k8s.io/api v0.25.4
k8s.io/apimachinery v0.25.4
k8s.io/client-go v0.25.4
Expand All @@ -20,6 +21,8 @@ require (
require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cilium/ebpf v0.9.1 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
Expand All @@ -31,20 +34,24 @@ require (
github.com/go-openapi/swag v0.19.14 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/moby/sys/mountinfo v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
Expand Down
Loading

0 comments on commit 7a1914b

Please sign in to comment.