MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
controller_statistics.h
Go to the documentation of this file.
1 #include <mist/shared_memory.h>
2 #include <mist/timing.h>
3 #include <mist/defines.h>
4 #include <mist/json.h>
5 #include <mist/tinythread.h>
6 #include <string>
7 #include <map>
8 
10 #define STAT_CUTOFF 600
11 
12 
13 namespace Controller {
14 
15  extern bool killOnExit;
16 
17  struct statLog {
18  long time;
19  long lastSecond;
20  long long down;
21  long long up;
22  };
23 
26  class sessIndex {
27  public:
28  sessIndex(std::string host, unsigned int crc, std::string streamName, std::string connector);
30  sessIndex();
31  std::string host;
32  unsigned int crc;
33  std::string streamName;
34  std::string connector;
35 
36  bool operator== (const sessIndex &o) const;
37  bool operator!= (const sessIndex &o) const;
38  bool operator> (const sessIndex &o) const;
39  bool operator<= (const sessIndex &o) const;
40  bool operator< (const sessIndex &o) const;
41  bool operator>= (const sessIndex &o) const;
42  };
43 
44 
45  class statStorage {
46  public:
47  void update(IPC::statExchange & data);
48  bool hasDataFor(unsigned long long);
49  statLog & getDataFor(unsigned long long);
50  std::map<unsigned long long, statLog> log;
51  };
52 
55  class statSession {
56  private:
57  unsigned long long firstSec;
58  unsigned long long lastSec;
59  std::deque<statStorage> oldConns;
60  std::map<unsigned long, statStorage> curConns;
61  char sync;
62  public:
63  statSession();
64  void wipeOld(unsigned long long);
65  void finish(unsigned long index);
66  void switchOverTo(statSession & newSess, unsigned long index);
67  void update(unsigned long index, IPC::statExchange & data);
68  unsigned long long getStart();
69  unsigned long long getEnd();
70  bool hasDataFor(unsigned long long time);
71  bool hasData();
72  long long getConnTime(unsigned long long time);
73  long long getLastSecond(unsigned long long time);
74  long long getDown(unsigned long long time);
75  long long getUp(unsigned long long time);
76  long long getBpsDown(unsigned long long time);
77  long long getBpsUp(unsigned long long time);
78  long long getBpsDown(unsigned long long start, unsigned long long end);
79  long long getBpsUp(unsigned long long start, unsigned long long end);
80  };
81 
82 
83  extern std::map<sessIndex, statSession> sessions;
84  extern std::map<unsigned long, sessIndex> connToSession;
85  extern tthread::mutex statsMutex;
86  void parseStatistics(char * data, size_t len, unsigned int id);
87  void killStatistics(char * data, size_t len, unsigned int id);
88  void fillClients(JSON::Value & req, JSON::Value & rep);
89  void fillActive(JSON::Value & req, JSON::Value & rep, bool onlyNow = false);
90  void fillTotals(JSON::Value & req, JSON::Value & rep);
91  void SharedMemStats(void * config);
92  bool hasViewers(std::string streamName);
93 }
94 
void killStatistics(char *data, size_t len, unsigned int id)
Forces a disconnect to all users.
Definition: controller_statistics.cpp:92
unsigned long long lastSec
Definition: controller_statistics.h:58
void fillClients(JSON::Value &req, JSON::Value &rep)
This takes a "clients" request, and fills in the response data.
Definition: controller_statistics.cpp:513
Holds everything unique to the controller.
Definition: controller_api.h:4
A session class that keeps track of both current and archived connections.
Definition: controller_statistics.h:55
unsigned long long firstSec
Definition: controller_statistics.h:57
char sync
Definition: controller_statistics.h:61
Definition: controller_statistics.h:17
std::map< unsigned long, sessIndex > connToSession
Map of socket IDs to session info.
Definition: controller_statistics.cpp:33
long time
Definition: controller_statistics.h:18
A JSON::Value is either a string or an integer, but may also be an object, array or null...
Definition: json.h:21
void fillTotals(JSON::Value &req, JSON::Value &rep)
This takes a "totals" request, and fills in the response data.
Definition: controller_statistics.cpp:752
unsigned int crc
Definition: controller_statistics.h:32
std::map< unsigned long, statStorage > curConns
Definition: controller_statistics.h:60
std::map< sessIndex, statSession > sessions
list of sessions that have statistics data available
Definition: controller_statistics.cpp:32
This is a comparison and storage class that keeps sessions apart from each other. ...
Definition: controller_statistics.h:26
Definition: controller_statistics.h:45
long long up
Definition: controller_statistics.h:21
long lastSecond
Definition: controller_statistics.h:19
std::string connector
Definition: controller_statistics.h:34
std::string streamName
Definition: controller_statistics.h:33
void fillActive(JSON::Value &req, JSON::Value &rep, bool onlyNow=false)
This takes a "active_streams" request, and fills in the response data.
Definition: controller_statistics.cpp:637
std::map< unsigned long long, statLog > log
Definition: controller_statistics.h:50
tthread::mutex statsMutex
Definition: controller_statistics.cpp:35
std::string host
Definition: controller_statistics.h:31
bool killOnExit
Definition: controller_statistics.cpp:34
A class used for the exchange of statistics over shared memory.
Definition: shared_memory.h:20
void parseStatistics(char *data, size_t len, unsigned int id)
This function is called by the shared memory page that holds statistics.
Definition: controller_statistics.cpp:435
void SharedMemStats(void *config)
This function runs as a thread and roughly once per second retrieves statistics from all connected cl...
Definition: controller_statistics.cpp:99
long long down
Definition: controller_statistics.h:20
bool hasViewers(std::string streamName)
Returns true if this stream has at least one connected client.
Definition: controller_statistics.cpp:466
std::deque< statStorage > oldConns
Definition: controller_statistics.h:59