<commit_before>package main

import (
	"fmt"
	"koding/db/models"
	"koding/db/mongodb/modelhelper"
)

// pops username from set in db and gets metrics for machines belonging
// to that user; it uses pop instead of find so multiple workers can
// work in parallel
func getAndSaveQueueMachineMetrics() error {
	var index = 0
	defer func() {
		Log.Debug("Fetched: %d entries for queued usernames", index)
	}()

	for {
		for _, metric := range metricsToSave {
			machines, err := popMachinesForMetricGet(metric.GetName())
			if err != nil {
				// ran out of usernames in queue, so return
				if isRedisRecordNil(err) {
					return nil
				}
			}

			if len(machines) == 0 {
				continue
			}

			for _, machine := range machines {
				err := metric.GetAndSaveData(machine.Credential)
				if err != nil {
					Log.Error(err.Error())
				}
			}
		}

		index += 1
	}

	return nil
}

func stopMachinesOverLimit() error {
	for _, metric := range metricsToSave {
		machines, err := metric.GetMachinesOverLimit()
		if err != nil {
			Log.Error(err.Error())
			continue
		}

		Log.Debug(
			"Fetched: %d machines that are overlimit for metric: %s",
			len(machines), metric.GetName(),
		)

		if len(machines) == 0 {
			continue
		}

		var stopSuccess = 0

		for _, machine := range machines {
			reason := fmt.Sprintf(
				"%v overlimit, allowed: %d", metric.GetName(), metric.GetLimit(),
			)

			err = stopVm(machine.ObjectId.Hex(), reason)
			if err != nil {
				Log.Error(err.Error())
				continue
			}

			stopSuccess += 1

			err := metric.RemoveUsername(machine.Credential)
			if err != nil {
				Log.Error(err.Error())
				continue
			}
		}
<commit_msg>vmwatcher: temporarily disable logs<commit_after>package main

import (
	"fmt"
	"koding/db/models"
	"koding/db/mongodb/modelhelper"
)

// pops username from set in db and gets metrics for machines belonging
// to that user; it uses pop instead of find so multiple workers can
// work in parallel
func getAndSaveQueueMachineMetrics() error {
	var index = 0
	defer func() {
		Log.Debug("Fetched: %d entries for queued usernames", index)
	}()

	for {
		for _, metric := range metricsToSave {
			machines, err := popMachinesForMetricGet(metric.GetName())
			if err != nil {
				// ran out of usernames in queue, so return
				if isRedisRecordNil(err) {
					return nil
				}
			}

			if len(machines) == 0 {
				continue
			}

			for _, machine := range machines {
				err := metric.GetAndSaveData(machine.Credential)
				if err != nil {
					Log.Error(err.Error())
				}
			}
		}

		index += 1
	}

	return nil
}

func stopMachinesOverLimit() error {
	for _, metric := range metricsToSave {
		machines, err := metric.GetMachinesOverLimit()
		if err != nil {
			Log.Error(err.Error())
			continue
		}

		Log.Debug(
			"Fetched: %d machines that are overlimit for metric: %s",
			len(machines), metric.GetName(),
		)

		if len(machines) == 0 {
			continue
		}

		var stopSuccess = 0

		for _, machine := range machines {
			reason := fmt.Sprintf(
				"%v overlimit, allowed: %d", metric.GetName(), metric.GetLimit(),
			)

			err = stopVm(machine.ObjectId.Hex(), reason)
			if err != nil {
				continue
			}

			stopSuccess += 1

			// err := metric.RemoveUsername(machine.Credential)
			// if err != nil {
			//   Log.Error(err.Error())
			//   continue
			// }
		}

{'fraction_non_alphanumeric': 0.12537764350453173, 'fraction_numerical': 0.0036253776435045317, 'mean_word_length': 2.832175925925926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2747234', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1091, 'n_words': 308}