Eunomia  0.1.0
A lightweight eBPF-based CloudNative Monitor tool for Container Security and Observability
syscall.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 SYSCALL_CMD_H
8 #define SYSCALL_CMD_H
9 
10 #include <mutex>
11 #include <thread>
12 
13 #include "libbpf_print.h"
14 #include "model/tracker.h"
15 #include "prometheus/counter.h"
16 #include "prometheus_server.h"
17 
18 extern "C" {
19 #include <syscall/syscall_tracker.h>
20 #include "syscall_helper.h"
21 }
22 
24 
26 class syscall_tracker : public tracker_with_config<syscall_env, syscall_event> {
27 public:
29 
30  // create a tracker with deafult config
31  static std::unique_ptr<syscall_tracker> create_tracker_with_default_env(tracker_event_handler handler);
32  static std::unique_ptr<syscall_tracker> create_tracker_with_args(
33  tracker_event_handler handler,
34  const std::vector<std::string> &args)
35  {
36  return create_tracker_with_default_env(handler);
37  }
38 
39  void start_tracker();
40 
41  // used for prometheus exporter
42  struct prometheus_event_handler : public event_handler<syscall_event>
43  {
44  // read times counter for field reads
45  prometheus::Family<prometheus::Counter> &eunomia_files_syscall_counter;
46  void report_prometheus_event(const struct syscall_event &e);
47 
50  };
51 
52  // convert event to json
53  struct json_event_handler : public event_handler<syscall_event>
54  {
55  std::string to_json(const struct syscall_event &e);
56  };
57 
58  // used for json exporter, inherits from json_event_handler
60  {
62  };
63 
64  struct plain_text_event_printer : public event_handler<syscall_event>
65  {
67  };
68 
69  struct csv_event_printer : public event_handler<syscall_event>
70  {
72  };
73 };
74 
75 #endif
syscall_tracker::json_event_handler
Definition: syscall.h:53
tracker.h
eunomia_mode::server
@ server
syscall_tracker::create_tracker_with_args
static std::unique_ptr< syscall_tracker > create_tracker_with_args(tracker_event_handler handler, const std::vector< std::string > &args)
Definition: syscall.h:32
syscall_tracker::json_event_printer::handle
void handle(tracker_event< syscall_event > &e)
implement this function to handle the event
Definition: syscall.cpp:53
syscall_tracker::prometheus_event_handler::prometheus_event_handler
prometheus_event_handler(prometheus_server &server)
Definition: syscall.cpp:111
syscall_tracker::create_tracker_with_default_env
static std::unique_ptr< syscall_tracker > create_tracker_with_default_env(tracker_event_handler handler)
Definition: syscall.cpp:21
event_handler
the event handler for single type
Definition: event_handler.h:52
syscall_tracker::start_tracker
void start_tracker()
start the tracker thread
Definition: syscall.cpp:30
tracker_with_config< syscall_env, syscall_event >::config_data
tracker_config< syscall_env, syscall_event > config_data
type alias for env and config
Definition: tracker.h:65
syscall_tracker::plain_text_event_printer::handle
void handle(tracker_event< syscall_event > &e)
implement this function to handle the event
Definition: syscall.cpp:58
syscall_tracker::syscall_tracker
syscall_tracker(config_data config)
Definition: syscall.cpp:15
tracker_with_config
tracker template with env and data
Definition: tracker.h:59
syscall_tracker::prometheus_event_handler::report_prometheus_event
void report_prometheus_event(const struct syscall_event &e)
Definition: syscall.cpp:101
syscall_tracker::prometheus_event_handler::eunomia_files_syscall_counter
prometheus::Family< prometheus::Counter > & eunomia_files_syscall_counter
Definition: syscall.h:45
syscall_tracker::csv_event_printer
Definition: syscall.h:69
syscall_tracker::plain_text_event_printer
Definition: syscall.h:64
syscall_tracker::csv_event_printer::handle
void handle(tracker_event< syscall_event > &e)
implement this function to handle the event
Definition: syscall.cpp:79
prometheus_server.h
tracker_event
the basic event type
Definition: event_handler.h:31
syscall_tracker::json_event_printer
Definition: syscall.h:59
libbpf_print.h
syscall_tracker::json_event_handler::to_json
std::string to_json(const struct syscall_event &e)
Definition: syscall.cpp:36
prometheus_server
Definition: prometheus_server.h:22
tracker_with_config< syscall_env, syscall_event >::tracker_event_handler
std::shared_ptr< event_handler< syscall_event > > tracker_event_handler
type alias for event handler
Definition: tracker.h:67
config
seccomp_config config
Definition: seccomp_test.cpp:13
syscall_tracker::prometheus_event_handler::handle
void handle(tracker_event< syscall_event > &e)
implement this function to handle the event
Definition: syscall.cpp:119
syscall_tracker::prometheus_event_handler
Definition: syscall.h:42
syscall_helper.h
syscall_tracker
syscall tracker cpp interface
Definition: syscall.h:26