Example #1
0
func timeAsString(gotime time.Time, unit units.Unit) string {
	var dur duration.Duration
	if !gotime.IsZero() {
		dur = duration.SinceEpoch(gotime)
	}
	return dur.StringUsingUnits(unit)
}
Example #2
0
func (m *Metric) convertToJson() {
	m.Value, m.Kind, m.SubType = asJson(m.Value, m.Kind, m.SubType, m.Unit)
	if m.TimeStamp == nil {
		m.TimeStamp = ""
	} else {
		m.TimeStamp = duration.SinceEpoch(m.TimeStamp.(time.Time)).String()
	}
}
Example #3
0
func (e *connectionErrorsType) Set(
	m *collector.Endpoint, err error, timestamp time.Time) {
	newError := &messages.Error{
		HostName:  m.HostName(),
		Timestamp: duration.SinceEpoch(timestamp).String(),
		Error:     err.Error(),
	}
	e.lock.Lock()
	defer e.lock.Unlock()
	e.errorMap[m] = newError
}
Example #4
0
func (m *Metric) convertToJson() {
	m.Value, m.Kind, m.SubType = asJson(m.Value, m.Kind, m.SubType, m.Unit)
	switch i := m.TimeStamp.(type) {
	case nil:
		m.TimeStamp = ""
	case time.Time:
		m.TimeStamp = duration.SinceEpoch(i).String()
	case string:
		// Do nothing we are already in json format
	default:
		m.TimeStamp = fmt.Sprintf("%v", i)
	}
}
Example #5
0
func timeToDuration(t time.Time) (result duration.Duration) {
	if t.IsZero() {
		return
	}
	return duration.SinceEpoch(t)
}