From 49ea431902b0c8cc82e6b8bc7a8c78b9f20a434c Mon Sep 17 00:00:00 2001 From: Nathaniel Waisbrot Date: Mon, 1 Jan 2024 09:18:58 -0500 Subject: [PATCH] try getting default metric options to work --- cmd/hourlyMetrics.go | 11 +---------- metrics/influx.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/hourlyMetrics.go b/cmd/hourlyMetrics.go index 59e3bad..f9ea88b 100644 --- a/cmd/hourlyMetrics.go +++ b/cmd/hourlyMetrics.go @@ -19,6 +19,7 @@ var hourlyMetricsCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { stationIds := viper.GetIntSlice("stations") for _, stationId := range stationIds { + fmt.Printf("Recording counts for station %d\n", stationId) birdweather.RecordCountsForStationPastMinutes(fmt.Sprint(stationId), 30) } }, @@ -26,14 +27,4 @@ var hourlyMetricsCmd = &cobra.Command{ func init() { rootCmd.AddCommand(hourlyMetricsCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // hourlyMetricsCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // hourlyMetricsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/metrics/influx.go b/metrics/influx.go index dc77836..1b86941 100644 --- a/metrics/influx.go +++ b/metrics/influx.go @@ -2,6 +2,7 @@ package metrics import ( "context" + "fmt" "time" influxdb "github.com/influxdata/influxdb-client-go/v2" @@ -21,11 +22,18 @@ func initInflux(args []string) { } else { command = "" } - influxdb.DefaultOptions(). - AddDefaultTag("application", "birdweather_digest"). - AddDefaultTag("command", command) - influxClient = influxdb.NewClient(viper.GetString("influx.url"), viper.GetString("influx.token")) + influxClient = influxdb.NewClientWithOptions( + viper.GetString("influx.url"), + viper.GetString("influx.token"), + &influxdb.Options{ + writeOptions: &write.Options{ + defaultTags: map[string]string{ + "command": command, + } + } + }) writeAPI = influxClient.WriteAPIBlocking(viper.GetString("influx.org"), viper.GetString("influx.bucket")) + produceMetrics = true } @@ -43,6 +51,7 @@ func writePoint(p *write.Point) { if err != nil { panic(err) } + fmt.Printf("Wrote data-point %#v\n", p) } func recordInfluxFetch(station string, speciesCount int) {