-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from samcm/feat/disk-usage-node-info
Feat(exporter): disk usage & node info
- Loading branch information
Showing
13 changed files
with
235 additions
and
23 deletions.
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
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
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
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,10 +1,14 @@ | ||
pollingFrequencySeconds: 5 | ||
pollingFrequencySeconds: 10 | ||
|
||
consensus: | ||
enabled: true | ||
url: "http://192.168.0.128:5053" | ||
url: "http://localhost:5053" | ||
name: "consensus-client" | ||
execution: | ||
enabled: true | ||
url: "http://192.168.0.128:8545" | ||
name: "execution-client" | ||
url: "http://localhost:8545" | ||
name: "execution-client" | ||
diskUsage: | ||
enabled: false | ||
directories: | ||
- /data/ethereum |
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
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
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
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
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,81 @@ | ||
package disk | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type DiskUsage interface { | ||
GetUsage(ctx context.Context, directories []string) ([]DiskUsed, error) | ||
} | ||
|
||
type diskUsage struct { | ||
log logrus.FieldLogger | ||
metrics Metrics | ||
} | ||
|
||
func NewDiskUsage(ctx context.Context, log logrus.FieldLogger, metrics Metrics) (DiskUsage, error) { | ||
return &diskUsage{ | ||
log: log, | ||
metrics: metrics, | ||
}, nil | ||
} | ||
|
||
func (d *diskUsage) GetUsage(ctx context.Context, directories []string) ([]DiskUsed, error) { | ||
var diskUsed []DiskUsed | ||
for _, directory := range directories { | ||
info, err := os.Lstat(directory) | ||
if err != nil { | ||
d.log.WithField("directory", directory).Warn("Directory does not exist") | ||
continue | ||
} | ||
|
||
used, err := getDiskUsed(directory, info) | ||
if err != nil { | ||
d.log.WithField("directory", directory).WithError(err).Error("Failed to get usage") | ||
continue | ||
} | ||
|
||
diskUsed = append(diskUsed, DiskUsed{ | ||
Directory: directory, | ||
UsageBytes: used, | ||
}) | ||
} | ||
|
||
for _, disk := range diskUsed { | ||
d.metrics.ObserveDiskUsage(disk) | ||
} | ||
|
||
return diskUsed, nil | ||
} | ||
|
||
func getDiskUsed(currentPath string, info os.FileInfo) (int64, error) { | ||
size := info.Size() | ||
if !info.IsDir() { | ||
return size, nil | ||
} | ||
|
||
dir, err := os.Open(currentPath) | ||
|
||
if err != nil { | ||
return size, err | ||
} | ||
defer dir.Close() | ||
|
||
files, err := dir.Readdir(-1) | ||
if err != nil { | ||
return size, err | ||
} | ||
|
||
for _, file := range files { | ||
if file.Name() == "." || file.Name() == ".." { | ||
continue | ||
} | ||
s, _ := getDiskUsed(currentPath+"/"+file.Name(), file) | ||
size += s | ||
} | ||
|
||
return size, 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,36 @@ | ||
package disk | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
type Metrics interface { | ||
ObserveDiskUsage(disk DiskUsed) | ||
} | ||
|
||
type metrics struct { | ||
diskUsage *prometheus.GaugeVec | ||
} | ||
|
||
func NewMetrics(namespace string) Metrics { | ||
constLabels := make(prometheus.Labels) | ||
|
||
m := &metrics{ | ||
diskUsage: prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Namespace: namespace, | ||
Name: "disk_usage", | ||
Help: "How large the directory is (in bytes).", | ||
ConstLabels: constLabels, | ||
}, | ||
[]string{ | ||
"directory", | ||
}, | ||
), | ||
} | ||
|
||
prometheus.MustRegister(m.diskUsage) | ||
return m | ||
} | ||
|
||
func (m *metrics) ObserveDiskUsage(disk DiskUsed) { | ||
m.diskUsage.WithLabelValues(disk.Directory).Set(float64(disk.UsageBytes)) | ||
} |
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,6 @@ | ||
package disk | ||
|
||
type DiskUsed struct { | ||
Directory string | ||
UsageBytes int64 | ||
} |
Oops, something went wrong.