Skip to content

Commit

Permalink
Add DHCP statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
corny authored and genofire committed May 5, 2018
1 parent 8512afb commit 10f58a7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions data/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions database/influxdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions database/influxdb/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

2 comments on commit 10f58a7

@lemoer
Copy link
Contributor

@lemoer lemoer commented on 10f58a7 Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds interessting. Which data source is announcing this values?

@genofire
Copy link
Member

@genofire genofire commented on 10f58a7 Jun 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short:

Please sign in to comment.