Skip to content

Commit

Permalink
Exporter self metrics
Browse files Browse the repository at this point in the history
* Exporter Health metric is added(0 - Offline, 1 - Up but errors,
  2 - Up and All OK)
* Exporter local metrics(CPU percentage, Memory percentage and Uptime)
  added.

Updates: #15
Fixes: #16
Signed-off-by: Aravinda Vishwanathapura <[email protected]>
  • Loading branch information
aravindavk committed Aug 16, 2021
1 parent 392e6f2 commit 78e1fc0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ shards:

glustercli:
git: https://github.com/aravindavk/glustercli-crystal.git
version: 0.1.0+git.commit.b213b433ff886cc063c7fa3a0214212a7fcee3f3
version: 0.1.0+git.commit.01d9db7a282bbb8cba661a3be8adf01fa96fc70e

kemal:
git: https://github.com/kemalcr/kemal.git
Expand Down
20 changes: 16 additions & 4 deletions src/metrics/helpers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module GlusterMetricsExporter

property volumes = [] of GlusterCLI::VolumeInfo,
peers = [] of GlusterCLI::NodeInfo,
local_metrics = Hash(String, GlusterCLI::LocalMetrics).new
local_metrics = Hash(String, GlusterCLI::LocalMetrics).new,
exporter_health = Hash(String, Int32).new

def self.collect
data = MetricsData.new
Expand Down Expand Up @@ -34,9 +35,20 @@ module GlusterMetricsExporter
data.peers.each do |peer|
url = "http://#{peer.hostname}:#{GlusterMetricsExporter.config.port}/_api/local-metrics"
# TODO: Handle HTTP error and Connection refused errors
response = HTTP::Client.get url

data.local_metrics[peer.hostname] = GlusterCLI::LocalMetrics.from_json(response.body)
begin
response = HTTP::Client.get url
if response.status_code == 200
data.local_metrics[peer.hostname] = GlusterCLI::LocalMetrics.from_json(response.body)
data.exporter_health[peer.hostname] = 2
next
else
# Exporter is Up but error
data.exporter_health[peer.hostname] = 1
end
rescue Socket::ConnectError
# Exporter is Offline
data.exporter_health[peer.hostname] = 0
end
end

data
Expand Down
18 changes: 18 additions & 0 deletions src/metrics/local.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ module GlusterMetricsExporter
@@shd_memory_percentage = ShdGauge.new(:shd_memory_percentage, "Self Heal Daemon Memory Percentage")
@@shd_uptime_seconds = ShdGauge.new(:shd_uptime_seconds, "Self Heal Daemon Uptime in Seconds")

@@exporter_cpu_percentage = PeerGauge.new(:exporter_cpu_percentage, "Metrics Exporter CPU Percentage")
@@exporter_memory_percentage = PeerGauge.new(:exporter_memory_percentage, "Metrics Exporter Memory Percentage")
@@exporter_uptime_seconds = PeerGauge.new(:exporter_uptime_seconds, "Metrics Exporter Uptime in Seconds")
@@exporter_health = PeerGauge.new(:exporter_health, "Metrics Exporter Health")

def self.clear_local_metrics
@@brick_cpu_percentage.clear
@@brick_memory_percentage.clear
Expand All @@ -28,6 +33,10 @@ module GlusterMetricsExporter
@@shd_uptime_seconds.clear
@@node_uptime_seconds.clear
@@log_dir_size_bytes.clear
@@exporter_cpu_percentage.clear
@@exporter_memory_percentage.clear
@@exporter_uptime_seconds.clear
@@exporter_health.clear
end

handle_metrics(["local_metrics"]) do |metrics_data|
Expand Down Expand Up @@ -68,6 +77,8 @@ module GlusterMetricsExporter
hostname: peer.hostname,
}

# TODO: Handle the case when Metrics exporter is down or error

@@node_uptime_seconds[**peer_labels].set(metrics_data.local_metrics[peer.hostname].node_uptime_seconds)

log_labels = peer_labels.merge({path: "/var/log/glusterfs"})
Expand All @@ -86,6 +97,13 @@ module GlusterMetricsExporter
@@shd_memory_percentage[**shd_labels].set(shd.memory_percentage)
@@shd_uptime_seconds[**shd_labels].set(shd.uptime_seconds)
end

exporter_metrics = metrics_data.local_metrics[peer.hostname].exporter
@@exporter_cpu_percentage[**peer_labels].set(exporter_metrics.cpu_percentage)
@@exporter_memory_percentage[**peer_labels].set(exporter_metrics.memory_percentage)
@@exporter_uptime_seconds[**peer_labels].set(exporter_metrics.uptime_seconds)

@@exporter_health[**peer_labels].set(metrics_data.exporter_health[peer.hostname])
end
end
end

0 comments on commit 78e1fc0

Please sign in to comment.