Skip to content

Commit 92182ca

Browse files
authored
add new stats (#79)
* add new stats Signed-off-by: John Seekins <jseekins@datto.com> * add debug logging about bad metrics Signed-off-by: John Seekins <jseekins@datto.com>
1 parent 8d4d51d commit 92182ca

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

handlers.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package main
1616

1717
import (
18+
"fmt"
1819
"io/ioutil"
1920
"net/http"
2021

@@ -68,14 +69,17 @@ func receiveHandler(producer *kafka.Producer, serializer Serializer) func(c *gin
6869
Topic: &t,
6970
}
7071
for _, metric := range metrics {
72+
objectsWritten.Add(float64(1))
7173
err := producer.Produce(&kafka.Message{
7274
TopicPartition: part,
7375
Value: metric,
7476
}, nil)
7577

7678
if err != nil {
79+
objectsFailed.Add(float64(1))
7780
c.AbortWithStatus(http.StatusInternalServerError)
78-
logrus.WithError(err).Error("couldn't produce message in kafka")
81+
logrus.WithError(err).Debug(fmt.Sprintf("Failing metric %v", metric))
82+
logrus.WithError(err).Error(fmt.Sprintf("couldn't produce message in kafka topic %v", topic))
7983
return
8084
}
8185
}

metrics.go

+36
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,44 @@ var (
2222
Name: "http_requests_total",
2323
Help: "Count of all http requests",
2424
})
25+
promBatches = prometheus.NewCounter(
26+
prometheus.CounterOpts{
27+
Name: "incoming_prometheus_batches_total",
28+
Help: "Count of incoming prometheus batches (to be broken into individual metrics)",
29+
})
30+
serializeTotal = prometheus.NewCounter(
31+
prometheus.CounterOpts{
32+
Name: "serialized_total",
33+
Help: "Count of all serialization requests",
34+
})
35+
serializeFailed = prometheus.NewCounter(
36+
prometheus.CounterOpts{
37+
Name: "serialized_failed_total",
38+
Help: "Count of all serialization failures",
39+
})
40+
objectsFiltered = prometheus.NewCounter(
41+
prometheus.CounterOpts{
42+
Name: "objects_filtered_total",
43+
Help: "Count of all filter attempts",
44+
})
45+
objectsWritten = prometheus.NewCounter(
46+
prometheus.CounterOpts{
47+
Name: "objects_written_total",
48+
Help: "Count of all objects written to Kafka",
49+
})
50+
objectsFailed = prometheus.NewCounter(
51+
prometheus.CounterOpts{
52+
Name: "objects_failed_total",
53+
Help: "Count of all objects write failures to Kafka",
54+
})
2555
)
2656

2757
func init() {
2858
prometheus.MustRegister(httpRequestsTotal)
59+
prometheus.MustRegister(promBatches)
60+
prometheus.MustRegister(serializeTotal)
61+
prometheus.MustRegister(serializeFailed)
62+
prometheus.MustRegister(objectsFiltered)
63+
prometheus.MustRegister(objectsFailed)
64+
prometheus.MustRegister(objectsWritten)
2965
}

serializers.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Serializer interface {
3535

3636
// Serialize generates the JSON representation for a given Prometheus metric.
3737
func Serialize(s Serializer, req *prompb.WriteRequest) (map[string][][]byte, error) {
38+
promBatches.Add(float64(1))
3839
result := make(map[string][][]byte)
3940

4041
for _, ts := range req.Timeseries {
@@ -49,6 +50,7 @@ func Serialize(s Serializer, req *prompb.WriteRequest) (map[string][][]byte, err
4950
for _, sample := range ts.Samples {
5051
name := string(labels["__name__"])
5152
if !filter(name, labels) {
53+
objectsFiltered.Add(float64(1))
5254
continue
5355
}
5456

@@ -62,9 +64,10 @@ func Serialize(s Serializer, req *prompb.WriteRequest) (map[string][][]byte, err
6264

6365
data, err := s.Marshal(m)
6466
if err != nil {
67+
serializeFailed.Add(float64(1))
6568
logrus.WithError(err).Errorln("couldn't marshal timeseries")
6669
}
67-
70+
serializeTotal.Add(float64(1))
6871
result[t] = append(result[t], data)
6972
}
7073
}

0 commit comments

Comments
 (0)