Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shadowy-pycoder/go-node-collector
Prometheus collector for hardware and OS metrics exposed by *NIX kernels.
https://github.com/shadowy-pycoder/go-node-collector
collector golang kernel linux metrics observability prometheus prometheus-collector stats
Last synced: 9 days ago
JSON representation
Prometheus collector for hardware and OS metrics exposed by *NIX kernels.
- Host: GitHub
- URL: https://github.com/shadowy-pycoder/go-node-collector
- Owner: shadowy-pycoder
- License: apache-2.0
- Created: 2024-07-31T08:33:57.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-08-02T03:29:04.000Z (4 months ago)
- Last Synced: 2024-08-02T10:29:02.795Z (3 months ago)
- Topics: collector, golang, kernel, linux, metrics, observability, prometheus, prometheus-collector, stats
- Language: Go
- Homepage: https://pkg.go.dev/github.com/shadowy-pycoder/go-node-collector/collector
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Prometheus Node Collector
Prometheus collector for [prometheus golang client](https://github.com/prometheus/client_golang)
that collects hardware and OS metrics exposed by \*NIX kernels.This library is a modification heavily based on [Prometheus Node Exporter](https://github.com/prometheus/node_exporter)
For now, only Ubuntu-based distributions are supported.
# Supported Collectors
- cpu | Exposes CPU statistics
- cpufreq | Exposes CPU frequency statistics
- diskstats | Exposes disk I/O statistics
- filesystem | Exposes filesystem statistics, such as disk space used
- meminfo | Exposes memory statistics
- systemd | Exposes systemd statistics
- thermal_zone | Exposes thermal zone & cooling device statistics from `/sys/class/thermal`# Usage
```go
package mainimport (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time""github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/shadowy-pycoder/go-node-collector/collector"
)func main() {
nc, err := collector.NewNodeCollector()
// By default, it gathers all metrics, but specific collectors can be selected
// Example: nc, err := collector.NewNodeCollector("cpu", "systemd")
if err != nil {
log.Fatal(err)
}
prometheus.DefaultRegisterer.MustRegister(nc)
port := 9100
sm := http.NewServeMux()
sm.Handle("/metrics", promhttp.Handler())
bindAddress := fmt.Sprintf(":%d", port)
s := http.Server{
Addr: bindAddress, // configure the bind address
Handler: sm, // set the default handler
ReadTimeout: 5 * time.Second, // max time to read request from the client
WriteTimeout: 10 * time.Second, // max time to write response to the client
IdleTimeout: 120 * time.Second, // max time for connections using TCP Keep-Alive
}go func() {
log.Printf("Starting server on port %d", port)err := s.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}()
// trap sigterm or interupt and gracefully shutdown the server
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)// Block until a signal is received.
sig := <-c
log.Println("Got signal:", sig)// gracefully shutdown the server, waiting max 30 seconds for current operations to complete
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
s.Shutdown(ctx)
}
```