mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-11-04 10:45:06 +01:00 
			
		
		
		
	Fix: Add missing hostname tag
This commit is contained in:
		@@ -3,6 +3,7 @@ package metricRouter
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -29,6 +30,7 @@ type metricRouterConfig struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Metric router data structure
 | 
					// Metric router data structure
 | 
				
			||||||
type metricRouter struct {
 | 
					type metricRouter struct {
 | 
				
			||||||
 | 
						hostname   string              // Hostname used in tags
 | 
				
			||||||
	coll_input chan lp.CCMetric    // Input channel from CollectorManager
 | 
						coll_input chan lp.CCMetric    // Input channel from CollectorManager
 | 
				
			||||||
	recv_input chan lp.CCMetric    // Input channel from ReceiveManager
 | 
						recv_input chan lp.CCMetric    // Input channel from ReceiveManager
 | 
				
			||||||
	outputs    []chan lp.CCMetric  // List of all output channels
 | 
						outputs    []chan lp.CCMetric  // List of all output channels
 | 
				
			||||||
@@ -62,6 +64,15 @@ func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, rout
 | 
				
			|||||||
	r.wg = wg
 | 
						r.wg = wg
 | 
				
			||||||
	r.ticker = ticker
 | 
						r.ticker = ticker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Set hostname
 | 
				
			||||||
 | 
						hostname, err := os.Hostname()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							cclog.Error(err.Error())
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// Drop domain part of host name
 | 
				
			||||||
 | 
						r.hostname = strings.SplitN(hostname, `.`, 2)[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Read metric router config file
 | 
						// Read metric router config file
 | 
				
			||||||
	configFile, err := os.Open(routerConfigFile)
 | 
						configFile, err := os.Open(routerConfigFile)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -209,6 +220,7 @@ func (r *metricRouter) Start() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			case p := <-r.coll_input:
 | 
								case p := <-r.coll_input:
 | 
				
			||||||
				// receive from metric collector
 | 
									// receive from metric collector
 | 
				
			||||||
 | 
									p.AddTag("hostname", r.hostname)
 | 
				
			||||||
				if r.config.IntervalStamp {
 | 
									if r.config.IntervalStamp {
 | 
				
			||||||
					p.SetTime(r.timestamp)
 | 
										p.SetTime(r.timestamp)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,6 @@ import (
 | 
				
			|||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/signal"
 | 
						"os/signal"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
	"syscall"
 | 
						"syscall"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/ClusterCockpit/cc-metric-collector/collectors"
 | 
						"github.com/ClusterCockpit/cc-metric-collector/collectors"
 | 
				
			||||||
@@ -45,7 +44,6 @@ func LoadCentralConfiguration(file string, config *CentralConfigFile) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type RuntimeConfig struct {
 | 
					type RuntimeConfig struct {
 | 
				
			||||||
	Hostname   string
 | 
					 | 
				
			||||||
	Interval   time.Duration
 | 
						Interval   time.Duration
 | 
				
			||||||
	Duration   time.Duration
 | 
						Duration   time.Duration
 | 
				
			||||||
	CliArgs    map[string]string
 | 
						CliArgs    map[string]string
 | 
				
			||||||
@@ -213,13 +211,6 @@ func mainFunc() int {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	rcfg.Duration = time.Duration(rcfg.ConfigFile.Duration) * time.Second
 | 
						rcfg.Duration = time.Duration(rcfg.ConfigFile.Duration) * time.Second
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rcfg.Hostname, err = os.Hostname()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		cclog.Error(err.Error())
 | 
					 | 
				
			||||||
		return 1
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// Drop domain part of host name
 | 
					 | 
				
			||||||
	rcfg.Hostname = strings.SplitN(rcfg.Hostname, `.`, 2)[0]
 | 
					 | 
				
			||||||
	//	err = CreatePidfile(rcfg.CliArgs["pidfile"])
 | 
						//	err = CreatePidfile(rcfg.CliArgs["pidfile"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set log file
 | 
						// Set log file
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user