Commit c02894b7 authored by ale's avatar ale
Browse files

Allow regexp filtering of scanned cgroups

By default we'll only look at system.slice.
parent 8b0ad4eb
Pipeline #20612 passed with stages
in 48 seconds
......@@ -2,15 +2,47 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
"time"
)
var cgroupsRootPath string
var (
cgroupsUpdateInterval = flag.Duration("cgroups-update-interval", 60*time.Second, "update interval")
cgroupsFilterRx = regexpFlag{Regexp: regexp.MustCompile("^system.slice/")}
cgroupsRootPath string
)
func init() {
flag.Var(&cgroupsFilterRx, "cgroups-filter", "filter for cgroup paths")
}
type regexpFlag struct {
*regexp.Regexp
}
func (f *regexpFlag) Set(value string) error {
rx, err := regexp.Compile(value)
if err != nil {
return err
}
f.Regexp = rx
return nil
}
func (f *regexpFlag) String() string {
if f.Regexp == nil {
return "<nil>"
}
return fmt.Sprintf("\"%s\"", f.Regexp.String())
}
func findCGroups() ([]string, error) {
var paths []string
......@@ -23,10 +55,13 @@ func findCGroups() ([]string, error) {
return nil
}
relPath := path[len(cgroupsRootPath)+1:]
if !cgroupsFilterRx.MatchString(relPath) {
return nil
}
paths = append(paths, relPath)
return nil
})
debug("found %d units below %s", len(paths), cgroupsRootPath)
debug("found %d cgroups below %s", len(paths), cgroupsRootPath)
return paths, err
}
......@@ -59,7 +94,7 @@ func updateCGroupsList(ctx context.Context) {
updateFn()
go func() {
ticker := time.NewTicker(*updateInterval)
ticker := time.NewTicker(*cgroupsUpdateInterval)
defer ticker.Stop()
for {
select {
......
......@@ -17,9 +17,8 @@ import (
)
var (
addr = flag.String("addr", ":3909", "address to listen on")
updateInterval = flag.Duration("interval", 10*time.Second, "update interval")
doDebug = flag.Bool("debug", false, "log debug messages")
addr = flag.String("addr", ":3909", "address to listen on")
doDebug = flag.Bool("debug", false, "log debug messages")
)
const (
......
......@@ -65,6 +65,9 @@ func parseIOV2File(path string) (map[string]int64, error) {
}
defer f.Close()
// Sum I/O counters across devices, but only for mounted
// devices, so we do not count I/O operations twice with
// LVM/MD.
result := make(map[string]int64)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment