Skip to content

Commit

Permalink
Move metrics to after figuring out activevcl
Browse files Browse the repository at this point in the history
  • Loading branch information
auduny committed Mar 20, 2024
1 parent f895228 commit 9bda86c
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions varnishprom.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,7 @@ func main() {
varnishVersion = columns[0]
}
}
// Get Commit hash if needed
if *gitCheck != "" {
// og -n 1 --pretty=format:"%H"
gitCmd := exec.Command("git", "-C", *gitCheck, "log", "-n", "1", "--pretty=format:%H")
gitCmdOutput, err := gitCmd.Output()
if err != nil {
slog.Warn("Error running git: ", "err", err)
break
}
commitHash = string(gitCmdOutput)
prommetric := getGauge("stats_version", "Version Varnish running", []string{"version", "githash", "activevcl", "varnishprom", "host"})
setGauge(prommetric, 1, []string{varnishVersion, commitHash, activeVcl, version, *hostname})
} else {
prommetric := getGauge("stats_version", "Version Varnish running", []string{"version", "activevcl", "varnishprom", "host"})
setGauge(prommetric, 1, []string{varnishVersion, activeVcl, version, *hostname})
}

// Get the active VCL

if *adminHost != "" {
Expand Down Expand Up @@ -326,6 +311,23 @@ func main() {
activeVcl = parsedVcl
}

// Get Commit hash if needed
if *gitCheck != "" {
// og -n 1 --pretty=format:"%H"
gitCmd := exec.Command("git", "-C", *gitCheck, "log", "-n", "1", "--pretty=format:%H")
gitCmdOutput, err := gitCmd.Output()
if err != nil {
slog.Warn("Error running git: ", "err", err)
break
}
commitHash = string(gitCmdOutput)
prommetric := getGauge("stats_version", "Version Varnish running", []string{"version", "githash", "activevcl", "varnishprom", "host"})
setGauge(prommetric, 1, []string{varnishVersion, commitHash, activeVcl, version, *hostname})
} else {
prommetric := getGauge("stats_version", "Version Varnish running", []string{"version", "activevcl", "varnishprom", "host"})
setGauge(prommetric, 1, []string{varnishVersion, activeVcl, version, *hostname})
}

varnishstat := exec.Command("varnishstat", "-1", "-j")
// Get a pipe connected to the command's standard output.
varnishstatOutput, err := varnishstat.StdoutPipe()
Expand Down

0 comments on commit 9bda86c

Please sign in to comment.