Skip to content

Commit 33fc8f9

Browse files
committed
add 'apatit_mp_data_status' metric
1 parent c43e1fe commit 33fc8f9

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

internal/exporter/exporter.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ func (e *Exporter) RefreshMetrics() ([]prometheus.Labels, error) {
158158
// check monitoring point status and set it as ZERO if it was incorrect
159159
if item.Status > 1 || item.Status < 0 {
160160
e.log.WithFields(
161-
logrus.Fields{"mp_id": item.ID, "mp_name": item.Name}).Errorf("incorrect monitoring points status: %d", item.Status)
161+
logrus.Fields{
162+
"mp_id": item.ID,
163+
"mp_name": item.Name,
164+
"status": item.Status,
165+
}).Errorf("incorrect monitoring points status: %d", item.Status)
162166
item.Status = 0
163167
}
164168

@@ -186,8 +190,21 @@ func (e *Exporter) processTaskStatResults(taskStatResults *client.TaskStatEntry)
186190
// processTaskStatGraphResultItem processes one record (monitoring point) and updates metrics.
187191
func (e *Exporter) processTaskStatGraphResultItem(item *client.MonitoringPointEntry, refreshStartTime time.Time) []prometheus.Labels {
188192
if len(item.Result) == 0 {
193+
locationName := item.Name
194+
if e.Config.EngMPNames {
195+
locationName = translator.GetEngLocation(item.Name)
196+
}
197+
MPDataStatus.WithLabelValues(
198+
strconv.Itoa(e.taskInfo.ID),
199+
e.taskInfo.ServiceName,
200+
item.ID,
201+
locationName,
202+
).Set(0)
203+
189204
e.log.WithFields(
190-
logrus.Fields{"mp_id": item.ID, "mp_name": item.Name}).Warn("No results found for MP")
205+
logrus.Fields{
206+
"mp_id": item.ID,
207+
"mp_name": item.Name}).Warn("No results found for MP")
191208
return nil
192209
}
193210

@@ -198,6 +215,14 @@ func (e *Exporter) processTaskStatGraphResultItem(item *client.MonitoringPointEn
198215
e.updateMetrics(res, labels, item.Status, refreshStartTime)
199216
processedLabels = append(processedLabels, labels)
200217
}
218+
219+
MPDataStatus.WithLabelValues(
220+
strconv.Itoa(e.taskInfo.ID),
221+
e.taskInfo.ServiceName,
222+
item.ID,
223+
processedLabels[0][LabelMPName],
224+
).Set(1)
225+
201226
return processedLabels
202227
}
203228

internal/exporter/metrics.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,22 @@ var (
9696
prometheus.GaugeOpts{
9797
Namespace: namespace,
9898
Subsystem: subsystemMP,
99-
Name: "status",
99+
Name: "mp_status",
100100
Help: "Status of the monitoring point (1 = up/processed, 0 = stale/down).",
101101
},
102102
mpLabels,
103103
)
104104

105+
MPDataStatus = prometheus.NewGaugeVec(
106+
prometheus.GaugeOpts{
107+
Namespace: namespace,
108+
Subsystem: subsystemMP,
109+
Name: "data_status",
110+
Help: "Status of the data for the monitoring point (1 = has data, 0 = no data).",
111+
},
112+
[]string{LabelTaskID, LabelTaskName, LabelMPID, LabelMPName},
113+
)
114+
105115
MPConnectSeconds = prometheus.NewGaugeVec(
106116
prometheus.GaugeOpts{
107117
Namespace: namespace,
@@ -192,6 +202,7 @@ func RegisterMetrics() {
192202
ELoopsTotal,
193203
EErrorsTotal,
194204
MPStatus,
205+
MPDataStatus,
195206
MPConnectSeconds,
196207
MPDNSLookupSeconds,
197208
MPServerProcessingSeconds,
@@ -206,6 +217,7 @@ func RegisterMetrics() {
206217
// DeleteSeries deletes "Monitoring Point" related metrics
207218
func DeleteSeries(labels prometheus.Labels) {
208219
MPStatus.Delete(labels)
220+
MPDataStatus.Delete(labels)
209221
MPConnectSeconds.Delete(labels)
210222
MPDNSLookupSeconds.Delete(labels)
211223
MPServerProcessingSeconds.Delete(labels)

0 commit comments

Comments
 (0)