Skip to content
This repository was archived by the owner on Nov 18, 2024. It is now read-only.

Commit 9baaac4

Browse files
committed
fix bug #54
1 parent 55c83fe commit 9baaac4

File tree

5 files changed

+116
-103
lines changed

5 files changed

+116
-103
lines changed

hmc/hmc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ func (hmc *HMC) WritePoints() (err error) {
103103
// AddPoint add a InfluxDB point. It's using the GlobalPoint parameter to fill some fields
104104
func (hmc *HMC) AddPoint(name string, metric string, values []float64) {
105105

106-
value := 0.0
106+
value := 0.0
107107
if len(values) > 0 {
108108
value = values[0]
109109
}
110110

111-
point := Point{ Name: name, Metric: metric, Value: value}
111+
point := Point{Name: name, Metric: metric, Value: value}
112112

113113
tags := map[string]string{"system": hmc.GlobalPoint.System, "name": point.Metric}
114114
if len(hmc.GlobalPoint.Pool) > 0 {

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ func main() {
272272
Value: config.InfluxdbPort,
273273
},
274274
cli.BoolFlag{
275-
Name: "secure",
276-
Usage: "use ssl for InfluxDB",
275+
Name: "secure",
276+
Usage: "use ssl for InfluxDB",
277277
EnvVar: "NMON2INFLUXDB_SECURE",
278278
},
279279
cli.BoolFlag{
280-
Name: "skip_cert_check",
281-
Usage: "skip cert check for ssl connzction to InfluxDB",
280+
Name: "skip_cert_check",
281+
Usage: "skip cert check for ssl connzction to InfluxDB",
282282
EnvVar: "NMON2INFLUXDB_SKIP_CERT_CHECK",
283283
},
284284
cli.StringFlag{

nmon/dashboard.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88
"bufio"
99
"encoding/json"
1010
"fmt"
11+
"log"
1112
"os"
13+
"path"
1214
"regexp"
1315
"sort"
14-
"path"
1516

1617
"github.com/adejoux/grafanaclient"
1718
"github.com/adejoux/nmon2influxdb/nmon2influxdblib"
@@ -116,7 +117,7 @@ func (nmon *Nmon) WriteDashboard() {
116117
r.WriteTo(writer)
117118
writer.Flush()
118119

119-
fmt.Printf("Writing GRAFANA dashboard: %s\n", filename)
120+
log.Printf("Writing GRAFANA dashboard: %s\n", filename)
120121

121122
}
122123

@@ -826,13 +827,13 @@ func (nmon *Nmon) InitGrafanaSession() *grafanaclient.Session {
826827
}
827828

828829
if status != "ok" {
829-
fmt.Printf("No plugin for influxDB in Grafana !\n")
830+
log.Printf("No plugin for influxDB in Grafana !\n")
830831
os.Exit(1)
831832
}
832833
} else {
833834
nmon2influxdblib.CheckError(err)
834835
if _, present := plugins["influxdb"]; !present {
835-
fmt.Printf("No plugin for influxDB in Grafana !\n")
836+
log.Printf("No plugin for influxDB in Grafana !\n")
836837
os.Exit(1)
837838
}
838839
}
@@ -848,7 +849,7 @@ func (nmon *Nmon) InitGrafanaSession() *grafanaclient.Session {
848849
}
849850
err = grafana.CreateDataSource(ds)
850851
nmon2influxdblib.CheckError(err)
851-
fmt.Printf("Grafana %s DataSource created.\n", nmon.Config.GrafanaDatasource)
852+
log.Printf("Grafana %s DataSource created.\n", nmon.Config.GrafanaDatasource)
852853
}
853854

854855
return grafana
@@ -860,10 +861,10 @@ func (nmon *Nmon) UploadDashboard(dashboard grafanaclient.Dashboard) (err error)
860861

861862
err = grafana.UploadDashboard(dashboard, true)
862863
if err != nil {
863-
fmt.Printf("Unable to upload Grafana dashboard: %s ! \n", err.Error())
864+
log.Printf("Unable to upload Grafana dashboard: %s ! \n", err.Error())
864865
return
865866
}
866867

867-
fmt.Printf("Dashboard uploaded to grafana\n")
868+
log.Printf("Dashboard uploaded to grafana\n")
868869
return
869870
}

nmon/import.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ package nmon
77
import (
88
"fmt"
99
"log"
10+
"math"
1011
"os"
1112
"path"
1213
"regexp"
1314
"strconv"
1415
"strings"
1516
"time"
16-
"math"
1717

1818
"github.com/adejoux/influxdbclient"
1919
"github.com/adejoux/nmon2influxdb/nmon2influxdblib"
@@ -63,7 +63,6 @@ func Import(c *cli.Context) {
6363

6464
for _, nmonFile := range nmonFiles.Valid() {
6565

66-
6766
// store the list of metrics which was logged as skipped
6867
LoggedSkippedMetrics := make(map[string]bool)
6968
var count int64
@@ -75,18 +74,26 @@ func Import(c *cli.Context) {
7574
nmon.TagParsers = tagParsers
7675
}
7776

77+
if nmon.Debug {
78+
log.Printf("Import file: %s", nmonFile.Name)
79+
}
80+
7881
lines := nmonFile.Content()
7982
log.Printf("NMON file separator: %s\n", nmonFile.Delimiter)
8083
var last string
8184
filters := new(influxdbclient.Filters)
8285
filters.Add("file", path.Base(nmonFile.Name), "text")
8386

84-
result, err := influxdbLog.ReadLastPoint("value", filters, "timestamp")
87+
timeStamp, err := influxdbLog.ReadLastPoint("value", filters, "timestamp")
8588
nmon2influxdblib.CheckError(err)
8689

90+
if nmon.Debug {
91+
log.Printf("influxdb stored timestamp: %v\n", timeStamp)
92+
}
93+
8794
var lastTime time.Time
88-
if !nmon.Config.ImportForce && len(result) > 0 {
89-
lastTime, err = nmon.ConvertTimeStamp(result[1].(string))
95+
if !nmon.Config.ImportForce && len(timeStamp) > 0 {
96+
lastTime, err = nmon.ConvertTimeStamp(timeStamp)
9097
} else {
9198
lastTime, err = nmon.ConvertTimeStamp("00:00:00,01-JAN-1900")
9299
}
@@ -95,10 +102,14 @@ func Import(c *cli.Context) {
95102
origChecksum, err := influxdbLog.ReadLastPoint("value", filters, "checksum")
96103
nmon2influxdblib.CheckError(err)
97104

105+
if nmon.Debug {
106+
log.Printf("influxdb stored checksum: %v\n", origChecksum)
107+
}
108+
98109
ckfield := map[string]interface{}{"value": nmonFile.Checksum()}
99110
if !nmon.Config.ImportForce && len(origChecksum) > 0 {
100111

101-
if origChecksum[1].(string) == nmonFile.Checksum() {
112+
if origChecksum == nmonFile.Checksum() {
102113
fmt.Printf("file not changed since last import: %s\n", nmonFile.Name)
103114
continue
104115
}
@@ -159,7 +170,7 @@ func Import(c *cli.Context) {
159170

160171
// try to convert string to integer
161172
converted, parseErr := strconv.ParseFloat(value, 64)
162-
if (parseErr != nil || math.IsNaN(converted)) {
173+
if parseErr != nil || math.IsNaN(converted) {
163174
//if not working, skip to next value. We don't want text values in InfluxDB.
164175
continue
165176
}

nmon2influxdblib/config.go

Lines changed: 84 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,50 @@ var secretPassword = "secret"
2323

2424
// Config is the configuration structure used by nmon2influxdb
2525
type Config struct {
26-
Debug bool
27-
DebugFile string
28-
Timezone string
29-
InfluxdbUser string
30-
InfluxdbPassword string
31-
InfluxdbServer string
32-
InfluxdbPort string
33-
InfluxdbSecure bool
26+
Debug bool
27+
DebugFile string
28+
Timezone string
29+
InfluxdbUser string
30+
InfluxdbPassword string
31+
InfluxdbServer string
32+
InfluxdbPort string
33+
InfluxdbSecure bool
3434
InfluxdbSkipCertCheck bool
35-
InfluxdbDatabase string
36-
GrafanaUser string
37-
GrafanaPassword string
38-
GrafanaURL string `toml:"grafana_URL"`
39-
GrafanaAccess string
40-
GrafanaDatasource string
41-
HMCServer string `toml:"hmc_server"`
42-
HMCUser string `toml:"hmc_user"`
43-
HMCPassword string `toml:"hmc_password"`
44-
HMCDatabase string `toml:"hmc_database"`
45-
HMCDataRetention string `toml:"hmc_data_retention"`
46-
HMCManagedSystem string `toml:"hmc_managed_system"`
47-
HMCManagedSystemOnly bool `toml:"hmc_managed_system_only"`
48-
HMCSamples int `toml:"hmc_samples"`
49-
ImportSkipDisks bool
50-
ImportAllCpus bool
51-
ImportBuildDashboard bool
52-
ImportForce bool
53-
ImportSkipMetrics string
54-
ImportLogDatabase string
55-
ImportLogRetention string
56-
ImportDataRetention string
57-
ImportSSHUser string `toml:"import_ssh_user"`
58-
ImportSSHKey string `toml:"import_ssh_key"`
59-
DashboardWriteFile bool
60-
StatsLimit int
61-
StatsSort string
62-
StatsFilter string
63-
StatsFrom string
64-
StatsTo string
65-
StatsHost string
66-
Metric string `toml:"metric,omitempty"`
67-
ListFilter string `toml:",omitempty"`
68-
ListHost string `toml:",omitempty"`
69-
Inputs Inputs `toml:"input"`
35+
InfluxdbDatabase string
36+
GrafanaUser string
37+
GrafanaPassword string
38+
GrafanaURL string `toml:"grafana_URL"`
39+
GrafanaAccess string
40+
GrafanaDatasource string
41+
HMCServer string `toml:"hmc_server"`
42+
HMCUser string `toml:"hmc_user"`
43+
HMCPassword string `toml:"hmc_password"`
44+
HMCDatabase string `toml:"hmc_database"`
45+
HMCDataRetention string `toml:"hmc_data_retention"`
46+
HMCManagedSystem string `toml:"hmc_managed_system"`
47+
HMCManagedSystemOnly bool `toml:"hmc_managed_system_only"`
48+
HMCSamples int `toml:"hmc_samples"`
49+
ImportSkipDisks bool
50+
ImportAllCpus bool
51+
ImportBuildDashboard bool
52+
ImportForce bool
53+
ImportSkipMetrics string
54+
ImportLogDatabase string
55+
ImportLogRetention string
56+
ImportDataRetention string
57+
ImportSSHUser string `toml:"import_ssh_user"`
58+
ImportSSHKey string `toml:"import_ssh_key"`
59+
DashboardWriteFile bool
60+
StatsLimit int
61+
StatsSort string
62+
StatsFilter string
63+
StatsFrom string
64+
StatsTo string
65+
StatsHost string
66+
Metric string `toml:"metric,omitempty"`
67+
ListFilter string `toml:",omitempty"`
68+
ListHost string `toml:",omitempty"`
69+
Inputs Inputs `toml:"input"`
7070
}
7171

7272
// Inputs allows to put multiple input in the configuration file
@@ -87,39 +87,39 @@ func InitConfig() Config {
8787
sshKey := filepath.Join(home, "/.ssh/id_rsa")
8888

8989
return Config{Debug: false,
90-
Timezone: "Europe/Paris",
91-
InfluxdbUser: "root",
92-
InfluxdbPassword: "root",
93-
InfluxdbServer: "localhost",
94-
InfluxdbPort: "8086",
95-
InfluxdbDatabase: "nmon_reports",
96-
InfluxdbSecure: false,
97-
InfluxdbSkipCertCheck: false,
98-
HMCUser: "hscroot",
99-
HMCPassword: "abc123",
100-
HMCDatabase: "nmon2influxdbHMC",
101-
HMCSamples: 10,
102-
GrafanaUser: "admin",
103-
GrafanaPassword: "admin",
104-
GrafanaURL: "http://localhost:3000",
105-
GrafanaAccess: "direct",
106-
GrafanaDatasource: "nmon2influxdb",
107-
ImportSkipDisks: false,
108-
ImportAllCpus: false,
109-
ImportBuildDashboard: false,
110-
ImportForce: false,
111-
ImportLogDatabase: "nmon2influxdb_log",
112-
ImportLogRetention: "2d",
113-
ImportSSHUser: currUser.Username,
114-
ImportSSHKey: sshKey,
115-
DashboardWriteFile: false,
116-
ImportSkipMetrics: "JFSINODE|TOP|PCPU",
117-
StatsLimit: 20,
118-
StatsSort: "mean",
119-
StatsFilter: "",
120-
StatsFrom: "",
121-
StatsTo: "",
122-
StatsHost: "",
90+
Timezone: "Europe/Paris",
91+
InfluxdbUser: "root",
92+
InfluxdbPassword: "root",
93+
InfluxdbServer: "localhost",
94+
InfluxdbPort: "8086",
95+
InfluxdbDatabase: "nmon_reports",
96+
InfluxdbSecure: false,
97+
InfluxdbSkipCertCheck: false,
98+
HMCUser: "hscroot",
99+
HMCPassword: "abc123",
100+
HMCDatabase: "nmon2influxdbHMC",
101+
HMCSamples: 10,
102+
GrafanaUser: "admin",
103+
GrafanaPassword: "admin",
104+
GrafanaURL: "http://localhost:3000",
105+
GrafanaAccess: "direct",
106+
GrafanaDatasource: "nmon2influxdb",
107+
ImportSkipDisks: false,
108+
ImportAllCpus: false,
109+
ImportBuildDashboard: false,
110+
ImportForce: false,
111+
ImportLogDatabase: "nmon2influxdb_log",
112+
ImportLogRetention: "2d",
113+
ImportSSHUser: currUser.Username,
114+
ImportSSHKey: sshKey,
115+
DashboardWriteFile: false,
116+
ImportSkipMetrics: "JFSINODE|TOP|PCPU",
117+
StatsLimit: 20,
118+
StatsSort: "mean",
119+
StatsFilter: "",
120+
StatsFrom: "",
121+
StatsTo: "",
122+
StatsHost: "",
123123
}
124124
}
125125

@@ -202,6 +202,7 @@ func (config *Config) AddDashboardParams() {
202202
config.GrafanaDatasource = dfltConfig.GrafanaDatasource
203203
config.GrafanaUser = dfltConfig.GrafanaUser
204204
config.GrafanaPassword = dfltConfig.GrafanaPassword
205+
config.DashboardWriteFile = dfltConfig.DashboardWriteFile
205206
}
206207

207208
// ParseParameters parse parameter from command line in Config struct
@@ -277,13 +278,13 @@ func ParseParameters(c *cli.Context) (config *Config) {
277278
// ConnectDB connect to the specified influxdb database
278279
func (config *Config) ConnectDB(db string) *influxdbclient.InfluxDB {
279280
influxdbConfig := influxdbclient.InfluxDBConfig{
280-
Host: config.InfluxdbServer,
281-
Port: config.InfluxdbPort,
282-
Database: db,
283-
User: config.InfluxdbUser,
284-
Pass: config.InfluxdbPassword,
285-
Debug: config.Debug,
286-
Secure: config.InfluxdbSecure,
281+
Host: config.InfluxdbServer,
282+
Port: config.InfluxdbPort,
283+
Database: db,
284+
User: config.InfluxdbUser,
285+
Pass: config.InfluxdbPassword,
286+
Debug: config.Debug,
287+
Secure: config.InfluxdbSecure,
287288
SkipCertCheck: config.InfluxdbSkipCertCheck,
288289
}
289290
influxdb, err := influxdbclient.NewInfluxDB(influxdbConfig)

0 commit comments

Comments
 (0)