Skip to content

Commit 2a9d303

Browse files
authored
Add system average load and memory metrics (#50)
* Add system load average and memory metrics to the exporter. * Add System Load Average and System Memory panels to the Grafana dashboard and update panel layout.
1 parent 4c212d3 commit 2a9d303

File tree

5 files changed

+280
-15
lines changed

5 files changed

+280
-15
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,20 @@ eventstore_tcp_connection_received_bytes{client_name="ES-8d3d28dd-7944-49b4-a130
260260
# TYPE eventstore_tcp_connection_sent_bytes counter
261261
eventstore_tcp_connection_sent_bytes{client_name="ES-8d3d28dd-7944-49b4-a130-686cc9aecc92",external="true",id="7d7f9762-9565-4cca-8bdf-2dc7c845c19a",local_endpoint="172.16.1.11:1113",remote_endpoint="172.16.1.1:59230",ssl="false"} 252635
262262
263+
# HELP eventstore_sys_free_memory_bytes System free memory in bytes
264+
# TYPE eventstore_sys_free_memory_bytes gauge
265+
eventstore_sys_free_memory_bytes 2.502856704e+09
266+
267+
# HELP eventstore_sys_total_memory_bytes System total memory in bytes
268+
# TYPE eventstore_sys_total_memory_bytes gauge
269+
eventstore_sys_total_memory_bytes 1.6656265216e+10
270+
271+
# HELP eventstore_sys_loadavg System load average
272+
# TYPE eventstore_sys_loadavg gauge
273+
eventstore_sys_loadavg{period="15m"} 0.35
274+
eventstore_sys_loadavg{period="1m"} 0.72
275+
eventstore_sys_loadavg{period="5m"} 0.52
276+
263277
# HELP eventstore_up Whether the EventStore scrape was successful
264278
# TYPE eventstore_up gauge
265279
eventstore_up 1

internal/client/server_stats.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ type TCPStats struct {
3131
}
3232

3333
type SystemStats struct {
34-
Drives map[string]DriveStats `json:"drive"`
34+
Drives map[string]DriveStats `json:"drive"`
35+
LoadAvg LoadAvgStats `json:"loadavg"`
36+
FreeMem int64 `json:"freeMem"`
37+
TotalMem int64 `json:"totalMem"`
38+
}
39+
40+
type LoadAvgStats struct {
41+
OneMin float64 `json:"1m"`
42+
FiveMin float64 `json:"5m"`
43+
FifteenMin float64 `json:"15m"`
3544
}
3645

3746
type DriveStats struct {

internal/collector/collector.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ type Collector struct {
3939
driveTotalBytes *prometheus.Desc
4040
driveAvailableBytes *prometheus.Desc
4141

42+
sysLoadAvg *prometheus.Desc
43+
sysFreeMemoryBytes *prometheus.Desc
44+
sysTotalMemoryBytes *prometheus.Desc
45+
4246
projectionRunning *prometheus.Desc
4347
projectionStatus *prometheus.Desc
4448
projectionProgress *prometheus.Desc
@@ -92,6 +96,10 @@ func NewCollector(config *config.Config, client *client.EventStoreStatsClient) *
9296
driveTotalBytes: prometheus.NewDesc("eventstore_drive_total_bytes", "Drive total size in bytes", []string{"drive"}, nil),
9397
driveAvailableBytes: prometheus.NewDesc("eventstore_drive_available_bytes", "Drive available bytes", []string{"drive"}, nil),
9498

99+
sysLoadAvg: prometheus.NewDesc("eventstore_sys_loadavg", "System load average", []string{"period"}, nil),
100+
sysFreeMemoryBytes: prometheus.NewDesc("eventstore_sys_free_memory_bytes", "System free memory in bytes", nil, nil),
101+
sysTotalMemoryBytes: prometheus.NewDesc("eventstore_sys_total_memory_bytes", "System total memory in bytes", nil, nil),
102+
95103
projectionRunning: prometheus.NewDesc("eventstore_projection_running", "If 1, projection is in 'Running' state", []string{"projection"}, nil),
96104
projectionStatus: prometheus.NewDesc("eventstore_projection_status", "If 1, projection is in specified state", []string{"projection", "status"}, nil),
97105
projectionProgress: prometheus.NewDesc("eventstore_projection_progress", "Projection progress 0 - 1, where 1 = projection progress at 100%", []string{"projection"}, nil),
@@ -144,6 +152,10 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
144152
ch <- c.driveTotalBytes
145153
ch <- c.driveAvailableBytes
146154

155+
ch <- c.sysLoadAvg
156+
ch <- c.sysFreeMemoryBytes
157+
ch <- c.sysTotalMemoryBytes
158+
147159
ch <- c.projectionRunning
148160
ch <- c.projectionStatus
149161
ch <- c.projectionProgress
@@ -190,6 +202,7 @@ func (c *Collector) collectFromStats(ch chan<- prometheus.Metric, stats *client.
190202
c.collectFromTCPConnectionStats(ch, stats.TCPConnections)
191203
c.collectFromQueueStats(ch, stats.Server.Es.Queues)
192204
c.collectFromDriveStats(ch, stats.Server.System.Drives)
205+
c.collectFromSystemStats(ch, stats.Server.System)
193206
c.collectFromProjectionStats(ch, stats.Projections)
194207
c.collectFromSubscriptionStats(ch, stats.Subscriptions)
195208
c.collectFromStreamStats(ch, stats.Streams)
@@ -240,6 +253,15 @@ func (c *Collector) collectFromDriveStats(ch chan<- prometheus.Metric, stats map
240253
}
241254
}
242255

256+
func (c *Collector) collectFromSystemStats(ch chan<- prometheus.Metric, stats client.SystemStats) {
257+
ch <- prometheus.MustNewConstMetric(c.sysLoadAvg, prometheus.GaugeValue, stats.LoadAvg.OneMin, "1m")
258+
ch <- prometheus.MustNewConstMetric(c.sysLoadAvg, prometheus.GaugeValue, stats.LoadAvg.FiveMin, "5m")
259+
ch <- prometheus.MustNewConstMetric(c.sysLoadAvg, prometheus.GaugeValue, stats.LoadAvg.FifteenMin, "15m")
260+
261+
ch <- prometheus.MustNewConstMetric(c.sysFreeMemoryBytes, prometheus.GaugeValue, float64(stats.FreeMem))
262+
ch <- prometheus.MustNewConstMetric(c.sysTotalMemoryBytes, prometheus.GaugeValue, float64(stats.TotalMem))
263+
}
264+
243265
func (c *Collector) collectFromProjectionStats(ch chan<- prometheus.Metric, stats []client.ProjectionStats) {
244266
for _, projection := range stats {
245267
running := 0.0

internal/server/server_basic_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func Test_BasicMetrics(t *testing.T) {
3030
assertHasMetric(t, metrics, "eventstore_disk_io_write_ops", "gauge")
3131
assertHasMetric(t, metrics, "eventstore_disk_io_written_bytes", "gauge")
3232
assertHasMetric(t, metrics, "eventstore_drive_available_bytes", "gauge")
33+
assertHasMetric(t, metrics, "eventstore_sys_loadavg", "gauge")
34+
assertHasMetric(t, metrics, "eventstore_sys_free_memory_bytes", "gauge")
35+
assertHasMetric(t, metrics, "eventstore_sys_total_memory_bytes", "gauge")
3336
assertHasMetric(t, metrics, "eventstore_process_cpu", "gauge")
3437
assertHasMetric(t, metrics, "eventstore_process_memory_bytes", "gauge")
3538
assertHasMetric(t, metrics, "eventstore_queue_items_processed_total", "counter")

0 commit comments

Comments
 (0)