|
49 | 49 | configFile = kingpin.Flag("config.file", "Path to configuration file.").Default("snmp.yml").Strings() |
50 | 50 | dryRun = kingpin.Flag("dry-run", "Only verify configuration is valid and exit.").Default("false").Bool() |
51 | 51 | concurrency = kingpin.Flag("snmp.module-concurrency", "The number of modules to fetch concurrently per scrape").Default("1").Int() |
| 52 | + debugSNMP = kingpin.Flag("snmp.debug-packets", "Include a full debug trace of SNMP packet traffics.").Default("false").Bool() |
52 | 53 | expandEnvVars = kingpin.Flag("config.expand-environment-variables", "Expand environment variables to source secrets").Default("false").Bool() |
53 | 54 | metricsPath = kingpin.Flag( |
54 | 55 | "web.telemetry-path", |
@@ -86,6 +87,14 @@ const ( |
86 | 87 | func handler(w http.ResponseWriter, r *http.Request, logger log.Logger, exporterMetrics collector.Metrics) { |
87 | 88 | query := r.URL.Query() |
88 | 89 |
|
| 90 | + debug := *debugSNMP |
| 91 | + if query.Get("snmp_debug_packets") == "true" { |
| 92 | + debug = true |
| 93 | + // TODO: This doesn't work the way I want. |
| 94 | + // logger = level.NewFilter(logger, level.AllowDebug()) |
| 95 | + level.Debug(logger).Log("msg", "Debug query param enabled") |
| 96 | + } |
| 97 | + |
89 | 98 | target := query.Get("target") |
90 | 99 | if len(query["target"]) != 1 || target == "" { |
91 | 100 | http.Error(w, "'target' parameter must be specified once", http.StatusBadRequest) |
@@ -149,7 +158,7 @@ func handler(w http.ResponseWriter, r *http.Request, logger log.Logger, exporter |
149 | 158 | sc.RUnlock() |
150 | 159 | logger = log.With(logger, "auth", authName, "target", target) |
151 | 160 | registry := prometheus.NewRegistry() |
152 | | - c := collector.New(r.Context(), target, authName, snmpContext, auth, nmodules, logger, exporterMetrics, *concurrency) |
| 161 | + c := collector.New(r.Context(), target, authName, snmpContext, auth, nmodules, logger, exporterMetrics, *concurrency, debug) |
153 | 162 | registry.MustRegister(c) |
154 | 163 | // Delegate http serving to Prometheus client library, which will call collector.Collect. |
155 | 164 | h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{}) |
@@ -200,7 +209,7 @@ func main() { |
200 | 209 | *concurrency = 1 |
201 | 210 | } |
202 | 211 |
|
203 | | - level.Info(logger).Log("msg", "Starting snmp_exporter", "version", version.Info(), "concurrency", concurrency) |
| 212 | + level.Info(logger).Log("msg", "Starting snmp_exporter", "version", version.Info(), "concurrency", concurrency, "debug_snmp", debugSNMP) |
204 | 213 | level.Info(logger).Log("build_context", version.BuildContext()) |
205 | 214 |
|
206 | 215 | prometheus.MustRegister(versioncollector.NewCollector("snmp_exporter")) |
|
0 commit comments