Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/in_windows_exporter_metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(src
we_util.c
we_metric.c
we_cache.c
we_performancecounter.c
we_perflib.c
we_wmi_thermalzone.c
we_wmi_cpu_info.c
Expand All @@ -26,6 +27,7 @@ set(libs
wbemuuid
netapi32
iphlpapi
pdh
)

FLB_PLUGIN(in_windows_exporter_metrics "${src}" "${libs}")
71 changes: 71 additions & 0 deletions plugins/in_windows_exporter_metrics/we.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "we_logical_disk.h"
#include "we_cs.h"
#include "we_cache.h"
#include "we_performancecounter.h"

/* wmi collectors */
#include "we_wmi_cpu_info.h"
Expand Down Expand Up @@ -197,6 +198,17 @@ static int we_timer_wmi_tcp_metrics_cb(struct flb_input_instance *ins,
return 0;
}

static int we_timer_performancecounter_metrics_cb(struct flb_input_instance *ins,
struct flb_config *config,
void *in_context)
{
struct flb_we *ctx = in_context;

we_performancecounter_update(ctx);

return 0;
}

struct flb_we_callback {
char *name;
void (*func)(char *, void *, void *);
Expand Down Expand Up @@ -354,6 +366,13 @@ static void we_wmi_tcp_update_cb(char *name, void *p1, void *p2)
we_wmi_tcp_update(ctx);
}

static void we_performancecounter_update_cb(char *name, void *p1, void *p2)
{
struct flb_we *ctx = p1;

we_performancecounter_update(ctx);
}

static int we_update_cb(struct flb_we *ctx, char *name)
{
int ret;
Expand Down Expand Up @@ -382,6 +401,7 @@ struct flb_we_callback ne_callbacks[] = {
{ "paging_file", we_wmi_paging_file_update_cb },
{ "process", we_wmi_process_update_cb },
{ "tcp", we_wmi_tcp_update_cb },
{ "performancecounter", we_performancecounter_update_cb },
{ 0 }
};

Expand Down Expand Up @@ -421,6 +441,7 @@ static int in_we_init(struct flb_input_instance *in,
ctx->coll_wmi_paging_file_fd = -1;
ctx->coll_wmi_process_fd = -1;
ctx->coll_wmi_tcp_fd = -1;
ctx->coll_performancecounter_fd = -1;

ctx->callback = flb_callback_create(in->name);
if (!ctx->callback) {
Expand Down Expand Up @@ -474,6 +495,7 @@ static int in_we_init(struct flb_input_instance *in,
if (ctx->metrics) {
mk_list_foreach(head, ctx->metrics) {
entry = mk_list_entry(head, struct flb_slist_entry, _head);
metric_idx = -1;
ret = flb_callback_exists(ctx->callback, entry->str);

if (ret == FLB_FALSE) {
Expand Down Expand Up @@ -851,6 +873,32 @@ static int in_we_init(struct flb_input_instance *in,
return -1;
}
}
else if (strncmp(entry->str, "performancecounter", 18) == 0) {
if (ctx->performancecounter_scrape_interval == 0) {
flb_plg_debug(ctx->ins, "enabled metrics %s", entry->str);
metric_idx = 15;
}
else {
/* Create the performancecounter collector */
ret = flb_input_set_collector_time(
in,
we_timer_performancecounter_metrics_cb,
ctx->performancecounter_scrape_interval, 0,
config);
if (ret == -1) {
flb_plg_error(ctx->ins,
"could not set performancecounter collector "
"for Windows Exporter Metrics plugin");
return -1;
}
ctx->coll_performancecounter_fd = ret;
}

ret = we_performancecounter_init(ctx);
if (ret) {
return -1;
}
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
metric_idx = -1;
Expand Down Expand Up @@ -939,6 +987,9 @@ static int in_we_exit(void *data, struct flb_config *config)
else if (strncmp(entry->str, "tcp", 3) == 0) {
we_wmi_tcp_exit(ctx);
}
else if (strncmp(entry->str, "performancecounter", 18) == 0) {
we_performancecounter_exit(ctx);
}
else {
flb_plg_warn(ctx->ins, "Unknown metrics: %s", entry->str);
}
Expand Down Expand Up @@ -994,6 +1045,9 @@ static int in_we_exit(void *data, struct flb_config *config)
if (ctx->coll_wmi_tcp_fd != -1) {
we_wmi_tcp_exit(ctx);
}
if (ctx->coll_performancecounter_fd != -1) {
we_performancecounter_exit(ctx);
}

flb_we_config_destroy(ctx);

Expand Down Expand Up @@ -1052,6 +1106,9 @@ static void in_we_pause(void *data, struct flb_config *config)
if (ctx->coll_wmi_tcp_fd != -1) {
flb_input_collector_pause(ctx->coll_wmi_tcp_fd, ctx->ins);
}
if (ctx->coll_performancecounter_fd != -1) {
flb_input_collector_pause(ctx->coll_performancecounter_fd, ctx->ins);
}
}

static void in_we_resume(void *data, struct flb_config *config)
Expand Down Expand Up @@ -1109,6 +1166,9 @@ static void in_we_resume(void *data, struct flb_config *config)
if (ctx->coll_wmi_tcp_fd != -1) {
flb_input_collector_resume(ctx->coll_wmi_tcp_fd, ctx->ins);
}
if (ctx->coll_performancecounter_fd != -1) {
flb_input_collector_resume(ctx->coll_performancecounter_fd, ctx->ins);
}
}

/* Configuration properties map */
Expand Down Expand Up @@ -1209,6 +1269,12 @@ static struct flb_config_map config_map[] = {
"scrape interval to collect tcp metrics from the node."
},

{
FLB_CONFIG_MAP_TIME, "collector.performancecounter.scrape_interval", "0",
0, FLB_TRUE, offsetof(struct flb_we, performancecounter_scrape_interval),
"scrape interval to collect performancecounter metrics from the node."
},

{
FLB_CONFIG_MAP_CLIST, "metrics",
"cpu,cpu_info,os,net,logical_disk,cs,cache,thermalzone,logon,system,service,tcp",
Expand Down Expand Up @@ -1255,6 +1321,11 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_we, raw_denying_process),
"Specify the regex for process metrics to prevent collection of/ignore."
},
{
FLB_CONFIG_MAP_STR, "PerformanceCounter", NULL,
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_we, raw_performance_counters),
"Windows Performance Counter in name=counter_path form."
},
/* EOF */
{0}
};
Expand Down
40 changes: 40 additions & 0 deletions plugins/in_windows_exporter_metrics/we.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#include <windows.h>
#include <wbemidl.h>
#include <pdh.h>
#include <pdhmsg.h>

#include "we_metric.h"

Expand Down Expand Up @@ -248,6 +250,40 @@ struct we_wmi_tcp_counters {
struct cmt_gauge *segments_sent_total;
};

struct we_performancecounter_definition {
char *name;
char *path;
wchar_t *path_w;
struct cmt_gauge *metric;
int has_wildcard;
int warned_expand_failure;
int warned_no_instances;
struct mk_list _head;
};

struct we_performancecounter_counter {
struct we_performancecounter_definition *definition;
char *name;
char *path;
wchar_t *path_w;
char *instance;
char *label_values[1];
PDH_HCOUNTER handle;
struct cmt_gauge *metric;
int label_count;
int valid;
int seen_valid;
int stale;
struct mk_list _head;
};

struct we_performancecounter_counters {
PDH_HQUERY query;
int operational;
struct mk_list definitions;
struct mk_list counters;
};

struct we_os_counters {
struct cmt_gauge *info;
struct cmt_gauge *users;
Expand Down Expand Up @@ -286,6 +322,7 @@ struct flb_we {
char *raw_service_exclude;
char *raw_allowing_process;
char *raw_denying_process;
struct mk_list *raw_performance_counters;
char *service_include_buffer;
int service_include_buffer_size;
char *service_exclude_buffer;
Expand Down Expand Up @@ -324,6 +361,7 @@ struct flb_we {
int wmi_paging_file_scrape_interval;
int wmi_process_scrape_interval;
int wmi_tcp_scrape_interval;
int performancecounter_scrape_interval;

int coll_cpu_fd; /* collector fd (cpu) */
int coll_net_fd; /* collector fd (net) */
Expand All @@ -340,6 +378,7 @@ struct flb_we {
int coll_wmi_paging_file_fd; /* collector fd (wmi_paging_file) */
int coll_wmi_process_fd; /* collector fd (wmi_process) */
int coll_wmi_tcp_fd; /* collector fd (wmi_tcp) */
int coll_performancecounter_fd; /* collector fd (performancecounter) */

/*
* Metrics Contexts
Expand All @@ -361,6 +400,7 @@ struct flb_we {
struct we_wmi_paging_file_counters *wmi_paging_file;
struct we_wmi_process_counters *wmi_process;
struct we_wmi_tcp_counters *wmi_tcp;
struct we_performancecounter_counters *performancecounter;
};

typedef int (*collector_cb)(struct flb_we *);
Expand Down
Loading
Loading