parent
b792c45921
commit
411baa4dcf
|
@ -56,7 +56,7 @@ cscli hub update # Download list of available configurations from the hub
|
||||||
log.Info(v)
|
log.Info(v)
|
||||||
}
|
}
|
||||||
cwhub.DisplaySummary()
|
cwhub.DisplaySummary()
|
||||||
ListItems([]string{cwhub.PARSERS, cwhub.COLLECTIONS, cwhub.SCENARIOS, cwhub.PARSERS_OVFLW}, args, true, false)
|
ListItems([]string{cwhub.COLLECTIONS, cwhub.PARSERS, cwhub.SCENARIOS, cwhub.PARSERS_OVFLW}, args, true, false)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmdHubList.PersistentFlags().BoolVarP(&all, "all", "a", false, "List disabled items as well")
|
cmdHubList.PersistentFlags().BoolVarP(&all, "all", "a", false, "List disabled items as well")
|
||||||
|
|
|
@ -74,7 +74,11 @@ func metricsToTable(table *tablewriter.Table, stats map[string]map[string]int, k
|
||||||
row = append(row, alabel) //name
|
row = append(row, alabel) //name
|
||||||
for _, sl := range keys {
|
for _, sl := range keys {
|
||||||
if v, ok := astats[sl]; ok && v != 0 {
|
if v, ok := astats[sl]; ok && v != 0 {
|
||||||
row = append(row, fmt.Sprintf("%d", v))
|
numberToShow := fmt.Sprintf("%d", v)
|
||||||
|
if !noUnit {
|
||||||
|
numberToShow = formatNumber(v)
|
||||||
|
}
|
||||||
|
row = append(row, numberToShow)
|
||||||
} else {
|
} else {
|
||||||
row = append(row, "-")
|
row = append(row, "-")
|
||||||
}
|
}
|
||||||
|
@ -327,31 +331,38 @@ func ShowPrometheus(url string) {
|
||||||
|
|
||||||
if bucketsTable.NumLines() > 0 {
|
if bucketsTable.NumLines() > 0 {
|
||||||
log.Printf("Buckets Metrics:")
|
log.Printf("Buckets Metrics:")
|
||||||
|
bucketsTable.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
bucketsTable.Render()
|
bucketsTable.Render()
|
||||||
}
|
}
|
||||||
if acquisTable.NumLines() > 0 {
|
if acquisTable.NumLines() > 0 {
|
||||||
log.Printf("Acquisition Metrics:")
|
log.Printf("Acquisition Metrics:")
|
||||||
|
acquisTable.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
acquisTable.Render()
|
acquisTable.Render()
|
||||||
}
|
}
|
||||||
if parsersTable.NumLines() > 0 {
|
if parsersTable.NumLines() > 0 {
|
||||||
log.Printf("Parser Metrics:")
|
log.Printf("Parser Metrics:")
|
||||||
|
parsersTable.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
parsersTable.Render()
|
parsersTable.Render()
|
||||||
}
|
}
|
||||||
if lapiTable.NumLines() > 0 {
|
if lapiTable.NumLines() > 0 {
|
||||||
log.Printf("Local Api Metrics:")
|
log.Printf("Local Api Metrics:")
|
||||||
|
lapiTable.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
lapiTable.Render()
|
lapiTable.Render()
|
||||||
}
|
}
|
||||||
if lapiMachinesTable.NumLines() > 0 {
|
if lapiMachinesTable.NumLines() > 0 {
|
||||||
log.Printf("Local Api Machines Metrics:")
|
log.Printf("Local Api Machines Metrics:")
|
||||||
|
lapiMachinesTable.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
lapiMachinesTable.Render()
|
lapiMachinesTable.Render()
|
||||||
}
|
}
|
||||||
if lapiBouncersTable.NumLines() > 0 {
|
if lapiBouncersTable.NumLines() > 0 {
|
||||||
log.Printf("Local Api Bouncers Metrics:")
|
log.Printf("Local Api Bouncers Metrics:")
|
||||||
|
lapiBouncersTable.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
lapiBouncersTable.Render()
|
lapiBouncersTable.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
if lapiDecisionsTable.NumLines() > 0 {
|
if lapiDecisionsTable.NumLines() > 0 {
|
||||||
log.Printf("Local Api Bouncers Decisions:")
|
log.Printf("Local Api Bouncers Decisions:")
|
||||||
|
lapiDecisionsTable.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||||
lapiDecisionsTable.Render()
|
lapiDecisionsTable.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,6 +385,8 @@ func ShowPrometheus(url string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var noUnit bool
|
||||||
|
|
||||||
func NewMetricsCmd() *cobra.Command {
|
func NewMetricsCmd() *cobra.Command {
|
||||||
/* ---- UPDATE COMMAND */
|
/* ---- UPDATE COMMAND */
|
||||||
var cmdMetrics = &cobra.Command{
|
var cmdMetrics = &cobra.Command{
|
||||||
|
@ -404,6 +417,7 @@ func NewMetricsCmd() *cobra.Command {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmdMetrics.PersistentFlags().StringVarP(&prometheusURL, "url", "u", "", "Prometheus url (http://<ip>:<port>/metrics)")
|
cmdMetrics.PersistentFlags().StringVarP(&prometheusURL, "url", "u", "", "Prometheus url (http://<ip>:<port>/metrics)")
|
||||||
|
cmdMetrics.PersistentFlags().BoolVar(&noUnit, "no-unit", false, "Show the real number instead of formatted with units")
|
||||||
|
|
||||||
return cmdMetrics
|
return cmdMetrics
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -122,7 +123,13 @@ func ListItems(itemTypes []string, args []string, showType bool, showHeader bool
|
||||||
}
|
}
|
||||||
|
|
||||||
if csConfig.Cscli.Output == "human" {
|
if csConfig.Cscli.Output == "human" {
|
||||||
for itemType, statuses := range hubStatusByItemType {
|
for _, itemType := range itemTypes {
|
||||||
|
var statuses []cwhub.ItemHubStatus
|
||||||
|
var ok bool
|
||||||
|
if statuses, ok = hubStatusByItemType[itemType]; !ok {
|
||||||
|
log.Errorf("unknown item type: %s", itemType)
|
||||||
|
continue
|
||||||
|
}
|
||||||
fmt.Println(strings.ToUpper(itemType))
|
fmt.Println(strings.ToUpper(itemType))
|
||||||
table := tablewriter.NewWriter(os.Stdout)
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
table.SetCenterSeparator("")
|
table.SetCenterSeparator("")
|
||||||
|
@ -154,7 +161,13 @@ func ListItems(itemTypes []string, args []string, showType bool, showHeader bool
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
for itemType, statuses := range hubStatusByItemType {
|
for _, itemType := range itemTypes {
|
||||||
|
var statuses []cwhub.ItemHubStatus
|
||||||
|
var ok bool
|
||||||
|
if statuses, ok = hubStatusByItemType[itemType]; !ok {
|
||||||
|
log.Errorf("unknown item type: %s", itemType)
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, status := range statuses {
|
for _, status := range statuses {
|
||||||
if status.LocalVersion == "" {
|
if status.LocalVersion == "" {
|
||||||
status.LocalVersion = "n/a"
|
status.LocalVersion = "n/a"
|
||||||
|
@ -745,3 +758,52 @@ func BackupHub(dirPath string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type unit struct {
|
||||||
|
value int
|
||||||
|
symbol string
|
||||||
|
}
|
||||||
|
|
||||||
|
var ranges = []unit{
|
||||||
|
{
|
||||||
|
value: 1e18,
|
||||||
|
symbol: "E",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 1e15,
|
||||||
|
symbol: "P",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 1e12,
|
||||||
|
symbol: "T",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 1e6,
|
||||||
|
symbol: "M",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 1e3,
|
||||||
|
symbol: "k",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 1,
|
||||||
|
symbol: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatNumber(num int) string {
|
||||||
|
goodUnit := unit{}
|
||||||
|
for _, u := range ranges {
|
||||||
|
if num >= u.value {
|
||||||
|
goodUnit = u
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if goodUnit.value == 1 {
|
||||||
|
return fmt.Sprintf("%d%s", num, goodUnit.symbol)
|
||||||
|
}
|
||||||
|
|
||||||
|
res := math.Round(float64(num)/float64(goodUnit.value)*100) / 100
|
||||||
|
return fmt.Sprintf("%.2f%s", res, goodUnit.symbol)
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cwhub
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
//"errors"
|
//"errors"
|
||||||
|
@ -284,5 +285,6 @@ func GetHubStatusForItemType(itemType string, name string, all bool) []ItemHubSt
|
||||||
//Check the item status
|
//Check the item status
|
||||||
ret = append(ret, item.toHubStatus())
|
ret = append(ret, item.toHubStatus())
|
||||||
}
|
}
|
||||||
|
sort.Slice(ret, func(i, j int) bool { return ret[i].Name < ret[j].Name })
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue