From 10f58a72ea289d68f36c9c6ccad1d0f6f424ac38 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Thu, 19 Apr 2018 11:26:08 +0200 Subject: [PATCH] Add DHCP statistics --- data/statistics.go | 17 +++++++++++++++++ database/influxdb/database.go | 1 + database/influxdb/node.go | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/data/statistics.go b/data/statistics.go index 437113a..19212d8 100644 --- a/data/statistics.go +++ b/data/statistics.go @@ -9,6 +9,7 @@ package data type Statistics struct { NodeID string `json:"node_id"` Clients Clients `json:"clients"` + DHCP *DHCP `json:"dhcp"` RootFsUsage float64 `json:"rootfs_usage,omitempty"` LoadAverage float64 `json:"loadavg,omitempty"` Memory Memory `json:"memory,omitempty"` @@ -64,6 +65,22 @@ type Clients struct { Total uint32 `json:"total"` } +// DHCP struct +type DHCP struct { + // Packet counters + Decline uint32 `json:"dhcp_decline"` + Offer uint32 `json:"dhcp_offer"` + Ack uint32 `json:"dhcp_ack"` + Nak uint32 `json:"dhcp_nak"` + Request uint32 `json:"dhcp_request"` + Discover uint32 `json:"dhcp_discover"` + Inform uint32 `json:"dhcp_inform"` + Release uint32 `json:"dhcp_release"` + + LeasesAllocated uint32 `json:"leases_allocated_4"` + LeasesPruned uint32 `json:"leases_pruned_4"` +} + // Memory struct type Memory struct { Cached int64 `json:"cached"` diff --git a/database/influxdb/database.go b/database/influxdb/database.go index 0266b62..b59a6fb 100644 --- a/database/influxdb/database.go +++ b/database/influxdb/database.go @@ -14,6 +14,7 @@ import ( const ( MeasurementLink = "link" // Measurement for per-link statistics MeasurementNode = "node" // Measurement for per-node statistics + MeasurementDHCP = "dhcp" // Measurement for DHCP server statistics MeasurementGlobal = "global" // Measurement for summarized global statistics CounterMeasurementFirmware = "firmware" // Measurement for firmware statistics CounterMeasurementModel = "model" // Measurement for model statistics diff --git a/database/influxdb/node.go b/database/influxdb/node.go index 17acc13..56b7715 100644 --- a/database/influxdb/node.go +++ b/database/influxdb/node.go @@ -141,5 +141,30 @@ func (conn *Connection) InsertNode(node *runtime.Node) { conn.addPoint(MeasurementNode, tags, fields, time) + // Add DHCP statistics + if dhcp := stats.DHCP; dhcp != nil { + fields := models.Fields{ + "decline": dhcp.Decline, + "offer": dhcp.Offer, + "ack": dhcp.Ack, + "nak": dhcp.Nak, + "request": dhcp.Request, + "discover": dhcp.Discover, + "inform": dhcp.Inform, + "release": dhcp.Release, + + "leases.allocated": dhcp.LeasesAllocated, + "leases.pruned": dhcp.LeasesPruned, + } + + // Tags + tags.SetString("nodeid", stats.NodeID) + if nodeinfo := node.Nodeinfo; nodeinfo != nil { + tags.SetString("hostname", nodeinfo.Hostname) + } + + conn.addPoint(MeasurementDHCP, tags, fields, time) + } + return }