Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use target in logs and not host #1

Merged
merged 2 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
}

func (c *Collector) Collect(ch chan<- prometheus.Metric) {
level.Debug(c.logger).Log("msg", "Collecting SSH metrics", "host", c.target.Host)
level.Debug(c.logger).Log("msg", "Collecting SSH metrics")
failureReasons := []string{"error", "timeout", "command-error", "command-output"}
collectTime := time.Now()

Expand Down Expand Up @@ -95,7 +95,7 @@ func (c *Collector) collect() Metric {
auth, autherror = getPrivateKeyAuth(c.target.PrivateKey)
if autherror != nil {
metric.FailureReason = "error"
level.Error(c.logger).Log("msg", "Error setting up private key auth", "err", autherror, "host", c.target.Host)
level.Error(c.logger).Log("msg", "Error setting up private key auth", "err", autherror)
return metric
}
} else {
Expand All @@ -115,7 +115,7 @@ func (c *Collector) collect() Metric {
} else {
metric.FailureReason = "error"
}
level.Error(c.logger).Log("msg", "Failed to establish SSH connection", "err", err, "host", c.target.Host)
level.Error(c.logger).Log("msg", "Failed to establish SSH connection", "err", err)
return metric
}
defer connection.Close()
Expand Down Expand Up @@ -147,25 +147,25 @@ func (c *Collector) collect() Metric {
timeout = true
close(c1)
metric.FailureReason = "timeout"
level.Error(c.logger).Log("msg", "Timeout establishing SSH session", "host", c.target.Host)
level.Error(c.logger).Log("msg", "Timeout establishing SSH session")
return metric
}
close(c1)
if sessionerror != nil {
metric.FailureReason = "error"
level.Error(c.logger).Log("msg", "Error establishing SSH session", "err", sessionerror, "host", c.target.Host)
level.Error(c.logger).Log("msg", "Error establishing SSH session", "err", sessionerror)
return metric
}
if commanderror != nil {
metric.FailureReason = "command-error"
level.Error(c.logger).Log("msg", "Error executing command", "err", commanderror, "host", c.target.Host, "command", c.target.Command)
level.Error(c.logger).Log("msg", "Error executing command", "err", commanderror, "command", c.target.Command)
return metric
}
if c.target.Command != "" && c.target.CommandExpect != "" {
commandExpectPattern := regexp.MustCompile(c.target.CommandExpect)
if !commandExpectPattern.MatchString(commandOutput) {
level.Error(c.logger).Log("msg", "Command output did not match expected value",
"output", commandOutput, "host", c.target.Host, "command", c.target.Command)
"output", commandOutput, "command", c.target.Command)
metric.FailureReason = "command-output"
return metric
}
Expand Down
2 changes: 1 addition & 1 deletion ssh_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func metricsHandler(c *config.Config, logger log.Logger) http.HandlerFunc {
Command: module.Command,
CommandExpect: module.CommandExpect,
}
sshCollector := collector.NewCollector(target, logger)
sshCollector := collector.NewCollector(target, log.With(logger, "target", target.Host))
registry.MustRegister(sshCollector)

gatherers := prometheus.Gatherers{registry}
Expand Down