We will only check if the RRD is available if we really need to.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
return td_queue_submit_metrics(self->queue, metrics);
}
-int td_daemon_flush_source(
- td_daemon* self, td_source* source, const char* object) {
+int td_daemon_has_source(td_daemon* self, td_source* source, const char* object) {
+ return td_queue_has_source(self->queue, source, object);
+}
+
+int td_daemon_flush_source(td_daemon* self, td_source* source, const char* object) {
return td_queue_flush_source(self->queue, source, object);
}
int td_daemon_submit_metrics(td_daemon* self, td_metrics* metrics);
-int td_daemon_flush_source(
- td_daemon* self, td_source* source, const char* object);
+int td_daemon_has_source(td_daemon* self, td_source* source, const char* object);
+int td_daemon_flush_source(td_daemon* self, td_source* source, const char* object);
#ifdef HAVE_LIBNL3
td_netlink* td_daemon_get_netlink(td_daemon* self);
return 0;
}
+int td_queue_has_source(td_queue* self,td_source* source, const char* object) {
+ struct td_queue_object* o = NULL;
+
+ STAILQ_FOREACH(o, &self->queue, nodes) {
+ // Continue if the source does not match
+ if (o->source != source)
+ continue;
+
+ // Continue if the object does not match
+ if (!td_queue_object_equals(self, o, object))
+ continue;
+
+ // Match
+ return 1;
+ }
+
+ // No match
+ return 0;
+}
+
int td_queue_flush_source(td_queue* self,
td_source* source, const char* object) {
struct td_queue_object* o = NULL;
int td_queue_flush(td_queue* self);
+int td_queue_has_source(td_queue* self,td_source* source, const char* object);
+
int td_queue_flush_source(td_queue* self,
td_source* source, const char* object);
if (r < 0)
return r;
- // Commit any buffered data right now
- r = td_daemon_flush_source(self->daemon, self, object);
- if (r < 0)
- return r;
+ // Check if we have this object
+ r = td_source_has_object(self, object);
+ switch (r) {
+ // Not found
+ case 0:
+ return -ENOENT;
+
+ // Found
+ case 1:
+ break;
- // Fail if the path does not exist
- r = access(path, R_OK);
- if (r < 0)
- return -errno;
+ // Raise any other errors
+ default:
+ return r;
+ }
// Add all data sources
for (const td_rrd_ds* ds = self->impl->rrd_dss; ds->field; ds++) {
return r;
}
- return 0;
+ // Commit any buffered data right now
+ return td_daemon_flush_source(self->daemon, self, object);
+}
+
+int td_source_has_object(td_source* self, const char* object) {
+ char path[PATH_MAX];
+ int r;
+
+ // Fast path by checking if there is anything in the queue
+ r = td_daemon_has_source(self->daemon, self, object);
+ if (r)
+ return r;
+
+ // Determine the path to the RRD file
+ r = td_source_path(self, object, path);
+ if (r < 0)
+ return r;
+
+ // Fail if the path does not exist
+ r = access(path, R_OK);
+ if (r < 0) {
+ switch (errno) {
+ // Object has not been found
+ case ENOENT:
+ return 0;
+
+ // Error
+ default:
+ return -errno;
+ }
+ }
+
+ // Object has been found
+ return 1;
}
int td_source_render(td_source* self,
td_args* args, const char* object);
+int td_source_has_object(td_source* self, const char* object);
+
#endif /* TELEMETRY_SOURCE_H */