Skip to content

Commit

Permalink
[vin/rey] Refactor metrics and lxc service list
Browse files Browse the repository at this point in the history
  • Loading branch information
Reynaldi Ananda Pane authored and Reynaldi Ananda Pane committed Aug 28, 2018
1 parent d9d43aa commit ba4dfbc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lxc_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (l *lxcService) updateStatusByID(db *sqlx.DB) error {
}

func (l *lxcService) getLxcServicesListByLxcID(db *sqlx.DB) ([]lxcService, error) {
rows, err := db.Queryx("SELECT id, service, lxc_id, lxc_port, lxd_id, lxd_port, lxc_name, status, lxd_address FROM lxc_services WHERE lxc_id=$1", l.LxcID)
rows, err := db.Queryx("SELECT id, service, lxc_id, lxc_port, lxd_id, lxd_port, lxc_name, status, lxd_name, lxd_address FROM lxc_services WHERE lxc_id=$1", l.LxcID)
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -55,7 +56,7 @@ type metricsDB interface {
type prometheusMetricsDB struct{}

func (p prometheusMetricsDB) callMetricAPI(query string) (*promResponse, error) {
prometheusAddress := "172.28.128.5"
prometheusAddress := os.Getenv("PROMETHEUS_ADDRESS")
url := fmt.Sprintf("http://%s:9090/api/v1/query", prometheusAddress)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
Expand Down Expand Up @@ -108,7 +109,7 @@ func (p prometheusMetricsDB) getLowestLoadLxdInstance(weight string, weightValue
}

func (p prometheusMetricsDB) getFreeMemory() (*promResponse, error) {
return p.callMetricAPI("100 * (((avg_over_time(node_memory_MemFree_bytes[24h]) + avg_over_time(node_memory_Cached_bytes[24h]) + avg_over_time(node_memory_Buffers_bytes[24h])) / avg_over_time(node_memory_MemTotal_bytes[24h])))")
return p.callMetricAPI("100 * (((avg_over_time(node_memory_MemFree_bytes[1h]) + avg_over_time(node_memory_Cached_bytes[1h]) + avg_over_time(node_memory_Buffers_bytes[1h])) / avg_over_time(node_memory_MemTotal_bytes[1h])))")
}

func (p prometheusMetricsDB) getCpuUsage() (*promResponse, error) {
Expand All @@ -124,8 +125,6 @@ func calculateMetrics(memResult, cpuResult, storageResult promResponse, scoringW

log.Infof("array length: %d", len(memoryScores))
for i := 0; i < len(memoryScores); i++ {
log.Infof("memoryScore arr: %s for i: %d", memoryScores[i], i)
log.Infof("cpuScore arr: %s for i: %d", cpuScores[i], i)
address := memoryScores[i].Metric.Instance
strMemScore := memoryScores[i].Value[1].(string)
strCpuScore := cpuScores[i].Value[1].(string)
Expand Down

0 comments on commit ba4dfbc

Please sign in to comment.