Exemplo n.º 1
0
func (job Job) StoreResult(res m.CheckEvalResult) {
	if !setting.WriteIndividualAlertResults {
		return
	}
	metrics := make([]*schema.MetricData, 3)
	metricNames := [3]string{"ok_state", "warn_state", "error_state"}
	for pos, state := range metricNames {
		metrics[pos] = &schema.MetricData{
			OrgId:      int(job.OrgId),
			Name:       fmt.Sprintf("health.%s.%s.%s", job.EndpointSlug, strings.ToLower(job.MonitorTypeName), state),
			Metric:     fmt.Sprintf("health.%s.%s", strings.ToLower(job.MonitorTypeName), state),
			Interval:   int(job.Freq),
			Value:      0.0,
			Unit:       "state",
			Time:       job.LastPointTs.Unix(),
			TargetType: "gauge",
			Tags: []string{
				fmt.Sprintf("endpoint_id:%d", job.EndpointId),
				fmt.Sprintf("monitor_id:%d", job.MonitorId),
			},
		}
	}
	if int(res) >= 0 {
		metrics[int(res)].Value = 1.0
	}
	metricpublisher.Publish(metrics)
}
Exemplo n.º 2
0
func (c *CollectorContext) OnResults(results []*schema.MetricData) {
	metricsRecvd.Inc(int64(len(results)))
	for _, r := range results {
		if !c.Collector.Public {
			r.OrgId = int(c.OrgId)
		}
	}
	metricpublisher.Publish(results)
}