Esempio n. 1
0
func (self *Sample) UnmarshalJSON(data []byte) error {
	var jsonMap map[string]interface{}
	dec := json.NewDecoder(bytes.NewReader(data))
	dec.UseNumber()
	if err := dec.Decode(&jsonMap); err != nil {
		return err
	}
	self.T, _ = jsonMap["t"].(net.Millis)
	switch value := jsonMap["v"].(type) {
	case json.Number:
		strRep := value.String()
		if strings.Contains(strRep, ".") {
			temp, _ := value.Float64()
			self.V = net.Float64(temp)
		} else {
			temp, _ := value.Int64()
			self.V = net.Int64(temp)
		}
	default:
		panic(value)
	}
	return nil
}
Esempio n. 2
0
func (self *Storage) selfMetricSendTask() {
	timestamp := net.Millis(time.Now().UnixNano() / 1e6)
	writeCommunicatorMetricValues := self.writeCommunicator.SelfMetricValues()

	seriesCommands := []*net.SeriesCommand{}
	for _, metricValue := range writeCommunicatorMetricValues {
		seriesCommand := net.NewSeriesCommand(self.selfMetricsEntity, self.metricPrefix+"."+metricValue.name, metricValue.value).
			SetTimestamp(timestamp)
		for name, val := range metricValue.tags {
			seriesCommand.SetTag(name, val)
		}
		seriesCommands = append(seriesCommands, seriesCommand)
	}

	seriesCommand := net.NewSeriesCommand(self.selfMetricsEntity, self.metricPrefix+".memstore.entities.count", net.Int64(self.memstore.EntitiesCount())).SetTimestamp(timestamp)
	seriesCommands = append(seriesCommands, seriesCommand)
	seriesCommand = net.NewSeriesCommand(self.selfMetricsEntity, self.metricPrefix+".memstore.messages.count", net.Int64(self.memstore.MessagesCount())).SetTimestamp(timestamp)
	seriesCommands = append(seriesCommands, seriesCommand)
	seriesCommand = net.NewSeriesCommand(self.selfMetricsEntity, self.metricPrefix+".memstore.properties.count", net.Int64(self.memstore.PropertiesCount())).SetTimestamp(timestamp)
	seriesCommands = append(seriesCommands, seriesCommand)
	seriesCommand = net.NewSeriesCommand(self.selfMetricsEntity, self.metricPrefix+".memstore.series-commands.count", net.Int64(self.memstore.SeriesCommandCount())).SetTimestamp(timestamp)
	seriesCommands = append(seriesCommands, seriesCommand)
	seriesCommand = net.NewSeriesCommand(self.selfMetricsEntity, self.metricPrefix+".memstore.size", net.Int64(self.memstore.Size())).SetTimestamp(timestamp)
	seriesCommands = append(seriesCommands, seriesCommand)
	self.writeCommunicator.PriorSendData(seriesCommands, nil, nil, nil)

}
func (self *NetworkCommunicator) SelfMetricValues() []*metricValue {
	metricValues := []*metricValue{}
	for i := range self.counters {
		metricValues = append(metricValues,
			&metricValue{
				name: "series-commands.sent",
				tags: map[string]string{
					"thread":    strconv.FormatInt(int64(i), 10),
					"transport": self.protocol,
				},
				value: atsdNet.Int64(atomic.LoadUint64(&self.counters[i].series.sent)),
			},
			&metricValue{
				name: "series-commands.dropped",
				tags: map[string]string{
					"thread":    strconv.FormatInt(int64(i), 10),
					"transport": self.protocol,
				},
				value: atsdNet.Int64(atomic.LoadUint64(&self.counters[i].series.dropped)),
			},
			&metricValue{
				name: "message-commands.sent",
				tags: map[string]string{
					"thread":    strconv.FormatInt(int64(i), 10),
					"transport": self.protocol,
				},
				value: atsdNet.Int64(atomic.LoadUint64(&self.counters[i].messages.sent)),
			},
			&metricValue{
				name: "message-commands.dropped",
				tags: map[string]string{
					"thread":    strconv.FormatInt(int64(i), 10),
					"transport": self.protocol,
				},
				value: atsdNet.Int64(atomic.LoadUint64(&self.counters[i].messages.dropped)),
			},
			&metricValue{
				name: "property-commands.sent",
				tags: map[string]string{
					"thread":    strconv.FormatInt(int64(i), 10),
					"transport": self.protocol,
				},
				value: atsdNet.Int64(atomic.LoadUint64(&self.counters[i].prop.sent)),
			},
			&metricValue{
				name: "property-commands.dropped",
				tags: map[string]string{
					"thread":    strconv.FormatInt(int64(i), 10),
					"transport": self.protocol,
				},
				value: atsdNet.Int64(atomic.LoadUint64(&self.counters[i].prop.dropped)),
			},
			&metricValue{
				name: "entitytag-commands.sent",
				tags: map[string]string{
					"thread":    strconv.FormatInt(int64(i), 10),
					"transport": self.protocol,
				},
				value: atsdNet.Int64(atomic.LoadUint64(&self.counters[i].entityTag.sent)),
			},
			&metricValue{
				name: "entitytag-commands.dropped",
				tags: map[string]string{
					"thread":    strconv.FormatInt(int64(i), 10),
					"transport": self.protocol,
				},
				value: atsdNet.Int64(atomic.LoadUint64(&self.counters[i].entityTag.dropped)),
			},
		)
	}
	return metricValues
}