update influxdb URL

This commit is contained in:
Paul 2019-09-08 12:35:55 +02:00
commit abedcc98d8
4 changed files with 27 additions and 15 deletions

View File

@ -1,16 +1,25 @@
# fuelprices # fuelprices
## Summary
<<<<<<< HEAD
## Summary ## Summary
weather is a small program that fetch weather informations, and store them to influxdb weather is a small program that fetch weather informations, and store them to influxdb
## Usage ## Usage
=======
fuelprices is a small tool designed to fetch fuel prices from France open data and send them to influxdb
## Howto
### Build
>>>>>>> 329f1c7752d61b932e179be3884a1824a1393d6c
```shell ```shell
fuelprices -configfile fuelprices.ini go build
``` ```
## Sample config ### Sample config in fuelprices.ini
```ini ```ini
[fuelprices] [fuelprices]
@ -24,14 +33,19 @@ pos=50000007
types=Gazole,SP95,SP98 types=Gazole,SP95,SP98
[influxdb] [influxdb]
# Influxdb settings # InfluxDB settings
hostname=influxdb url=http://influxdb:8086/
port=8086
username=influxdb username=influxdb
password=password password=password
database=database database=database
``` ```
### Run
```shell
./fuelprices -configfile fuelprices.ini
```
## License ## License
```text ```text

View File

@ -12,8 +12,7 @@ table=fuel_price
[influxdb] [influxdb]
# Influxdb settings # Influxdb settings
hostname=host url=http://influxdb:8086/
database=me
port=8086
username=influx username=influx
password=password password=password
database=me

View File

@ -48,8 +48,7 @@ func (fpc *FuelPricesConfig) GetConfig() error {
} }
influxdbSection := config.Section("influxdb") influxdbSection := config.Section("influxdb")
fpc.InfluxHost = influxdbSection.Key("hostname").MustString("localhost") fpc.InfluxURL = influxdbSection.Key("url").MustString("http://localhost:8086")
fpc.InfluxPort = influxdbSection.Key("port").MustInt(8086)
fpc.InfluxUser = influxdbSection.Key("username").MustString("username") fpc.InfluxUser = influxdbSection.Key("username").MustString("username")
fpc.InfluxPass = influxdbSection.Key("password").MustString("password") fpc.InfluxPass = influxdbSection.Key("password").MustString("password")
fpc.InfluxDB = influxdbSection.Key("database").MustString("me") fpc.InfluxDB = influxdbSection.Key("database").MustString("me")
@ -74,7 +73,6 @@ func DownloadFile(fpc *FuelPricesConfig, zipfile *ZipFile) error {
if err != nil { if err != nil {
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
zipfile.Content, err = ioutil.ReadAll(resp.Body) zipfile.Content, err = ioutil.ReadAll(resp.Body)
@ -145,7 +143,7 @@ func GetPrices(fpc *FuelPricesConfig, prices *[]Price, xmlfile *XMLFile) error {
// SendToInflux sends time series data to influxdb // SendToInflux sends time series data to influxdb
func SendToInflux(fpc *FuelPricesConfig, prices *[]Price) error { func SendToInflux(fpc *FuelPricesConfig, prices *[]Price) error {
httpClient, err := client.NewHTTPClient(client.HTTPConfig{ httpClient, err := client.NewHTTPClient(client.HTTPConfig{
Addr: fmt.Sprintf("http://%s:%d", fpc.InfluxHost, fpc.InfluxPort), Addr: fpc.InfluxURL,
Username: fpc.InfluxUser, Username: fpc.InfluxUser,
Password: fpc.InfluxPass, Password: fpc.InfluxPass,
}) })
@ -153,6 +151,8 @@ func SendToInflux(fpc *FuelPricesConfig, prices *[]Price) error {
return err return err
} }
defer httpClient.Close()
bp, err := client.NewBatchPoints(client.BatchPointsConfig{ bp, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: fpc.InfluxDB, Database: fpc.InfluxDB,
}) })

View File

@ -21,8 +21,7 @@ type FuelPricesConfig struct {
Pos []string Pos []string
Types []string Types []string
Table string Table string
InfluxHost string InfluxURL string
InfluxPort int
InfluxUser string InfluxUser string
InfluxPass string InfluxPass string
InfluxDB string InfluxDB string