Eunomia  0.1.0
A lightweight eBPF-based CloudNative Monitor tool for Container Security and Observability
files.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2  *
3  * Copyright (c) 2022, 郑昱笙,濮雯旭,张典典(牛校牛子队)
4  * All rights reserved.
5  */
6 
7 #ifndef FILE_CMD_H
8 #define FILE_CMD_H
9 
10 #include <iostream>
11 #include <mutex>
12 #include <string>
13 #include <thread>
14 
15 #include "libbpf_print.h"
16 #include "model/tracker.h"
17 #include "prometheus/counter.h"
18 #include "prometheus_server.h"
19 extern "C"
20 {
21 #include <files/file_tracker.h>
22 }
23 
25 
29 struct files_tracker : public tracker_with_config<files_env, files_event>
30 {
32 
34  static std::unique_ptr<files_tracker> create_tracker_with_default_env(tracker_event_handler handler);
35  static std::unique_ptr<files_tracker> create_tracker_with_args(
36  tracker_event_handler handler,
37  const std::vector<std::string> &args)
38  {
39  return create_tracker_with_default_env(handler);
40  }
41 
43  void start_tracker();
44 
46  struct prometheus_event_handler : public event_handler<files_event>
47  {
49  prometheus::Family<prometheus::Counter> &eunomia_files_read_counter;
51  prometheus::Family<prometheus::Counter> &eunomia_files_write_counter;
53  prometheus::Family<prometheus::Counter> &eunomia_files_write_bytes;
55  prometheus::Family<prometheus::Counter> &eunomia_files_read_bytes;
57  void report_prometheus_event(const struct files_event &e);
58 
61  };
62 
64  struct json_event_handler : public event_handler<files_event>
65  {
66  std::string to_json(const struct files_event &e);
67  };
68 
71  {
73  };
74 
75  struct plain_text_event_printer : public event_handler<files_event>
76  {
78  };
79 
80  struct csv_event_printer : public event_handler<files_event>
81  {
83  };
84 };
85 
86 #endif
files_tracker::create_tracker_with_default_env
static std::unique_ptr< files_tracker > create_tracker_with_default_env(tracker_event_handler handler)
create a tracker with deafult config
Definition: files.cpp:97
files_tracker::json_event_handler::to_json
std::string to_json(const struct files_event &e)
Definition: files.cpp:124
tracker.h
files_tracker::prometheus_event_handler::container_manager_ref
const container_manager & container_manager_ref
Definition: files.h:56
files_tracker::prometheus_event_handler::eunomia_files_write_bytes
prometheus::Family< prometheus::Counter > & eunomia_files_write_bytes
write bytes counter for field write_bytes
Definition: files.h:53
files_tracker::csv_event_printer::handle
void handle(tracker_event< files_event > &e)
implement this function to handle the event
Definition: files.cpp:192
files_tracker
ebpf files tracker interface
Definition: files.h:29
eunomia_mode::server
@ server
event_handler
the event handler for single type
Definition: event_handler.h:52
files_tracker::json_event_handler
convert event to json
Definition: files.h:64
files_tracker::start_tracker
void start_tracker()
start files tracker
Definition: files.cpp:115
files_tracker::create_tracker_with_args
static std::unique_ptr< files_tracker > create_tracker_with_args(tracker_event_handler handler, const std::vector< std::string > &args)
Definition: files.h:35
files_tracker::plain_text_event_printer
Definition: files.h:75
files_tracker::prometheus_event_handler::report_prometheus_event
void report_prometheus_event(const struct files_event &e)
Definition: files.cpp:15
tracker_with_config< files_env, files_event >::config_data
tracker_config< files_env, files_event > config_data
type alias for env and config
Definition: tracker.h:65
tracker_with_config
tracker template with env and data
Definition: tracker.h:59
files_tracker::csv_event_printer
Definition: files.h:80
container_manager
manager all container or k8s info
Definition: container_manager.h:21
files_tracker::json_event_printer
used for json exporter, inherits from json_event_handler
Definition: files.h:70
prometheus_server.h
tracker_event
the basic event type
Definition: event_handler.h:31
files_tracker::json_event_printer::handle
void handle(tracker_event< files_event > &e)
implement this function to handle the event
Definition: files.cpp:145
files_tracker::prometheus_event_handler::handle
void handle(tracker_event< files_event > &e)
implement this function to handle the event
Definition: files.cpp:86
files_tracker::prometheus_event_handler::eunomia_files_write_counter
prometheus::Family< prometheus::Counter > & eunomia_files_write_counter
write times counter for field writes
Definition: files.h:51
libbpf_print.h
files_tracker::prometheus_event_handler::prometheus_event_handler
prometheus_event_handler(prometheus_server &server)
Definition: files.cpp:65
files_tracker::files_tracker
files_tracker(config_data config)
Definition: files.cpp:91
files_tracker::prometheus_event_handler::eunomia_files_read_bytes
prometheus::Family< prometheus::Counter > & eunomia_files_read_bytes
read bytes counter for field read_bytes
Definition: files.h:55
files_tracker::prometheus_event_handler::eunomia_files_read_counter
prometheus::Family< prometheus::Counter > & eunomia_files_read_counter
read times counter for field reads
Definition: files.h:49
prometheus_server
Definition: prometheus_server.h:22
tracker_with_config< files_env, files_event >::tracker_event_handler
std::shared_ptr< event_handler< files_event > > tracker_event_handler
type alias for event handler
Definition: tracker.h:67
config
seccomp_config config
Definition: seccomp_test.cpp:13
files_tracker::plain_text_event_printer::handle
void handle(tracker_event< files_event > &e)
implement this function to handle the event
Definition: files.cpp:160
files_tracker::prometheus_event_handler
used for prometheus exporter
Definition: files.h:46