update logging (#5)
* removed Zap logging and switched to logrus * "deprecating" the prometheus.go file and fixed up logging stuff on a couple more files. * removed uber zap from glide * well that sure messed things up
This commit is contained in:
86
collector/prometheus.bak
Normal file
86
collector/prometheus.bak
Normal file
@@ -0,0 +1,86 @@
|
||||
package collector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
type PromMetrics struct {
|
||||
InterfaceMetrics map[string]*prometheus.CounterVec
|
||||
ResourceMetrics map[string]*prometheus.GaugeVec
|
||||
}
|
||||
|
||||
func (p *PromMetrics) makeLabels(name, address string) prometheus.Labels {
|
||||
labels := make(prometheus.Labels)
|
||||
labels["name"] = metricStringCleanup(name)
|
||||
labels["address"] = metricStringCleanup(address)
|
||||
return labels
|
||||
}
|
||||
|
||||
func (p *PromMetrics) makeInterfaceLabels(name, address, intf string) prometheus.Labels {
|
||||
l := p.makeLabels(name, address)
|
||||
l["interface"] = intf
|
||||
return l
|
||||
}
|
||||
|
||||
func (p *PromMetrics) SetupPrometheus() (http.Handler, error) {
|
||||
|
||||
p.InterfaceMetrics = make(map[string]*prometheus.CounterVec)
|
||||
p.ResourceMetrics = make(map[string]*prometheus.GaugeVec)
|
||||
|
||||
for _, v := range InterfaceProps {
|
||||
n := metricStringCleanup(v)
|
||||
c := prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: "interface",
|
||||
Name: n,
|
||||
Help: fmt.Sprintf("Interface %s counter", v),
|
||||
}, interfaceLabelNames)
|
||||
|
||||
if err := prometheus.Register(c); err != nil {
|
||||
//l.Errorw("error creating interface counter vector",
|
||||
// "property", v,
|
||||
// "error", err,
|
||||
//)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p.InterfaceMetrics[v] = c
|
||||
|
||||
}
|
||||
|
||||
for _, v := range ResourceProps {
|
||||
n := metricStringCleanup(v)
|
||||
c := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: "resource",
|
||||
Name: n,
|
||||
Help: fmt.Sprintf("Resource %s counter", v),
|
||||
}, resourceLabelNames)
|
||||
|
||||
if err := prometheus.Register(c); err != nil {
|
||||
//l.Errorw("error creating resource counter vec",
|
||||
// "property", v,
|
||||
// "error", err,
|
||||
//)
|
||||
return nil, err
|
||||
}
|
||||
p.ResourceMetrics[v] = c
|
||||
}
|
||||
|
||||
return promhttp.Handler(), nil
|
||||
|
||||
}
|
||||
|
||||
func (p *PromMetrics) IncrementInterface(prop, name, address, intf string, cnt float64) {
|
||||
l := p.makeInterfaceLabels(name, address, intf)
|
||||
p.InterfaceMetrics[prop].With(l).Add(cnt)
|
||||
}
|
||||
|
||||
func (p *PromMetrics) UpdateResource(res, name, address string, v float64) {
|
||||
l := p.makeLabels(name, address)
|
||||
p.ResourceMetrics[res].With(l).Set(v)
|
||||
}
|
||||
Reference in New Issue
Block a user