Skip to content

Commit

Permalink
feat: switch to command line flags for files
Browse files Browse the repository at this point in the history
  • Loading branch information
egvimo committed Sep 12, 2023
1 parent 930baa4 commit ed53080
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"
Expand All @@ -11,8 +11,15 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

type config struct {
Files []string
type arrayFlag []string

func (i *arrayFlag) String() string {
return fmt.Sprintf("%v", *i)
}

func (i *arrayFlag) Set(value string) error {
*i = append(*i, value)
return nil
}

type fileMetric struct {
Expand Down Expand Up @@ -61,29 +68,20 @@ func (collector *fileCollector) Collect(ch chan<- prometheus.Metric) {
}

func main() {
var (
conf = flag.String("config", "/etc/exporter/config.json", "Path to the config.")
addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
)
var files arrayFlag
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
flag.Var(&files, "file", "File to export metric for.")

flag.Parse()

configBytes, err := os.ReadFile(*conf)
if err != nil {
log.Fatal(err)
return
}

var config config
err = json.Unmarshal(configBytes, &config)
if err != nil {
log.Fatal(err)
if len(files) == 0 {
log.Fatal("No files provided")
return
}

log.Printf("Initializing exporter for files: %v", config.Files)
log.Printf("Initializing exporter for files: %v", files)

fileCollector := newFileCollector(config.Files)
fileCollector := newFileCollector(files)

reg := prometheus.NewRegistry()
reg.MustRegister(fileCollector)
Expand Down

0 comments on commit ed53080

Please sign in to comment.