func (e *Exporter) scrapeMeter(key string, json *gabs.Container) (bool, error) {
	count, ok := json.Path("count").Data().(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad meter! %s has no count\n", key))
	}
	units, ok := json.Path("units").Data().(string)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad meter! %s has no units\n", key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(meterHelp, key, units)
	counter, new := e.Counters.Fetch(name+"_count", help)
	counter.WithLabelValues().Set(count)

	gauge, _ := e.Gauges.Fetch(name, help, "rate")
	properties, _ := json.ChildrenMap()
	for key, property := range properties {
		if strings.Contains(key, "rate") {
			if value, ok := property.Data().(float64); ok {
				gauge.WithLabelValues(renameRate(key)).Set(value)
			}
		}
	}

	return new, nil
}
func (e *Exporter) scrapeTimer(key string, json *gabs.Container) (bool, error) {
	count, ok := json.Path("count").Data().(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad timer! %s has no count\n", key))
	}
	units, ok := json.Path("rate_units").Data().(string)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad timer! %s has no units\n", key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(timerHelp, key, units)
	counter, new := e.Counters.Fetch(name+"_count", help)
	counter.WithLabelValues().Set(count)

	rates, _ := e.Gauges.Fetch(name+"_rate", help, "rate")
	percentiles, _ := e.Gauges.Fetch(name, help, "percentile")
	min, _ := e.Gauges.Fetch(name+"_min", help)
	max, _ := e.Gauges.Fetch(name+"_max", help)
	mean, _ := e.Gauges.Fetch(name+"_mean", help)
	stddev, _ := e.Gauges.Fetch(name+"_stddev", help)

	properties, _ := json.ChildrenMap()
	for key, property := range properties {
		switch key {
		case "mean_rate", "m1_rate", "m5_rate", "m15_rate":
			if value, ok := property.Data().(float64); ok {
				rates.WithLabelValues(renameRate(key)).Set(value)
			}

		case "p50", "p75", "p95", "p98", "p99", "p999":
			if value, ok := property.Data().(float64); ok {
				percentiles.WithLabelValues("0." + key[1:]).Set(value)
			}
		case "min":
			if value, ok := property.Data().(float64); ok {
				min.WithLabelValues().Set(value)
			}
		case "max":
			if value, ok := property.Data().(float64); ok {
				max.WithLabelValues().Set(value)
			}
		case "mean":
			if value, ok := property.Data().(float64); ok {
				mean.WithLabelValues().Set(value)
			}
		case "stddev":
			if value, ok := property.Data().(float64); ok {
				stddev.WithLabelValues().Set(value)
			}
		}
	}

	return new, nil
}
func (e *Exporter) scrapeGauge(key string, json *gabs.Container) (bool, error) {
	data := json.Path("value").Data()
	value, ok := data.(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for gauge %s\n", data, key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(gaugeHelp, key)
	gauge, new := e.Gauges.Fetch(name, help)
	gauge.WithLabelValues().Set(value)
	return new, nil
}
func (e *Exporter) scrapeCounter(key string, json *gabs.Container) (bool, error) {
	data := json.Path("count").Data()
	count, ok := data.(float64)
	if !ok {
		return false, errors.New(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for counter %s\n", data, key))
	}

	name := renameMetric(key)
	help := fmt.Sprintf(counterHelp, key)
	counter, new := e.Counters.Fetch(name, help)
	counter.WithLabelValues().Set(count)
	return new, nil
}
func (svc *Service) ExtractAndCheckToken(so socketio.Socket, g *gabs.Container) (string, bool) {
	if g.Path("t").Data() == nil {
		so.Emit("auth_error", "Missing Token")
		return "", false
	}

	uid, err := svc.ValidateUserToken(nil, g.Path("t").Data().(string))
	if err != nil {
		so.Emit("auth_error", "Invalid Token")
		return "", false
	}

	return uid, true
}
Exemple #6
0
func documentFromHit(hit *gabs.Container) *Document {
	return &Document{
		Index:  hit.Path("_index").Data().(string),
		Type:   hit.Path("_type").Data().(string),
		Id:     hit.Path("_id").Data().(string),
		source: []byte(hit.Path("_source").String()),
	}
}
// signupHandler controls the signup and user profile update forms
func signupHandler(w http.ResponseWriter, r *http.Request) {
	if strings.ToUpper(r.Method) == "POST" {
		invite, ok := service.Invites[r.FormValue("invite")]
		tokenenc := r.FormValue("token")

		var token *gabs.Container

		if ok {
			delete(service.Invites, r.FormValue("invite"))
			token, _ = assemble.CreateNewUserToken(
				r.FormValue("nick"),
				r.FormValue("name"),
				r.FormValue("email"),
				r.FormValue("phone"),
				r.FormValue("url"),
				r.FormValue("desc"),
				r.FormValue("avatar"),
				r.FormValue("alertaddress"))
		} else if tokenenc != "" {
			uid, tokerr := service.ValidateUserToken(nil, tokenenc)
			if tokerr == nil {
				privid := service.Users[uid].Token.Path("privid").Data().(string)
				token, _ = assemble.CreateUpdatedUserToken(
					r.FormValue("nick"),
					r.FormValue("name"),
					r.FormValue("email"),
					r.FormValue("phone"),
					r.FormValue("url"),
					r.FormValue("desc"),
					r.FormValue("avatar"),
					r.FormValue("alertaddress"),
					uid, privid)

				log.Println(uid, "updated user token")
			} else {
				tokenenc = ""
			}
		}

		if ok || tokenenc != "" {

			competok := utils.Compress([]byte(token.String()))
			etok, _ := utils.Encrypt(service.UserKey, competok.Bytes())

			service.AddToRoom(nil, token.Path("uid").Data().(string), "lobby")

			//TODO use templates
			fmt.Fprintf(w, `<html>`)
			fmt.Fprintf(w, `<meta http-equiv="refresh" content="10; url=/#%s">`, base64.StdEncoding.EncodeToString(etok))
			if ok {
				fmt.Fprintf(w, `<strong>SUCCESS!</strong> `+invite+`<br><br>`)
			} else {
				fmt.Fprintf(w, `<strong>Delete your old login bookmark and close the window or you will still be using your old profile!</strong><br><br>`)
			}
			//fmt.Fprintf(w, "Token (KEEP THIS SOMEWHERE SAFE OR SAVE THE LOGIN LINK): <br><textarea rows='10' cols='60'>%s</textarea><br><br>", base64.StdEncoding.EncodeToString(etok))
			fmt.Fprintf(w, "<a href='/#%s' target='_blank'>Assemble Chat Login - CLICK HERE AND BOOKMARK THE CHAT!</a> <strong>DO NOT SHARE THIS LINK</strong>", base64.StdEncoding.EncodeToString(etok))
			fmt.Fprintf(w, "<br>You will automatically enter the chat in 10 seconds...")
			fmt.Fprintf(w, `</html>`)
		} else {
			fmt.Fprintf(w, `Invalid Invite ID or Token`)
		}
	} else {
		fc, _ := ioutil.ReadFile("./static/signup.html")
		if fc != nil {
			fmt.Fprintf(w, string(fc[:]))
		}
	}
}
func cleanToken(token *gabs.Container) {
	token.SetP(html.EscapeString(token.Path("nick").Data().(string)), "nick")
	token.SetP(html.EscapeString(token.Path("uid").Data().(string)), "uid")
	token.SetP(html.EscapeString(token.Path("name").Data().(string)), "name")
	token.SetP(html.EscapeString(token.Path("email").Data().(string)), "email")
	token.SetP(html.EscapeString(token.Path("phone").Data().(string)), "phone")
	token.SetP(html.EscapeString(token.Path("url").Data().(string)), "url")
	token.SetP(html.EscapeString(token.Path("desc").Data().(string)), "desc")
	token.SetP(html.EscapeString(token.Path("avatar").Data().(string)), "avatar")
}