Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat(redis): collect master link status (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Sep 26, 2022
1 parent 2ab28b3 commit 41b5955
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ It collects information and statistics about the server executing the following
### Replication

- Connected replicas in `replicas`
- Master link status in `status`
- Time elapsed since the last interaction with master in `seconds`
- Time elapsed since the link between master and slave is down in `seconds`

Expand Down
13 changes: 13 additions & 0 deletions modules/redis/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
prioNet

prioConnectedReplicas
prioMasterLinkStatus
prioMasterLastIOSinceTime
prioMasterLinkDownSinceTime

Expand Down Expand Up @@ -331,6 +332,18 @@ var (
{ID: "connected_slaves", Name: "connected"},
},
}
masterLinkStatusChart = module.Chart{
ID: "master_last_status",
Title: "Master link status",
Units: "status",
Fam: "replication",
Ctx: "redis.master_link_status",
Priority: prioMasterLinkStatus,
Dims: module.Dims{
{ID: "master_link_status_up", Name: "up"},
{ID: "master_link_status_down", Name: "down"},
},
}
masterLastIOSinceTimeChart = module.Chart{
ID: "master_last_io_since_time",
Title: "Time elapsed since the last interaction with master",
Expand Down
13 changes: 13 additions & 0 deletions modules/redis/collect_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func (r *Redis) collectInfo(mx map[string]int64, info string) {
mx[field] = int64(time.Since(time.Unix(v, 0)).Seconds())
case field == "aof_enabled" && value == "1":
r.addAOFChartsOnce.Do(r.addAOFCharts)
case field == "master_link_status":
mx["master_link_status_up"] = boolToInt(value == "up")
mx["master_link_status_down"] = boolToInt(value == "down")
default:
collectNumericValue(mx, field, value)
}
Expand Down Expand Up @@ -227,6 +230,9 @@ func (r *Redis) addAOFCharts() {
}

func (r *Redis) addReplSlaveCharts() {
if err := r.Charts().Add(masterLinkStatusChart.Copy()); err != nil {
r.Warningf("error on adding '%s' chart", masterLinkStatusChart.ID)
}
if err := r.Charts().Add(masterLastIOSinceTimeChart.Copy()); err != nil {
r.Warningf("error on adding '%s' chart", masterLastIOSinceTimeChart.ID)
}
Expand All @@ -243,3 +249,10 @@ func has(m map[string]int64, key string, keys ...string) bool {
return ok && has(m, keys[0], keys[1:]...)
}
}

func boolToInt(v bool) int64 {
if v {
return 1
}
return 0
}

0 comments on commit 41b5955

Please sign in to comment.