Skip to content

Commit

Permalink
fix: added expires_at label to dhcp leases
Browse files Browse the repository at this point in the history
  • Loading branch information
henrywhitaker3 committed Apr 1, 2024
1 parent 8d6bb63 commit 6aab601
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 6 additions & 4 deletions internal/adguard/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package adguard

import "time"

type Bool bool

func (b Bool) Int() int {
Expand Down Expand Up @@ -30,10 +32,10 @@ type Status struct {
}

type DhcpLease struct {
Mac string `json:"mac"`
IP string `json:"ip"`
Hostname string `json:"hostname"`
Expires string `json:"expires,omitempty"`
Mac string `json:"mac"`
IP string `json:"ip"`
Hostname string `json:"hostname"`
Expires *time.Time `json:"expires,omitempty"`
Type string
}

Expand Down
9 changes: 7 additions & 2 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"sync"
"time"

"github.com/henrywhitaker3/adguard-exporter/internal/adguard"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -97,7 +98,7 @@ var (
DhcpLeasesMetric = prometheus.NewDesc(
"adguard_dhcp_leases",
"The dhcp leases",
[]string{"server", "type", "ip", "mac", "hostname"},
[]string{"server", "type", "ip", "mac", "hostname", "expires_at"},
nil,
)
DhcpLeases = NewDhcpLeasesServer(DhcpLeasesMetric)
Expand Down Expand Up @@ -127,11 +128,15 @@ func (d *DhcpLeasesServer) Record(server string, leases []adguard.DhcpLease) {
func (d *DhcpLeasesServer) Collect(ch chan<- prometheus.Metric) {
for server, leases := range d.leases {
for _, lease := range leases {
expires := ""
if lease.Expires != nil {
expires = lease.Expires.Format(time.RFC3339)
}
ch <- prometheus.MustNewConstMetric(
d.Desc,
prometheus.CounterValue,
1,
server, lease.Type, lease.IP, lease.Mac, lease.Hostname,
server, lease.Type, lease.IP, lease.Mac, lease.Hostname, expires,
)
}
}
Expand Down

0 comments on commit 6aab601

Please sign in to comment.