Skip to content

Commit

Permalink
added cli arguments, url and query
Browse files Browse the repository at this point in the history
  • Loading branch information
portertech committed Oct 2, 2017
1 parent 80adc09 commit 92fae3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Binary
sensu-prometheus-collector

# Binaries for programs and plugins
*.exe
*.dll
Expand Down
9 changes: 7 additions & 2 deletions sensu-prometheus-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"flag"
"fmt"
"time"

Expand Down Expand Up @@ -62,10 +63,14 @@ func CreateGraphiteMetrics(samples model.Vector) (string, error) {
}

func main() {
promURL := flag.String("url", "http://localhost:9090", "Prometheus API URL")
queryString := flag.String("query", "up", "Prometheus API query string")
flag.Parse()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

promConfig := prometheus.Config{Address: "http://localhost:9090"}
promConfig := prometheus.Config{Address: *promURL}
promClient, err := prometheus.New(promConfig)

if err != nil {
Expand All @@ -75,7 +80,7 @@ func main() {

promQueryClient := prometheus.NewQueryAPI(promClient)

promResponse, err := promQueryClient.Query(ctx, "go_gc_duration_seconds", time.Now())
promResponse, err := promQueryClient.Query(ctx, *queryString, time.Now())

if err != nil {
fmt.Errorf("%v", err)
Expand Down

0 comments on commit 92fae3e

Please sign in to comment.