--- /dev/null
+/*#############################################################################
+# #
+# telemetryd - The IPFire Telemetry Collection Service #
+# Copyright (C) 2025 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <errno.h>
+#include <limits.h>
+#include <unistd.h>
+
+#include "../ctx.h"
+#include "../file.h"
+#include "../source.h"
+#include "../string.h"
+#include "cpufreq.h"
+
+#define BASE_PATH "/sys/devices/system/cpu/cpu%ld/cpufreq/"
+
+static int cpufreq_heartbeat_cpu(td_ctx* ctx, td_source* source, long cpu) {
+ char object[NAME_MAX];
+ uint64_t freq_cur = 0;
+ uint64_t freq_min = 0;
+ uint64_t freq_max = 0;
+ uint64_t total_trans = 0;
+ int r;
+
+ // Format the object name
+ r = td_string_format(object, "%ld", cpu);
+ if (r < 0)
+ return r;
+
+ // Fetch the current frequency
+ r = td_read_uint64(ctx, &freq_cur, BASE_PATH "scaling_cur_freq", cpu);
+ if (r < 0)
+ return r;
+
+ // Fetch the minimum frequency
+ r = td_read_uint64(ctx, &freq_min, BASE_PATH "scaling_min_freq", cpu);
+ if (r < 0)
+ return r;
+
+ // Fetch the maximum frequency
+ r = td_read_uint64(ctx, &freq_max, BASE_PATH "scaling_max_freq", cpu);
+ if (r < 0)
+ return r;
+
+ // Fetch the total transitions
+ r = td_read_uint64(ctx, &total_trans, BASE_PATH "stats/total_trans", cpu);
+ if (r < 0)
+ return r;
+
+ // Convert values from kHz to Hz
+ freq_cur *= 1000;
+ freq_min *= 1000;
+ freq_max *= 1000;
+
+ // Submit everything
+ return td_source_submit_values(source, object, VALUES(
+ VALUE_UINT64("freq_cur", &freq_cur),
+ VALUE_UINT64("freq_min", &freq_min),
+ VALUE_UINT64("freq_max", &freq_max),
+ VALUE_UINT64("total_trans", &total_trans)
+ ));
+}
+
+static int cpufreq_heartbeat(td_ctx* ctx, td_source* source) {
+ int r;
+
+ // Fetch the number of available processors
+ long num = sysconf(_SC_NPROCESSORS_CONF);
+
+ // Collect metrics for each available processor
+ for (long i = 0; i < num; i++) {
+ r = cpufreq_heartbeat_cpu(ctx, source, i);
+ if (r < 0)
+ return r;
+ }
+
+ return 0;
+}
+
+const td_source_impl cpufreq_source = {
+ .name = "cpufreq",
+
+ // RRD Data Sources
+ .rrd_dss = {
+ { "freq_cur", "GAUGE", 0, -1, },
+ { "freq_min", "GAUGE", 0, -1, },
+ { "freq_max", "GAUGE", 0, -1, },
+ { "total_trans", "DERIVE", 0, -1, },
+ { NULL },
+ },
+
+ // Methods
+ .heartbeat = cpufreq_heartbeat,
+};
--- /dev/null
+/*#############################################################################
+# #
+# telemetryd - The IPFire Telemetry Collection Service #
+# Copyright (C) 2025 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef TELEMETRY_SOURCE_CPUFREQ_H
+#define TELEMETRY_SOURCE_CPUFREQ_H
+
+#include "../source.h"
+
+extern const td_source_impl cpufreq_source;
+
+#endif /* TELEMETRY_SOURCE_CPUFREQ_H */