@ -1,4 +1,4 @@
// +build ganglia
// +build !nogmond
package collector
@ -24,7 +24,7 @@ const (
)
type gmondCollector struct {
M etrics map [ string ] * prometheus . GaugeVec
m etrics map [ string ] * prometheus . GaugeVec
config Config
}
@ -38,41 +38,12 @@ var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
func NewGmondCollector ( config Config ) ( Collector , error ) {
c := gmondCollector {
config : config ,
M etrics: map [ string ] * prometheus . GaugeVec { } ,
m etrics: map [ string ] * prometheus . GaugeVec { } ,
}
return & c , nil
}
func ( c * gmondCollector ) setMetric ( name , cluster string , metric ganglia . Metric ) {
if _ , ok := c . Metrics [ name ] ; ! ok {
var desc string
var title string
for _ , element := range metric . ExtraData . ExtraElements {
switch element . Name {
case "DESC" :
desc = element . Val
case "TITLE" :
title = element . Val
}
if title != "" && desc != "" {
break
}
}
glog . V ( 1 ) . Infof ( "Register %s: %s" , name , desc )
gv := prometheus . NewGaugeVec (
prometheus . GaugeOpts {
Namespace : gangliaMetricsPrefix ,
Name : name ,
Help : desc ,
} ,
[ ] string { "cluster" } ,
)
}
glog . V ( 1 ) . Infof ( "Set %s{cluster=%q}: %f" , name , cluster , metric . Value )
c . Metrics [ name ] . WithLabelValues ( cluster ) . Set ( metric . Value )
}
func ( c * gmondCollector ) Update ( ch chan <- prometheus . Metric ) ( err error ) {
conn , err := net . Dial ( gangliaProto , gangliaAddress )
glog . V ( 1 ) . Infof ( "gmondCollector Update" )
@ -100,12 +71,41 @@ func (c *gmondCollector) Update(ch chan<- prometheus.Metric) (err error) {
}
}
}
for _ , m := range c . M etrics {
for _ , m := range c . m etrics {
m . Collect ( ch )
}
return err
}
func ( c * gmondCollector ) setMetric ( name , cluster string , metric ganglia . Metric ) {
if _ , ok := c . metrics [ name ] ; ! ok {
var desc string
var title string
for _ , element := range metric . ExtraData . ExtraElements {
switch element . Name {
case "DESC" :
desc = element . Val
case "TITLE" :
title = element . Val
}
if title != "" && desc != "" {
break
}
}
glog . V ( 1 ) . Infof ( "Register %s: %s" , name , desc )
c . metrics [ name ] = prometheus . NewGaugeVec (
prometheus . GaugeOpts {
Namespace : gangliaMetricsPrefix ,
Name : name ,
Help : desc ,
} ,
[ ] string { "cluster" } ,
)
}
glog . V ( 1 ) . Infof ( "Set %s{cluster=%q}: %f" , name , cluster , metric . Value )
c . metrics [ name ] . WithLabelValues ( cluster ) . Set ( metric . Value )
}
func toUtf8 ( charset string , input io . Reader ) ( io . Reader , error ) {
return input , nil //FIXME
}