Skip to content

Commit

Permalink
fixed issue of parse custom label.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunlzheng committed May 10, 2017
1 parent 5ae9d8f commit 20a78f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
30 changes: 11 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ func init() {
flag.StringVar(
&cfg.customLabelValues, "config.customLabelValues", "", "custom mertics label values",
)

if cfg.customLabels=="" {
labels = []string{}
values = []string{}
} else {
labels = strings.Split(cfg.customLabels, ",")
values = strings.Split(cfg.customLabelValues, ",")
}



}

func main() {
Expand All @@ -51,22 +40,25 @@ func main() {

var (
sampleAppender = storage.Fanout{}
)

var (
targetManager = retrieval.NewTargetManager(sampleAppender)
)

var (
jobTargets = scrape.NewJobTargets(targetManager)
)

fmt.Println("Loading prometheus config file: " + cfg.configFile)
fmt.Println("Custom labels: " + cfg.customLabels + "\t Custom label values: " + cfg.customLabelValues)

if cfg.customLabels == "" {
labels = []string{}
values = []string{}
} else {
labels = strings.Split(cfg.customLabels, ",")
values = strings.Split(cfg.customLabelValues, ",")
}

var (
scrapeManager = scrape.NewExporterScrape(jobTargets, labels, values)
)

fmt.Println("Loading prometheus config file: " + cfg.configFile)
fmt.Println("Custom labels: " + cfg.customLabels + "\t Custom label values: " + cfg.customLabelValues)
conf, err := config.LoadFile(cfg.configFile)
if err != nil {
fmt.Println(err.Error())
Expand Down
1 change: 0 additions & 1 deletion scrape/exporterscrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func (endpoint *jobEndpoint) scrape(jobName string, labels []string, values []st
var buffer bytes.Buffer

for _, sample := range allSamples {
// Add Custom Metrics, This will overwrite the metrics label value
for i, customLabel := range labels {
sample.Metric[model.LabelName(customLabel)] = model.LabelValue(values[i])
}
Expand Down

0 comments on commit 20a78f3

Please sign in to comment.