42
42
#include <zephyr/net/ipv4_autoconf.h>
43
43
#endif
44
44
45
+ #include <zephyr/net/prometheus/collector.h>
46
+
45
47
#ifdef __cplusplus
46
48
extern "C" {
47
49
#endif
@@ -694,6 +696,10 @@ struct net_if {
694
696
#if defined(CONFIG_NET_STATISTICS_PER_INTERFACE )
695
697
/** Network statistics related to this network interface */
696
698
struct net_stats stats ;
699
+
700
+ /** Promethus collector for this network interface */
701
+ IF_ENABLED (CONFIG_NET_STATISTICS_VIA_PROMETHEUS ,
702
+ (struct prometheus_collector * collector );)
697
703
#endif /* CONFIG_NET_STATISTICS_PER_INTERFACE */
698
704
699
705
/** Network interface instance configuration */
@@ -3198,12 +3204,24 @@ struct net_if_api {
3198
3204
NET_IF_DHCPV6_INIT \
3199
3205
}
3200
3206
3207
+ #define NET_PROMETHEUS_GET_COLLECTOR_NAME (dev_id , sfx ) \
3208
+ net_stats_##dev_id##_##sfx##_collector
3209
+ #define NET_PROMETHEUS_INIT (dev_id , sfx ) \
3210
+ IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS, \
3211
+ (.collector = &NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, sfx),))
3212
+
3201
3213
#define NET_IF_GET_NAME (dev_id , sfx ) __net_if_##dev_id##_##sfx
3202
3214
#define NET_IF_DEV_GET_NAME (dev_id , sfx ) __net_if_dev_##dev_id##_##sfx
3203
3215
3204
3216
#define NET_IF_GET (dev_id , sfx ) \
3205
3217
((struct net_if *)&NET_IF_GET_NAME(dev_id, sfx))
3206
3218
3219
+ #if defined(CONFIG_NET_STATISTICS_VIA_PROMETHEUS )
3220
+ extern int net_stats_prometheus_scrape (struct prometheus_collector * collector ,
3221
+ struct prometheus_metric * metric ,
3222
+ void * user_data );
3223
+ #endif /* CONFIG_NET_STATISTICS_VIA_PROMETHEUS */
3224
+
3207
3225
#define NET_IF_INIT (dev_id , sfx , _l2 , _mtu , _num_configs ) \
3208
3226
static STRUCT_SECTION_ITERABLE(net_if_dev, \
3209
3227
NET_IF_DEV_GET_NAME(dev_id, sfx)) = { \
@@ -3221,7 +3239,15 @@ struct net_if_api {
3221
3239
.if_dev = &(NET_IF_DEV_GET_NAME(dev_id, sfx)), \
3222
3240
NET_IF_CONFIG_INIT \
3223
3241
} \
3224
- }
3242
+ }; \
3243
+ IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS, \
3244
+ (static PROMETHEUS_COLLECTOR_DEFINE( \
3245
+ NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, \
3246
+ sfx), \
3247
+ net_stats_prometheus_scrape, \
3248
+ NET_IF_GET(dev_id, sfx)); \
3249
+ NET_STATS_PROMETHEUS(NET_IF_GET(dev_id, sfx), \
3250
+ dev_id, sfx);))
3225
3251
3226
3252
#define NET_IF_OFFLOAD_INIT (dev_id , sfx , _mtu ) \
3227
3253
static STRUCT_SECTION_ITERABLE(net_if_dev, \
@@ -3239,7 +3265,16 @@ struct net_if_api {
3239
3265
.if_dev = &(NET_IF_DEV_GET_NAME(dev_id, sfx)), \
3240
3266
NET_IF_CONFIG_INIT \
3241
3267
} \
3242
- }
3268
+ }; \
3269
+ IF_ENABLED(CONFIG_NET_STATISTICS_VIA_PROMETHEUS, \
3270
+ (static PROMETHEUS_COLLECTOR_DEFINE( \
3271
+ NET_PROMETHEUS_GET_COLLECTOR_NAME(dev_id, \
3272
+ sfx), \
3273
+ net_stats_prometheus_scrape, \
3274
+ NET_IF_GET(dev_id, sfx)); \
3275
+ NET_STATS_PROMETHEUS(NET_IF_GET(dev_id, sfx), \
3276
+ dev_id, sfx);))
3277
+
3243
3278
3244
3279
/** @endcond */
3245
3280
0 commit comments