-
Notifications
You must be signed in to change notification settings - Fork 6
/
metamonitoring.go
53 lines (46 loc) · 1.23 KB
/
metamonitoring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// May 2016, cisco
//
// Copyright (c) 2016 by cisco Systems, Inc.
// All rights reserved.
//
//
package main
//
// Monitoring the pipeline. The intention is to provide services to the rest of
// pipeline bits to keep stats for the various components. We start out with
// the aim of having stats scraped by prometheus.
//
import (
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
"net/http"
)
var pipelineMetaMonitoringStarted bool
func metamonitoring_init(nc nodeConfig) {
//
// Set up server to serve metrics to prometheus
if pipelineMetaMonitoringStarted {
return
}
pipelineMetaMonitoringStarted = true
path, err := nc.config.GetString("default",
"metamonitoring_prometheus_resource")
if err != nil {
logger.Info("Metamonitoring: not enabled")
return
}
server, err := nc.config.GetString("default",
"metamonitoring_prometheus_server")
if err != nil {
server = ":8080"
}
logger.WithFields(log.Fields{
"resource": path,
"name": "default",
"server": server}).Info(
"Metamonitoring: serving pipeline metrics to prometheus")
http.Handle(path, prometheus.Handler())
err = http.ListenAndServe(server, nil)
logger.WithError(err).Error("Metamonitoring: stop serving metrics")
}