add geoip country/asn labels and ipv6
This commit is contained in:
parent
8318f9fe70
commit
4710df2523
12 changed files with 559 additions and 43 deletions
|
|
@ -18,7 +18,7 @@ type Exporter struct {
|
|||
|
||||
// NewExporter creates a Prometheus collector for DNSTT metrics.
|
||||
func NewExporter(collector *Collector) *Exporter {
|
||||
labels := []string{"domain"}
|
||||
labels := append([]string{"domain"}, collector.GeoLabelNames()...)
|
||||
return &Exporter{
|
||||
collector: collector,
|
||||
activeClients: prometheus.NewDesc(
|
||||
|
|
@ -73,11 +73,27 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
|
|||
// Collect sends current metric values to Prometheus.
|
||||
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||
for _, tunnel := range e.collector.Snapshot().Tunnels {
|
||||
ch <- prometheus.MustNewConstMetric(e.activeClients, prometheus.GaugeValue, float64(tunnel.ActiveClients), tunnel.Domain)
|
||||
ch <- prometheus.MustNewConstMetric(e.peakClients, prometheus.GaugeValue, float64(tunnel.PeakClients), tunnel.Domain)
|
||||
ch <- prometheus.MustNewConstMetric(e.queries, prometheus.CounterValue, float64(tunnel.TotalQueries), tunnel.Domain)
|
||||
ch <- prometheus.MustNewConstMetric(e.bytesIn, prometheus.CounterValue, float64(tunnel.BytesIn), tunnel.Domain)
|
||||
ch <- prometheus.MustNewConstMetric(e.bytesOut, prometheus.CounterValue, float64(tunnel.BytesOut), tunnel.Domain)
|
||||
ch <- prometheus.MustNewConstMetric(e.sessions, prometheus.CounterValue, float64(tunnel.TotalSessions), tunnel.Domain)
|
||||
for _, series := range tunnel.Series {
|
||||
labels := e.labelValues(series)
|
||||
ch <- prometheus.MustNewConstMetric(e.activeClients, prometheus.GaugeValue, float64(series.ActiveClients), labels...)
|
||||
ch <- prometheus.MustNewConstMetric(e.peakClients, prometheus.GaugeValue, float64(series.PeakClients), labels...)
|
||||
ch <- prometheus.MustNewConstMetric(e.queries, prometheus.CounterValue, float64(series.TotalQueries), labels...)
|
||||
ch <- prometheus.MustNewConstMetric(e.bytesIn, prometheus.CounterValue, float64(series.BytesIn), labels...)
|
||||
ch <- prometheus.MustNewConstMetric(e.bytesOut, prometheus.CounterValue, float64(series.BytesOut), labels...)
|
||||
ch <- prometheus.MustNewConstMetric(e.sessions, prometheus.CounterValue, float64(series.TotalSessions), labels...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Exporter) labelValues(series SeriesSnapshot) []string {
|
||||
values := []string{series.Domain}
|
||||
for _, label := range e.collector.GeoLabelNames() {
|
||||
switch label {
|
||||
case "country":
|
||||
values = append(values, series.Country)
|
||||
case "asn":
|
||||
values = append(values, series.ASN)
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue