mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-11-04 02:35:07 +01:00 
			
		
		
		
	Change storage format
This commit is contained in:
		@@ -2,6 +2,7 @@ package collectors
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	lp "github.com/influxdata/line-protocol"
 | 
			
		||||
	"log"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"strings"
 | 
			
		||||
@@ -12,15 +13,23 @@ const NUM_PROCS = 5
 | 
			
		||||
 | 
			
		||||
type TopProcsCollector struct {
 | 
			
		||||
	MetricCollector
 | 
			
		||||
	tags map[string]string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TopProcsCollector) Init() error {
 | 
			
		||||
	m.name = "TopProcsCollector"
 | 
			
		||||
	m.tags = map[string]string{"type": "node"}
 | 
			
		||||
	m.setup()
 | 
			
		||||
	command := exec.Command("ps", "-Ao", "comm", "--sort=-pcpu")
 | 
			
		||||
	command.Wait()
 | 
			
		||||
	_, err := command.Output()
 | 
			
		||||
	if err == nil {
 | 
			
		||||
	    m.init = true
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TopProcsCollector) Read(interval time.Duration) {
 | 
			
		||||
func (m *TopProcsCollector) Read(interval time.Duration, out *[]lp.MutableMetric) {
 | 
			
		||||
	command := exec.Command("ps", "-Ao", "comm", "--sort=-pcpu")
 | 
			
		||||
	command.Wait()
 | 
			
		||||
	stdout, err := command.Output()
 | 
			
		||||
@@ -31,10 +40,15 @@ func (m *TopProcsCollector) Read(interval time.Duration) {
 | 
			
		||||
 | 
			
		||||
	lines := strings.Split(string(stdout), "\n")
 | 
			
		||||
	for i := 1; i < NUM_PROCS+1; i++ {
 | 
			
		||||
		m.node[fmt.Sprintf("topproc%d", i)] = lines[i]
 | 
			
		||||
		name := fmt.Sprintf("topproc%d", i)
 | 
			
		||||
		y, err := lp.New(name, m.tags, map[string]interface{}{"value": string(lines[i])}, time.Now())
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			*out = append(*out, y)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *TopProcsCollector) Close() {
 | 
			
		||||
    m.init = false
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user