mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-11-04 02:35:07 +01:00 
			
		
		
		
	Collector-specific configuration. LIKWID collector derives metrics itself, Run once CLI option
This commit is contained in:
		@@ -7,27 +7,36 @@ import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const NETSTATFILE = `/proc/net/dev`
 | 
			
		||||
 | 
			
		||||
type NetstatCollector struct {
 | 
			
		||||
	MetricCollector
 | 
			
		||||
	matches map[int]string
 | 
			
		||||
	tags    map[string]string
 | 
			
		||||
type NetstatCollectorConfig struct {
 | 
			
		||||
    ExcludeDevices []string                 `json:"exclude_devices, omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *NetstatCollector) Init() error {
 | 
			
		||||
type NetstatCollector struct {
 | 
			
		||||
	MetricCollector
 | 
			
		||||
	config NetstatCollectorConfig
 | 
			
		||||
	matches map[int]string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *NetstatCollector) Init(config []byte) error {
 | 
			
		||||
	m.name = "NetstatCollector"
 | 
			
		||||
	m.setup()
 | 
			
		||||
	m.tags = map[string]string{"type": "node"}
 | 
			
		||||
	m.matches = map[int]string{
 | 
			
		||||
		1:  "bytes_in",
 | 
			
		||||
		9:  "bytes_out",
 | 
			
		||||
		2:  "pkts_in",
 | 
			
		||||
		10: "pkts_out",
 | 
			
		||||
	}
 | 
			
		||||
	_, err := ioutil.ReadFile(string(NETSTATFILE))
 | 
			
		||||
	err := json.Unmarshal(config, &m.config)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
	    log.Print(err.Error())
 | 
			
		||||
	    return err
 | 
			
		||||
	}
 | 
			
		||||
	_, err = ioutil.ReadFile(string(NETSTATFILE))
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		m.init = true
 | 
			
		||||
	}
 | 
			
		||||
@@ -48,13 +57,20 @@ func (m *NetstatCollector) Read(interval time.Duration, out *[]lp.MutableMetric)
 | 
			
		||||
		}
 | 
			
		||||
		f := strings.Fields(l)
 | 
			
		||||
		dev := f[0][0 : len(f[0])-1]
 | 
			
		||||
		if dev == "lo" {
 | 
			
		||||
		cont := false
 | 
			
		||||
		for _, d := range m.config.ExcludeDevices {
 | 
			
		||||
		    if d == dev {
 | 
			
		||||
		        cont = true
 | 
			
		||||
		    }
 | 
			
		||||
		}
 | 
			
		||||
		if cont {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		tags := map[string]string{"device" : dev, "type": "node"}
 | 
			
		||||
		for i, name := range m.matches {
 | 
			
		||||
			v, err := strconv.ParseInt(f[i], 10, 0)
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				y, err := lp.New(name, m.tags, map[string]interface{}{"value": int(float64(v) * 1.0e-3)}, time.Now())
 | 
			
		||||
				y, err := lp.New(name, tags, map[string]interface{}{"value": int(float64(v) * 1.0e-3)}, time.Now())
 | 
			
		||||
				if err == nil {
 | 
			
		||||
					*out = append(*out, y)
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user