This repository has been archived by the owner on Nov 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Added label: vlanid to system_interface.go #279
Open
jseifeddine
wants to merge
1
commit into
bluecmd:master
Choose a base branch
from
jseifeddine:feature/add-vlanid-label
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ package probe | |
|
||
import ( | ||
"log" | ||
|
||
"strconv" | ||
"github.com/bluecmd/fortigate_exporter/pkg/http" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
@@ -12,42 +12,42 @@ func probeSystemInterface(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus. | |
mLink = prometheus.NewDesc( | ||
"fortigate_interface_link_up", | ||
"Whether the link is up or not (not taking into account admin status)", | ||
[]string{"vdom", "name", "alias", "parent"}, nil, | ||
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil, | ||
) | ||
mSpeed = prometheus.NewDesc( | ||
"fortigate_interface_speed_bps", | ||
"Speed negotiated on the port in bits/s", | ||
[]string{"vdom", "name", "alias", "parent"}, nil, | ||
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil, | ||
) | ||
mTxPkts = prometheus.NewDesc( | ||
"fortigate_interface_transmit_packets_total", | ||
"Number of packets transmitted on the interface", | ||
[]string{"vdom", "name", "alias", "parent"}, nil, | ||
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil, | ||
) | ||
mRxPkts = prometheus.NewDesc( | ||
"fortigate_interface_receive_packets_total", | ||
"Number of packets received on the interface", | ||
[]string{"vdom", "name", "alias", "parent"}, nil, | ||
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil, | ||
) | ||
mTxB = prometheus.NewDesc( | ||
"fortigate_interface_transmit_bytes_total", | ||
"Number of bytes transmitted on the interface", | ||
[]string{"vdom", "name", "alias", "parent"}, nil, | ||
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil, | ||
) | ||
mRxB = prometheus.NewDesc( | ||
"fortigate_interface_receive_bytes_total", | ||
"Number of bytes received on the interface", | ||
[]string{"vdom", "name", "alias", "parent"}, nil, | ||
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil, | ||
) | ||
mTxErr = prometheus.NewDesc( | ||
"fortigate_interface_transmit_errors_total", | ||
"Number of transmission errors detected on the interface", | ||
[]string{"vdom", "name", "alias", "parent"}, nil, | ||
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil, | ||
) | ||
mRxErr = prometheus.NewDesc( | ||
"fortigate_interface_receive_errors_total", | ||
"Number of reception errors detected on the interface", | ||
[]string{"vdom", "name", "alias", "parent"}, nil, | ||
[]string{"vdom", "name", "vlanid", "alias", "parent"}, nil, | ||
) | ||
) | ||
|
||
|
@@ -64,6 +64,7 @@ func probeSystemInterface(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus. | |
RxBytes float64 `json:"rx_bytes"` | ||
TxErrors float64 `json:"tx_errors"` | ||
RxErrors float64 `json:"rx_errors"` | ||
VlanID int `json:"vlanid"` | ||
Interface string | ||
} | ||
type ifResponse struct { | ||
|
@@ -83,14 +84,15 @@ func probeSystemInterface(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus. | |
if ir.Link { | ||
linkf = 1.0 | ||
} | ||
m = append(m, prometheus.MustNewConstMetric(mLink, prometheus.GaugeValue, linkf, v.VDOM, ir.Name, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mSpeed, prometheus.GaugeValue, ir.Speed*1000*1000, v.VDOM, ir.Name, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mTxPkts, prometheus.CounterValue, ir.TxPackets, v.VDOM, ir.Name, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mRxPkts, prometheus.CounterValue, ir.RxPackets, v.VDOM, ir.Name, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mTxB, prometheus.CounterValue, ir.TxBytes, v.VDOM, ir.Name, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mRxB, prometheus.CounterValue, ir.RxBytes, v.VDOM, ir.Name, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mTxErr, prometheus.CounterValue, ir.TxErrors, v.VDOM, ir.Name, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mRxErr, prometheus.CounterValue, ir.RxErrors, v.VDOM, ir.Name, ir.Alias, ir.Interface)) | ||
vlan_string := strconv.Itoa(ir.VlanID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prometheus label must be a string, so we convert it before adding to the metric |
||
m = append(m, prometheus.MustNewConstMetric(mLink, prometheus.GaugeValue, linkf, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mSpeed, prometheus.GaugeValue, ir.Speed*1000*1000, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mTxPkts, prometheus.CounterValue, ir.TxPackets, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mRxPkts, prometheus.CounterValue, ir.RxPackets, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mTxB, prometheus.CounterValue, ir.TxBytes, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mRxB, prometheus.CounterValue, ir.RxBytes, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mTxErr, prometheus.CounterValue, ir.TxErrors, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface)) | ||
m = append(m, prometheus.MustNewConstMetric(mRxErr, prometheus.CounterValue, ir.RxErrors, v.VDOM, ir.Name, vlan_string, ir.Alias, ir.Interface)) | ||
} | ||
} | ||
return m, true | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json:"vlanid"
is an int, I tried keeping as string (for Prometheus metric label), but:Error: json: cannot unmarshal number into Go struct field ifResult.Results.vlanid of type string