Created
November 28, 2016 12:19
-
-
Save johscheuer/7dbc435dc7591840508cb40559efea6e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func getHostnameFromConnection(connection, defaultHost string) string { | |
host, _, err := net.SplitHostPort(connection) | |
if err != nil { | |
host = defaultHost | |
fmt.Println(err) | |
} | |
return host | |
} | |
func (redisDB RedisDB) GetHealthStatus() map[string]string { | |
result := map[string]string{"self": okString} | |
hostname, err := os.Hostname() | |
if err != nil { //TODO we'll just ignore any errors :) | |
hostname = "UNKNOWN" | |
} | |
redisMasterHost := getHostnameFromConnection(redisDB.master, "redis-master") | |
redisSlaveHost := getHostnameFromConnection(redisDB.slave, "redis-slave") | |
var wg sync.WaitGroup | |
results := make(chan *checkConnectionResult, 2) | |
wg.Add(2) | |
go func() { | |
results <- checkConnections(redisMasterHost, hostname, redisDB.master, redisDB.masterPassword) | |
wg.Done() | |
}() | |
go func() { | |
results <- checkConnections(redisSlaveHost, hostname, redisDB.slave, redisDB.slavePassword) | |
wg.Done() | |
}() | |
wg.Wait() | |
close(results) | |
// Merge Results | |
for res := range results { | |
if res.name == redisMasterHost { | |
redisMastersTotal.WithLabelValues(hostname, redisDB.appVersion).Set(float64(res.total)) | |
redisMastersHealthyTotal.WithLabelValues(hostname, redisDB.appVersion).Set(float64(res.healthy)) | |
} | |
if res.name == redisSlaveHost { | |
redisSlavesTotal.WithLabelValues(hostname, redisDB.appVersion).Set(float64(res.total)) | |
redisSlavesHealthyTotal.WithLabelValues(hostname, redisDB.appVersion).Set(float64(res.healthy)) | |
} | |
for k, v := range res.results { | |
result[k] = v | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment