...

Source file src/edge-infra.dev/hack/observability/billing/billing.go

Documentation: edge-infra.dev/hack/observability/billing

     1  /*
     2  Some hack code which can make multiple calls to the
     3  log and metric cost utilities used by the cmd/billman cli.
     4  Useful if you have a set of cluster ids that you want to
     5  get the estimated costs for all in one shot. The edge sql
     6  db is not called with this script so dummy entries are used
     7  for cluster name, banner name and project id.
     8  */
     9  package main
    10  
    11  import (
    12  	"fmt"
    13  
    14  	"edge-infra.dev/pkg/edge/monitoring/billman/costs"
    15  	"edge-infra.dev/pkg/edge/monitoring/billman/edgesql"
    16  	"edge-infra.dev/pkg/edge/monitoring/billman/gcp"
    17  )
    18  
    19  func main() {
    20  	// cluster ids from the observability banner
    21  	clusterList := []string{"b25b1cc0-7c5a-4a29-90d3-f4382ac80dd1", "d4fd43da-a0eb-4ff0-96d6-f9ade869c972", "d362c9da-cd5a-4b5b-b42b-b50cf776798e", "cb817f19-42f6-4996-9727-5260ce6ec327", "6652cc1f-5163-4809-8ba2-5c1cf75ea955", "e01afc12-8893-4bb9-8ed9-14e6b1d3a377", "d132ccdf-f959-4493-a140-ac46994f1868", "34446988-9e92-4daa-852a-f22f97302cb9", "9e872b32-6478-43e7-a6dc-2c87bb5b834d", "e527579d-f011-45a8-bbd4-1cd2ba9f411a", "6a6712c4-58a0-4276-9761-ba5029d6d197", "8b3148d4-64f1-4eff-9a55-4fc4f77cda94", "a33b0692-26cf-4cd4-b1d8-9f7fe4459422", "940bf04b-409a-4034-9875-7c9898be1be7"}
    22  	topLevelProject := "ret-edge-dev0-foreman"
    23  	period := "1w"
    24  	logRate := .50
    25  	metricRate := .060
    26  	container := "k8s_container"
    27  	node := "k8s_node"
    28  	options := costs.Options{
    29  		Output:         "csv", // csv, tab
    30  		ShowDisclaimer: false,
    31  		ShowHeader:     false,
    32  	}
    33  
    34  	for _, c := range clusterList {
    35  		cluster := edgesql.EdgeCluster{
    36  			ClusterEdgeID: c,
    37  			ClusterName:   "unknown",
    38  			ProjectID:     "ret-edge-3u27t1ttkk4ngtkmk842b",
    39  			BannerName:    "observability",
    40  		}
    41  
    42  		bytesContainer, err := gcp.GetLogBytes(topLevelProject, cluster.ClusterEdgeID, period, container)
    43  		if err != nil {
    44  			return
    45  		}
    46  		bytesNode, err := gcp.GetLogBytes(topLevelProject, cluster.ClusterEdgeID, period, node)
    47  		if err != nil {
    48  			return
    49  		}
    50  		lcd := costs.LogContainerData{
    51  			Bytes: bytesContainer,
    52  			Cost:  costs.LogCosts(bytesContainer, logRate),
    53  		}
    54  		lnd := costs.LogNodeData{
    55  			Bytes: bytesNode,
    56  			Cost:  costs.LogCosts(bytesNode, logRate),
    57  		}
    58  		ld := costs.LogData{
    59  			Bytes: lcd.Bytes + lnd.Bytes,
    60  			Cost:  lcd.Cost + lnd.Cost,
    61  		}
    62  
    63  		samples, err := gcp.GetMetricSamples(topLevelProject, cluster.ClusterEdgeID, period)
    64  		if err != nil {
    65  			fmt.Println(err)
    66  		}
    67  		md := costs.MetricData{
    68  			Samples: samples,
    69  			Cost:    costs.MetricCosts(samples, metricRate),
    70  		}
    71  		b := costs.Billing{
    72  			Cluster:          cluster,
    73  			LogContainerData: lcd,
    74  			LogNodeData:      lnd,
    75  			LogData:          ld,
    76  			MetricData:       md,
    77  			Options:          options,
    78  			DisplayType:      "all",
    79  		}
    80  		costs.PrintClusterCosts(b)
    81  	}
    82  }
    83  

View as plain text