Skip to content

Commit

Permalink
try getting default metric options to work
Browse files Browse the repository at this point in the history
  • Loading branch information
waisbrot committed Jan 1, 2024
1 parent 4c1c202 commit 49ea431
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
11 changes: 1 addition & 10 deletions cmd/hourlyMetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,12 @@ 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)
}
},
}

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")
}
17 changes: 13 additions & 4 deletions metrics/influx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"context"
"fmt"
"time"

influxdb "github.com/influxdata/influxdb-client-go/v2"
Expand All @@ -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,
}

Check failure on line 32 in metrics/influx.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 32 in metrics/influx.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected newline in composite literal; possibly missing comma or }
}

Check failure on line 33 in metrics/influx.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 33 in metrics/influx.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected newline in composite literal; possibly missing comma or }
})
writeAPI = influxClient.WriteAPIBlocking(viper.GetString("influx.org"), viper.GetString("influx.bucket"))

produceMetrics = true
}

Expand All @@ -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) {
Expand Down

0 comments on commit 49ea431

Please sign in to comment.