Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"time"

"github.com/liftedinit/manifest-node-exporter/pkg"
"github.com/liftedinit/manifest-node-exporter/pkg/autodetect"
_ "github.com/liftedinit/manifest-node-exporter/pkg/autodetect/manifestd" // RegisterMonitor the manifestd monitor (side-effect)
"github.com/liftedinit/manifest-node-exporter/pkg/collectors"
"github.com/liftedinit/manifest-node-exporter/pkg/collectors/autodetect"
_ "github.com/liftedinit/manifest-node-exporter/pkg/collectors/autodetect/manifestd" // RegisterMonitor the manifestd monitor (side-effect)
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -36,11 +37,14 @@ var serveCmd = &cobra.Command{
defer rootCancel()
handleInterrupt(rootCancel)

geoIpCollector := collectors.NewGeoIPCollector()

// Setup process monitors and fetch all registered collectors
allCollectors, err := setupMonitors(rootCtx)
monitorCollectors, err := setupMonitors(rootCtx)
if err != nil {
return fmt.Errorf("failed to setup monitors: %w", err)
}
allCollectors := append(monitorCollectors, geoIpCollector)

// Register all collectors with Prometheus
registerCollectors(allCollectors)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20250422160041-2d3770c4ea7f // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
resty.dev/v3 v3.0.0-beta.2 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
resty.dev/v3 v3.0.0-beta.2 h1:xu4mGAdbCLuc3kbk7eddWfWm4JfhwDtdapwss5nCjnQ=
resty.dev/v3 v3.0.0-beta.2/go.mod h1:OgkqiPvTDtOuV4MGZuUDhwOpkY8enjOsjjMzeOHefy4=
14 changes: 14 additions & 0 deletions pkg/collectors/autodetect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Autodetect Module

## Overview

The `autodetect` module provides automatic detection functionality for the Manifest Node Exporter. It helps in
automatically discovering and configuring monitoring settings based on the environment.

## Purpose

This module is responsible for:

- Detecting available services and endpoints
- Configuring appropriate monitoring parameters
- Providing sensible defaults for the exporter configuration
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package collectors
package manifestd

import (
"log/slog"
"strconv"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
"github.com/liftedinit/manifest-node-exporter/pkg/client"
"github.com/liftedinit/manifest-node-exporter/pkg/collectors"
"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -71,10 +72,10 @@ func (c *DenomInfoCollector) Describe(ch chan<- *prometheus.Desc) {
// Collect implements the prometheus.Collector interface.
func (c *DenomInfoCollector) Collect(ch chan<- prometheus.Metric) {
// Check for initialization or connection errors first.
if err := validateClient(c.grpcClient, c.initialError); err != nil {
reportUpMetric(ch, c.upDesc, 0) // Report gRPC down
reportInvalidMetric(ch, c.totalSupplyDesc, err)
reportInvalidMetric(ch, c.denomInfoDesc, err)
if err := collectors.ValidateClient(c.grpcClient, c.initialError); err != nil {
collectors.ReportUpMetric(ch, c.upDesc, 0) // Report gRPC down
collectors.ReportInvalidMetric(ch, c.totalSupplyDesc, err)
collectors.ReportInvalidMetric(ch, c.denomInfoDesc, err)
return
}

Expand All @@ -94,15 +95,15 @@ func (c *DenomInfoCollector) Collect(ch chan<- prometheus.Metric) {
if denomMetaErr == nil && totalSupplyErr == nil {
upValue = 1.0
}
reportUpMetric(ch, c.upDesc, upValue)
collectors.ReportUpMetric(ch, c.upDesc, upValue)

c.collectDenomMetadata(ch, denomMetaResp, denomMetaErr)
c.collectTotalSupply(ch, totalSupplyResp, totalSupplyErr)
}

func (c *DenomInfoCollector) collectDenomMetadata(ch chan<- prometheus.Metric, resp *bankv1beta1.QueryDenomMetadataResponse, queryErr error) {
if queryErr != nil {
reportInvalidMetric(ch, c.denomInfoDesc, queryErr)
collectors.ReportInvalidMetric(ch, c.denomInfoDesc, queryErr)
return
}
if resp == nil {
Expand Down Expand Up @@ -131,7 +132,7 @@ func (c *DenomInfoCollector) collectDenomMetadata(ch chan<- prometheus.Metric, r

func (c *DenomInfoCollector) collectTotalSupply(ch chan<- prometheus.Metric, resp *bankv1beta1.QuerySupplyOfResponse, queryErr error) {
if queryErr != nil {
reportInvalidMetric(ch, c.totalSupplyDesc, queryErr)
collectors.ReportInvalidMetric(ch, c.totalSupplyDesc, queryErr)
return
}
if resp == nil {
Expand All @@ -140,15 +141,15 @@ func (c *DenomInfoCollector) collectTotalSupply(ch chan<- prometheus.Metric, res
coin := resp.Amount
if coin == nil {
slog.Warn("Total supply response is nil")
reportInvalidMetric(ch, c.totalSupplyDesc, status.Error(codes.Internal, "total supply response is nil"))
collectors.ReportInvalidMetric(ch, c.totalSupplyDesc, status.Error(codes.Internal, "total supply response is nil"))
return
}

amount, err := strconv.ParseFloat(coin.Amount, 64)
if err != nil {
parseErr := status.Errorf(codes.Internal, "failed to parse amount '%s' for denom '%s': %v", coin.Amount, coin.Denom, err)
slog.Warn("Failed to parse total supply amount", "denom", coin.Denom, "amount", coin.Amount, "error", err)
reportInvalidMetric(ch, c.totalSupplyDesc, parseErr)
collectors.ReportInvalidMetric(ch, c.totalSupplyDesc, parseErr)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
"slices"
"strconv"

"github.com/liftedinit/manifest-node-exporter/pkg/autodetect"
"github.com/liftedinit/manifest-node-exporter/pkg/autodetect/manifestd/collectors"
"github.com/liftedinit/manifest-node-exporter/pkg/client"
"github.com/liftedinit/manifest-node-exporter/pkg/collectors/autodetect"
"github.com/liftedinit/manifest-node-exporter/pkg/utils"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -108,7 +107,7 @@ func (m *manifestdMonitor) CollectCollectors(ctx context.Context, processInfo *a
}

var resultCollectors []prometheus.Collector
for _, collector := range collectors.GetAllCollectorFactories() {
for _, collector := range GetAllCollectorFactories() {
resultCollectors = append(resultCollectors, collector(grpcClient))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package collectors
package manifestd

import (
"maps"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package collectors
package manifestd

import (
"log/slog"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1"
"github.com/liftedinit/manifest-node-exporter/pkg/client"
"github.com/liftedinit/manifest-node-exporter/pkg/collectors"
"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -57,9 +58,9 @@ func (c *TokenCountCollector) Describe(ch chan<- *prometheus.Desc) {
// Collect implements the prometheus.Collector interface.
func (c *TokenCountCollector) Collect(ch chan<- prometheus.Metric) {
// Check for initialization or connection errors first.
if err := validateClient(c.grpcClient, c.initialError); err != nil {
reportUpMetric(ch, c.upDesc, 0) // Report gRPC down
reportInvalidMetric(ch, c.tokenCountDesc, err)
if err := collectors.ValidateClient(c.grpcClient, c.initialError); err != nil {
collectors.ReportUpMetric(ch, c.upDesc, 0) // Report gRPC down
collectors.ReportInvalidMetric(ch, c.tokenCountDesc, err)
return
}

Expand All @@ -74,15 +75,15 @@ func (c *TokenCountCollector) Collect(ch chan<- prometheus.Metric) {
if denomsMetaErr == nil {
upValue = 1.0
}
reportUpMetric(ch, c.upDesc, upValue)
collectors.ReportUpMetric(ch, c.upDesc, upValue)

if denomsMetaResp == nil {
reportInvalidMetric(ch, c.tokenCountDesc, status.Error(codes.Internal, "DenomsMetadata response is nil"))
collectors.ReportInvalidMetric(ch, c.tokenCountDesc, status.Error(codes.Internal, "DenomsMetadata response is nil"))
return
}

if denomsMetaResp.Pagination == nil {
reportInvalidMetric(ch, c.tokenCountDesc, status.Error(codes.Internal, "Pagination response is nil"))
collectors.ReportInvalidMetric(ch, c.tokenCountDesc, status.Error(codes.Internal, "Pagination response is nil"))
return
}

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"google.golang.org/grpc/status"
)

func reportUpMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, value float64) {
func ReportUpMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, value float64) {
metric, err := prometheus.NewConstMetric(desc, prometheus.GaugeValue, value)
if err != nil {
slog.Error("Failed to create up metric", "error", err)
Expand All @@ -18,11 +18,11 @@ func reportUpMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, value fl
}
}

func reportInvalidMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, err error) {
func ReportInvalidMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, err error) {
ch <- prometheus.NewInvalidMetric(desc, err)
}

func validateGrpcClient(client *client.GRPCClient) error {
func ValidateGrpcClient(client *client.GRPCClient) error {
if client == nil {
return status.Error(codes.Internal, "gRPC client is nil during collect")
}
Expand All @@ -32,11 +32,11 @@ func validateGrpcClient(client *client.GRPCClient) error {
return nil
}

func validateClient(client *client.GRPCClient, initErr error) error {
func ValidateClient(client *client.GRPCClient, initErr error) error {
if initErr != nil {
return initErr
}
if clientErr := validateGrpcClient(client); clientErr != nil {
if clientErr := ValidateGrpcClient(client); clientErr != nil {
return clientErr
}
return nil
Expand Down
Loading