mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-11-04 02:35:07 +01:00 
			
		
		
		
	CC topology module update (#76)
* Rename CPU to hardware thread, write some comments * Do renaming in other parts * Remove CpuList and SocketList function from metricCollector. Available in ccTopology
This commit is contained in:
		@@ -3,10 +3,6 @@ package collectors
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"log"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
 | 
			
		||||
@@ -72,58 +68,6 @@ func stringArrayContains(array []string, str string) (int, bool) {
 | 
			
		||||
	return -1, false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SocketList returns the list of physical sockets as read from /proc/cpuinfo
 | 
			
		||||
func SocketList() []int {
 | 
			
		||||
	buffer, err := ioutil.ReadFile("/proc/cpuinfo")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Print(err)
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	ll := strings.Split(string(buffer), "\n")
 | 
			
		||||
	var packs []int
 | 
			
		||||
	for _, line := range ll {
 | 
			
		||||
		if strings.HasPrefix(line, "physical id") {
 | 
			
		||||
			lv := strings.Fields(line)
 | 
			
		||||
			id, err := strconv.ParseInt(lv[3], 10, 32)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				log.Print(err)
 | 
			
		||||
				return packs
 | 
			
		||||
			}
 | 
			
		||||
			_, found := intArrayContains(packs, int(id))
 | 
			
		||||
			if !found {
 | 
			
		||||
				packs = append(packs, int(id))
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return packs
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CpuList returns the list of physical CPUs (in contrast to logical CPUs) as read from /proc/cpuinfo
 | 
			
		||||
func CpuList() []int {
 | 
			
		||||
	buffer, err := ioutil.ReadFile("/proc/cpuinfo")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Print(err)
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	ll := strings.Split(string(buffer), "\n")
 | 
			
		||||
	var cpulist []int
 | 
			
		||||
	for _, line := range ll {
 | 
			
		||||
		if strings.HasPrefix(line, "processor") {
 | 
			
		||||
			lv := strings.Fields(line)
 | 
			
		||||
			id, err := strconv.ParseInt(lv[2], 10, 32)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				log.Print(err)
 | 
			
		||||
				return cpulist
 | 
			
		||||
			}
 | 
			
		||||
			_, found := intArrayContains(cpulist, int(id))
 | 
			
		||||
			if !found {
 | 
			
		||||
				cpulist = append(cpulist, int(id))
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return cpulist
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RemoveFromStringList removes the string r from the array of strings s
 | 
			
		||||
// If r is not contained in the array an error is returned
 | 
			
		||||
func RemoveFromStringList(s []string, r string) ([]string, error) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user