fortigate_exporter icon indicating copy to clipboard operation
fortigate_exporter copied to clipboard

VLAN not present in

Open jseifeddine opened this issue 1 year ago • 4 comments

fortigate_interface_link_up{alias="",name="SIP",parent="port34",vdom="XXX"} 1

Wondering if this is available ?

jseifeddine avatar Sep 26 '23 04:09 jseifeddine

i've hacked it up and made it work now, built my own docker image,

./pkg/probe/system_interface.go

package probe

import (
	"log"

	"github.com/bluecmd/fortigate_exporter/pkg/http"
	"github.com/prometheus/client_golang/prometheus"
)

import "strconv"

func probeSystemInterface(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
	var (
		mLink = prometheus.NewDesc(
			"fortigate_interface_link_up",
			"Whether the link is up or not (not taking into account admin status)",
			[]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", "vlanid", "alias", "parent"}, nil,
		)
		mTxPkts = prometheus.NewDesc(
			"fortigate_interface_transmit_packets_total",
			"Number of packets transmitted on the interface",
			[]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", "vlanid", "alias", "parent"}, nil,
		)
		mTxB = prometheus.NewDesc(
			"fortigate_interface_transmit_bytes_total",
			"Number of bytes transmitted on the interface",
			[]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", "vlanid", "alias", "parent"}, nil,
		)
		mTxErr = prometheus.NewDesc(
			"fortigate_interface_transmit_errors_total",
			"Number of transmission errors detected on the interface",
			[]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", "vlanid", "alias", "parent"}, nil,
		)
	)

	type ifResult struct {
		Id        string
		Name      string
		Alias     string
		Link      bool
		Speed     float64
		Duplex    float64
		TxPackets float64 `json:"tx_packets"`
		RxPackets float64 `json:"rx_packets"`
		TxBytes   float64 `json:"tx_bytes"`
		RxBytes   float64 `json:"rx_bytes"`
		TxErrors  float64 `json:"tx_errors"`
		RxErrors  float64 `json:"rx_errors"`
		VlanID  int `json:"vlanid"`
		Interface string
	}
	type ifResponse struct {
		Results map[string]ifResult
		VDOM    string
	}
	var r []ifResponse

	if err := c.Get("api/v2/monitor/system/interface/select", "vdom=*&include_vlan=true&include_aggregate=true", &r); err != nil {
		log.Printf("Error: %v", err)
		return nil, false
	}
	m := []prometheus.Metric{}
	for _, v := range r {
		for _, ir := range v.Results {
			linkf := 0.0
			if ir.Link {
				linkf = 1.0
			}
			m = append(m, prometheus.MustNewConstMetric(mLink, prometheus.GaugeValue, linkf, v.VDOM, ir.Name, strconv.Itoa(ir.VlanID), ir.Alias, ir.Interface))
			m = append(m, prometheus.MustNewConstMetric(mSpeed, prometheus.GaugeValue, ir.Speed*1000*1000, v.VDOM, ir.Name, strconv.Itoa(ir.VlanID), ir.Alias, ir.Interface))
			m = append(m, prometheus.MustNewConstMetric(mTxPkts, prometheus.CounterValue, ir.TxPackets, v.VDOM, ir.Name, strconv.Itoa(ir.VlanID), ir.Alias, ir.Interface))
			m = append(m, prometheus.MustNewConstMetric(mRxPkts, prometheus.CounterValue, ir.RxPackets, v.VDOM, ir.Name, strconv.Itoa(ir.VlanID), ir.Alias, ir.Interface))
			m = append(m, prometheus.MustNewConstMetric(mTxB, prometheus.CounterValue, ir.TxBytes, v.VDOM, ir.Name, strconv.Itoa(ir.VlanID), ir.Alias, ir.Interface))
			m = append(m, prometheus.MustNewConstMetric(mRxB, prometheus.CounterValue, ir.RxBytes, v.VDOM, ir.Name, strconv.Itoa(ir.VlanID), ir.Alias, ir.Interface))
			m = append(m, prometheus.MustNewConstMetric(mTxErr, prometheus.CounterValue, ir.TxErrors, v.VDOM, ir.Name, strconv.Itoa(ir.VlanID), ir.Alias, ir.Interface))
			m = append(m, prometheus.MustNewConstMetric(mRxErr, prometheus.CounterValue, ir.RxErrors, v.VDOM, ir.Name, strconv.Itoa(ir.VlanID), ir.Alias, ir.Interface))
		}
	}
	return m, true
}

jseifeddine avatar Sep 26 '23 04:09 jseifeddine

Hello,

It would be very nice if you can submit a PR instead so we all can benefit from it :)

lazyb0nes avatar Oct 19 '23 19:10 lazyb0nes

Hello,

It would be very nice if you can submit a PR instead so we all can benefit from it :)

I've not submitted a PR before and I'm not 100% confident of the code above, please if you are able, inspect the code as a solution and submit the PR on my behalf - I shared the code in hope that it would help others, as it has helped us immensely

thanks

jseifeddine avatar Oct 24 '23 10:10 jseifeddine

There you go @lazyb0nes

#279 PR submitted...

Go easy on me, first time :D

jseifeddine avatar Feb 09 '24 11:02 jseifeddine