SearchSECODatabaseAPI
Statistics.h
1/*
2This program has been developed by students from the bachelor Computer Science at
3Utrecht University within the Software Project course.
4© Copyright Utrecht University (Department of Information and Computing Sciences)
5*/
6
7#pragma once
8
9#include <prometheus/counter.h>
10#include <prometheus/exposer.h>
11#include <prometheus/registry.h>
12#include <queue>
13
14#define SYNCHRONIZE_DELAY 10000000 // 10 seconds.
15
19enum StatFamily
20{
21 reqCount,
22 methCount,
23 langCount,
24 jobCount,
25 reqTime,
26 vulnCount,
27 recProj,
28 recVuln
29};
30
35{
36 public:
40 virtual void Initialize();
41
46 void addRecentProject(std::string url);
47
52 void addRecentVulnerability(std::string vulnCode);
53
58 void synchronize(std::string file);
59
64 void writeToFile(std::string file);
65
70 void readFromFile(std::string file);
71
72 // The families to store the statistics in.
73 prometheus::Family<prometheus::Counter> *requestCounter;
74 prometheus::Family<prometheus::Counter> *methodCounter;
75 prometheus::Family<prometheus::Counter> *languageCounter;
76 prometheus::Family<prometheus::Counter> *jobCounter;
77 prometheus::Family<prometheus::Gauge> *latestRequest;
78 prometheus::Family<prometheus::Counter> *vulnCounter;
79 prometheus::Family<prometheus::Gauge> *recentProjects;
80 prometheus::Family<prometheus::Gauge> *recentVulns;
81
82 // The ip of this node for identifying the node in the statistics.
83 std::string myIP;
84
85 // A boolean to store whether there has been a new request.
86 bool newRequest;
87
88 protected:
89 // The exposer for the statistics.
90 prometheus::Exposer *exposer;
91
92 // The registry that stores the families.
93 std::shared_ptr<prometheus::Registry> registry;
94
95 std::queue<prometheus::Gauge *> recentProjectsQueue;
96 std::queue<prometheus::Gauge *> recentVulnsQueue;
97};
Stores the Prometheus statistics variables.
Definition: Statistics.h:35
void addRecentProject(std::string url)
Add a recently added project.
Definition: Statistics.cpp:67
virtual void Initialize()
Initializes all statistics objects.
Definition: Statistics.cpp:18
void addRecentVulnerability(std::string vulnCode)
Add a recently added vulnerability.
Definition: Statistics.cpp:79
void writeToFile(std::string file)
Write the value of the statistics to the given file.
Definition: Statistics.cpp:233
void synchronize(std::string file)
Regularly synchronizes the statistics to the passed file.
Definition: Statistics.cpp:112
void readFromFile(std::string file)
Reads the values of the statistics from the passed file.
Definition: Statistics.cpp:125