Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VLAN not present in #249

Open
jseifeddine opened this issue Sep 26, 2023 · 4 comments
Open

VLAN not present in #249

jseifeddine opened this issue Sep 26, 2023 · 4 comments

Comments

@jseifeddine
Copy link

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

Wondering if this is available ?

@jseifeddine
Copy link
Author

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
}

@lazyb0nes
Copy link

Hello,

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

@jseifeddine
Copy link
Author

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
Copy link
Author

There you go @lazyb0nes

#279 PR submitted...

Go easy on me, first time :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants