mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-25 23:19:06 +01:00
Add StatsApi. Started if a configuration file is set in global config.json
This commit is contained in:
parent
28348bd108
commit
9447685a69
@ -28,6 +28,7 @@ type CentralConfigFile struct {
|
||||
RouterConfigFile string `json:"router"`
|
||||
SinkConfigFile string `json:"sinks"`
|
||||
ReceiverConfigFile string `json:"receivers,omitempty"`
|
||||
StatsApiConfigFile string `json:"stats_api,omitempty"`
|
||||
}
|
||||
|
||||
func LoadCentralConfiguration(file string, config *CentralConfigFile) error {
|
||||
@ -52,6 +53,7 @@ type RuntimeConfig struct {
|
||||
CollectManager collectors.CollectorManager
|
||||
SinkManager sinks.SinkManager
|
||||
ReceiveManager receivers.ReceiveManager
|
||||
StatsApi mr.StatsApi
|
||||
MultiChanTicker mct.MultiChanTicker
|
||||
|
||||
Channels []chan lp.CCMetric
|
||||
@ -152,11 +154,16 @@ func shutdownHandler(config *RuntimeConfig, shutdownSignal chan os.Signal) {
|
||||
cclog.Debug("Shutdown SinkManager...")
|
||||
config.SinkManager.Close()
|
||||
}
|
||||
if config.StatsApi != nil {
|
||||
cclog.Debug("Shutdown StatsApi...")
|
||||
config.StatsApi.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func mainFunc() int {
|
||||
var err error
|
||||
use_recv := false
|
||||
use_api := false
|
||||
|
||||
// Initialize runtime configuration
|
||||
rcfg := RuntimeConfig{
|
||||
@ -164,6 +171,7 @@ func mainFunc() int {
|
||||
CollectManager: nil,
|
||||
SinkManager: nil,
|
||||
ReceiveManager: nil,
|
||||
StatsApi: nil,
|
||||
CliArgs: ReadCli(),
|
||||
}
|
||||
|
||||
@ -253,6 +261,16 @@ func mainFunc() int {
|
||||
use_recv = true
|
||||
}
|
||||
|
||||
// Create new statistics API manager
|
||||
if len(rcfg.ConfigFile.StatsApiConfigFile) > 0 {
|
||||
rcfg.StatsApi, err = mr.NewStatsApi(rcfg.MultiChanTicker, &rcfg.Sync, rcfg.ConfigFile.StatsApiConfigFile)
|
||||
if err != nil {
|
||||
cclog.Error(err.Error())
|
||||
return 1
|
||||
}
|
||||
use_api = true
|
||||
}
|
||||
|
||||
// Create shutdown handler
|
||||
shutdownSignal := make(chan os.Signal, 1)
|
||||
signal.Notify(shutdownSignal, os.Interrupt)
|
||||
@ -260,6 +278,11 @@ func mainFunc() int {
|
||||
rcfg.Sync.Add(1)
|
||||
go shutdownHandler(&rcfg, shutdownSignal)
|
||||
|
||||
// Start the stats api early to be prepared for init settings
|
||||
if use_api {
|
||||
rcfg.StatsApi.Start()
|
||||
}
|
||||
|
||||
// Start the managers
|
||||
rcfg.MetricRouter.Start()
|
||||
rcfg.SinkManager.Start()
|
||||
|
17
internal/metricRouter/StatsApi.md
Normal file
17
internal/metricRouter/StatsApi.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Stats API
|
||||
|
||||
The Stats API can be used for debugging. It publishes counts at an HTTP endpoint as JSON from different componenets of the CC Metric Collector.
|
||||
|
||||
# Configuration
|
||||
|
||||
The Stats API has an own configuration file to specify the listen host and port. The defaults are `localhost` and `8080`.
|
||||
|
||||
```json
|
||||
{
|
||||
"bindhost" : "",
|
||||
"port" : "8080",
|
||||
"publish_collectorstate" : true
|
||||
}
|
||||
```
|
||||
|
||||
The `bindhost` and `port` can be used to specify the listen host and port. The `publish_collectorstate` needs to be `true`, otherwise nothing is presented. This option is for future use if we need to publish more infos using different domains.
|
@ -54,6 +54,12 @@ type metricRouter struct {
|
||||
cache MetricCache // pointer to MetricCache
|
||||
cachewg sync.WaitGroup // wait group for MetricCache
|
||||
maxForward int // number of metrics to forward maximally in one iteration
|
||||
statsCollForward int64
|
||||
statsRecvForward int64
|
||||
statsCacheForward int64
|
||||
statsTotalForward int64
|
||||
statsDropped int64
|
||||
statsRenamed int64
|
||||
}
|
||||
|
||||
// MetricRouter access functions
|
||||
@ -121,6 +127,12 @@ func (r *metricRouter) Init(ticker mct.MultiChanTicker, wg *sync.WaitGroup, rout
|
||||
for _, mname := range r.config.DropMetrics {
|
||||
r.config.dropMetrics[mname] = true
|
||||
}
|
||||
r.statsCollForward = 0
|
||||
r.statsRecvForward = 0
|
||||
r.statsCacheForward = 0
|
||||
r.statsTotalForward = 0
|
||||
r.statsDropped = 0
|
||||
r.statsRenamed = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -140,6 +152,7 @@ func (r *metricRouter) StartTimer() {
|
||||
cclog.ComponentDebug("MetricRouter", "TIMER DONE")
|
||||
return
|
||||
case t := <-m:
|
||||
cclog.ComponentDebug("MetricRouter", "INTERVAL_TICK", t.Unix())
|
||||
r.timestamp = t
|
||||
}
|
||||
}
|
||||
@ -253,6 +266,8 @@ func (r *metricRouter) Start() {
|
||||
r.DoDelTags(point)
|
||||
name := point.Name()
|
||||
if new, ok := r.config.RenameMetrics[name]; ok {
|
||||
r.statsRenamed++
|
||||
ComponentStatInt("MetricRouter", "renamed", r.statsRenamed)
|
||||
point.SetName(new)
|
||||
point.AddMeta("oldname", name)
|
||||
}
|
||||
@ -272,7 +287,14 @@ func (r *metricRouter) Start() {
|
||||
p.SetTime(r.timestamp)
|
||||
}
|
||||
if !r.dropMetric(p) {
|
||||
r.statsCollForward++
|
||||
r.statsTotalForward++
|
||||
ComponentStatInt("MetricRouter", "collector_forward", r.statsCollForward)
|
||||
ComponentStatInt("MetricRouter", "total_forward", r.statsTotalForward)
|
||||
forward(p)
|
||||
} else {
|
||||
r.statsDropped++
|
||||
ComponentStatInt("MetricRouter", "dropped", r.statsDropped)
|
||||
}
|
||||
// even if the metric is dropped, it is stored in the cache for
|
||||
// aggregations
|
||||
@ -288,7 +310,14 @@ func (r *metricRouter) Start() {
|
||||
p.SetTime(r.timestamp)
|
||||
}
|
||||
if !r.dropMetric(p) {
|
||||
r.statsRecvForward++
|
||||
r.statsTotalForward++
|
||||
ComponentStatInt("MetricRouter", "receiver_forward", r.statsRecvForward)
|
||||
ComponentStatInt("MetricRouter", "total_forward", r.statsTotalForward)
|
||||
forward(p)
|
||||
} else {
|
||||
r.statsDropped++
|
||||
ComponentStatInt("MetricRouter", "dropped", r.statsDropped)
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,7 +326,14 @@ func (r *metricRouter) Start() {
|
||||
// receive from metric collector
|
||||
if !r.dropMetric(p) {
|
||||
p.AddTag(r.config.HostnameTagName, r.hostname)
|
||||
r.statsCacheForward++
|
||||
r.statsTotalForward++
|
||||
ComponentStatInt("MetricRouter", "cache_forward", r.statsCacheForward)
|
||||
ComponentStatInt("MetricRouter", "total_forward", r.statsTotalForward)
|
||||
forward(p)
|
||||
} else {
|
||||
r.statsDropped++
|
||||
ComponentStatInt("MetricRouter", "dropped", r.statsDropped)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user