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

Commit aebad04

Browse files
authored
Merge pull request #75 from gblansteen/hmc-timeout
hmc timeout
2 parents 84e3405 + 760d8f5 commit aebad04

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

docs/content/configuration/file.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ hmc_password="abc123"
5555
hmc_managed_system="mysystem"
5656
hmc_database="nmon2influxdbHMC"
5757
hmc_data_retention="40d"
58+
hmc_timeout="30"
5859
{{< /highlight >}}
5960

6061
# Additional parameters

docs/content/usage/hmc_import.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OPTIONS:
2222
--managed_system, -m only import this managed system
2323
--managed_system-only, --sys-only skip partition metrics
2424
--samples "0" import latest <value> samples
25+
--timeout 30 set a connection timeout
2526
{{< /highlight >}}
2627

2728
# Parameters
@@ -32,6 +33,7 @@ OPTIONS:
3233
* **managed_system**: fetch HMC PCM data only for this managed system
3334
* **--sys-only**: skip partition metrics
3435
* **--samples <value>**: fetch the latest <value> samples. Each sample is averaging 30 seconds.
36+
* **--timeout <value>**: set a connection timeout
3537

3638
# Environment variables
3739

@@ -53,6 +55,7 @@ hmc_managed_system="mysystem"
5355
hmc_database="nmon2influxdbHMC"
5456
hmc_data_retention="40d"
5557
hmc_samples=10
58+
hmc_timeout=30
5659
{{< /highlight >}}
5760

5861
It's possible to set all CLI parameters. It's also possible to change the InfluxDB database name with **hmc_database** and change the data retention with **hmc_data_retention**.

hmc/hmc.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import (
2424
"github.com/codegangsta/cli"
2525
)
2626

27-
// hmc can be really slow to answer
28-
const timeout = 30
29-
3027
// HMC contains the base struct used by all the hmc sub command
3128
type HMC struct {
3229
Session *Session
@@ -87,8 +84,9 @@ func NewHMC(c *cli.Context) *HMC {
8784
}
8885
hmcURL := fmt.Sprintf("https://"+"%s"+":12443", config.HMCServer)
8986
//initialize new http session
90-
hmc.Session = NewSession(config.HMCUser, config.HMCPassword, hmcURL)
87+
hmc.Session = NewSession(config.HMCUser, config.HMCPassword, hmcURL, config.HMCTimeout)
9188
hmc.Token = hmc.Session.doLogon()
89+
9290
return &hmc
9391
}
9492

@@ -222,7 +220,7 @@ type Session struct {
222220
}
223221

224222
// NewSession initialize a Session struct
225-
func NewSession(user string, password string, url string) *Session {
223+
func NewSession(user string, password string, url string, timeout int) *Session {
226224
tr := &http.Transport{
227225
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
228226
}
@@ -232,7 +230,9 @@ func NewSession(user string, password string, url string) *Session {
232230
log.Fatal(err)
233231
}
234232

235-
return &Session{client: &http.Client{Transport: tr, Jar: jar, Timeout: time.Second * timeout}, User: user, Password: password, url: url}
233+
log.Printf("Session Timeout %d\n", timeout)
234+
235+
return &Session{client: &http.Client{Transport: tr, Jar: jar, Timeout: time.Second * time.Duration(timeout)}, User: user, Password: password, url: url}
236236
}
237237

238238
type Token struct {

main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func main() {
7373
app := cli.NewApp()
7474
app.Name = "nmon2influxdb"
7575
app.Usage = "upload NMON stats to InfluxDB database"
76-
app.Version = "2.1.5"
76+
app.Version = "2.1.6"
7777
app.Commands = []cli.Command{
7878
{
7979
Name: "import",
@@ -254,6 +254,11 @@ func main() {
254254
Usage: "import latest <value> samples",
255255
Value: config.HMCSamples,
256256
},
257+
cli.IntFlag{
258+
Name: "timeout",
259+
Usage: "HMC connection timeout",
260+
Value: config.HMCTimeout,
261+
},
257262
},
258263
},
259264
},

nmon2influxdblib/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Config struct {
4646
HMCManagedSystem string `toml:"hmc_managed_system"`
4747
HMCManagedSystemOnly bool `toml:"hmc_managed_system_only"`
4848
HMCSamples int `toml:"hmc_samples"`
49+
HMCTimeout int `toml:"hmc_timeout"`
4950
ImportSkipDisks bool
5051
ImportAllCpus bool
5152
ImportBuildDashboard bool
@@ -99,6 +100,7 @@ func InitConfig() Config {
99100
HMCPassword: "abc123",
100101
HMCDatabase: "nmon2influxdbHMC",
101102
HMCSamples: 10,
103+
HMCTimeout: 30,
102104
GrafanaUser: "admin",
103105
GrafanaPassword: "admin",
104106
GrafanaURL: "http://localhost:3000",
@@ -242,6 +244,7 @@ func ParseParameters(c *cli.Context) (config *Config) {
242244
config.HMCManagedSystem = c.String("managed_system")
243245
config.HMCManagedSystemOnly = c.Bool("managed_system-only")
244246
config.HMCSamples = c.Int("samples")
247+
config.HMCTimeout = c.Int("timeout")
245248
config.InfluxdbServer = c.GlobalString("server")
246249
config.InfluxdbUser = c.GlobalString("user")
247250
config.InfluxdbPort = c.GlobalString("port")

0 commit comments

Comments
 (0)