forked from kuskoman/logstash-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package collector | ||
package collectors | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package nodestats | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/kuskoman/logstash-exporter/config" | ||
logstashclient "github.com/kuskoman/logstash-exporter/fetcher/logstash_client" | ||
"github.com/kuskoman/logstash-exporter/helpers" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"log" | ||
) | ||
|
||
type NodestatsCollector struct { | ||
client *logstashclient.Client | ||
|
||
NodeInfos *prometheus.Desc | ||
BuildInfos *prometheus.Desc | ||
|
||
PipelineWorkers *prometheus.Desc | ||
PipelineBatchSize *prometheus.Desc | ||
PipelineBatchDelay *prometheus.Desc | ||
|
||
Status *prometheus.Desc | ||
} | ||
|
||
func NewNodestatsCollector(client *logstashclient.Client) *NodestatsCollector { | ||
const subsystem = "info" | ||
namespace := config.PrometheusNamespace | ||
descHelper := helpers.SimpleDescHelper{Namespace: namespace, Subsystem: subsystem} | ||
|
||
return &NodestatsCollector{ | ||
client: client, | ||
NodeInfos: prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, subsystem, "node"), | ||
"A metric with a constant '1' value labeled by node name, version, host, http_address, and id.", | ||
[]string{"name", "version", "http_address", "host", "id"}, | ||
nil, | ||
), | ||
BuildInfos: prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, subsystem, "build"), | ||
"A metric with a constant '1' value labeled by build date, sha, and snapshot.", | ||
[]string{"date", "sha", "snapshot"}, | ||
nil, | ||
), | ||
|
||
PipelineWorkers: descHelper.NewDesc("pipeline_workers"), | ||
PipelineBatchSize: descHelper.NewDesc("pipeline_batch_size"), | ||
PipelineBatchDelay: descHelper.NewDesc("pipeline_batch_delay"), | ||
|
||
Status: prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, subsystem, "status"), | ||
"A metric with a constant '1' value labeled by status.", | ||
[]string{"status"}, | ||
nil, | ||
), | ||
} | ||
} | ||
|
||
func (c *NodestatsCollector) Collect(ch chan<- prometheus.Metric) error { | ||
nodeInfo, err := c.client.GetNodeInfo() | ||
if err != nil { | ||
log.Printf("Error while fetching node info: %s", err) | ||
return err | ||
} | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
c.NodeInfos, | ||
prometheus.CounterValue, | ||
float64(1), | ||
nodeInfo.Name, | ||
nodeInfo.Version, | ||
nodeInfo.Host, | ||
nodeInfo.HTTPAddress, | ||
nodeInfo.ID, | ||
) | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
c.BuildInfos, | ||
prometheus.CounterValue, | ||
float64(1), | ||
nodeInfo.BuildDate, | ||
nodeInfo.BuildSHA, | ||
strconv.FormatBool(nodeInfo.BuildSnapshot), | ||
) | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
c.PipelineWorkers, | ||
prometheus.CounterValue, | ||
float64(nodeInfo.Pipeline.Workers), | ||
) | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
c.PipelineBatchSize, | ||
prometheus.CounterValue, | ||
float64(nodeInfo.Pipeline.BatchSize), | ||
) | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
c.PipelineBatchDelay, | ||
prometheus.CounterValue, | ||
float64(nodeInfo.Pipeline.BatchDelay), | ||
) | ||
|
||
ch <- prometheus.MustNewConstMetric( | ||
c.Status, | ||
prometheus.CounterValue, | ||
float64(1), | ||
nodeInfo.Status, | ||
) | ||
|
||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package config | ||
|
||
const PrometheusNamespace = "logstash" |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package helpers | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
type SimpleDescHelper struct { | ||
Namespace string | ||
Subsystem string | ||
} | ||
|
||
func (h *SimpleDescHelper) NewDesc(name string) *prometheus.Desc { | ||
help := name | ||
return prometheus.NewDesc(prometheus.BuildFQName(h.Namespace, h.Subsystem, name), help, nil, nil) | ||
} |