Esempio n. 1
0
func GetQuotas() {
	// Collect quotas and quota mememory data
	token := helpers.NewToken()
	quotas := token.GetQuotas()
	db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
	if err != nil {
		fmt.Println(err)
	}
	defer db.Close()
	for _, quota := range quotas.Resources {
		err = db.QueryRow(`
      INSERT INTO quotas(guid, name) VALUES($1, $2)`,
			quota.MetaData.Guid,
			quota.Entity.Name).Scan()
		if err != nil {
			fmt.Println(err)
		}
		err = db.QueryRow(
			"INSERT INTO quotadata(guid, memory, date) VALUES($1, $2, $3)",
			quota.MetaData.Guid,
			quota.Entity.MemoryLimit,
			time.Now().Format("2006-01-02")).Scan()
		if err != nil {
			fmt.Println(err)
		}
	}
}
Esempio n. 2
0
func main() {
	// Get Mongo session
	session := helpers.GetMongoSession()
	defer session.Close()
	collection := session.DB("cloudfoundry").C("events")
	// Make new token
	token := helpers.NewToken()
	// events Generator
	eventsGen := token.EventGen()
	// get event indefinitely
	endLoop := false
	for _ = range time.Tick(1 * time.Second) {
		apiResponse := eventsGen()
		if apiResponse.NextUrl == "" {
			// Break loop if there are no more urls
			break
		}
		for _, event := range apiResponse.Resources {
			info, err := collection.Upsert(event, event)
			if err != nil {
				log.Fatal(err)
			}
			if info.Updated == 1 {
				// Break loop if there are document exist in the database
				endLoop = true
				break
			}
		}
		if endLoop == true {
			break
		}
	}
}