|
static constexpr unsigned | LOG_LEVEL_FATAL = (0x1 << 0) |
|
static constexpr unsigned | LOG_LEVEL_ERROR = (0x1 << 1) |
|
static constexpr unsigned | LOG_LEVEL_WARNING = (0x1 << 2) |
|
static constexpr unsigned | LOG_LEVEL_MILESTONE = (0x1 << 3) |
|
static constexpr unsigned | LOG_LEVEL_INFO = (0x1 << 4) |
|
static constexpr unsigned | LOG_LEVEL_DEBUG = (0x1 << 5) |
|
|
int | pipeFdHandler (uint32_t revents) |
| Callback called when data to read on the logging pipe. More...
|
|
void | processLogData () |
| Process some log data from a client pipe. More...
|
|
int | processLogLevel (const char *field, ssize_t len, struct iovec *iov) const |
| Process the log level field. More...
|
|
int | processPid (const char *field, ssize_t len, struct iovec *iov) const |
| Process the pid field. More...
|
|
int | processTimestamp (const char *field, ssize_t len, struct iovec *iov) const |
| Process the timestamp field. More...
|
|
int | processThreadName (const char *field, ssize_t len, struct iovec *iov) const |
| Process the thread name field. More...
|
|
int | processCodeFile (const char *field, ssize_t len, struct iovec *iov) const |
| Process the function name field. More...
|
|
int | processCodeFunction (const char *field, ssize_t len, struct iovec *iov) const |
| Process the function name field. More...
|
|
int | processCodeLine (const char *field, ssize_t len, struct iovec *iov) const |
| Process the line number field. More...
|
|
int | processMessage (const char *field, ssize_t len, struct iovec *iov) const |
| Process the message field. More...
|
|
bool | shouldDrop () |
| Returns true if the message should be dropped due to rate limiting. More...
|
|
pid_t | findRealPid (pid_t nsPid) const |
| Attempts to find the pid number in the root pid namespace from a pid in the containers namespace. More...
|
|
std::set< pid_t > | getAllContainerPids () const |
| Reads the set of all pids within the client's container. More...
|
|
pid_t | readNsPidFromProc (pid_t pid) const |
| Given a pid (in global namespace) tries to find what it's namespace pid is. More...
|
|
pid_t EthanLogClient::findRealPid |
( |
pid_t |
nsPid | ) |
const |
|
private |
Attempts to find the pid number in the root pid namespace from a pid in the containers namespace.
It's tricky getting the real pid of a process in a namespace, see the below link for more information: https://blogs.oracle.com/linux/translating-process-id-between-namespaces
However we can make some assumptions about our containers which make it slightly easier; the first is that we always have a memory cgroup setup for them, and secondly there aren't typically going to be lots of processes in our containers. So what we do is read the /sys/fs/cgroup/memory/<id>/cgroup.procs file to get all the processes within the container, then we read each of their /proc/<pid>/status files to extract the NSpid fields and then match them up.
To speed up the process, everytime this method is called and we don't have an existing mapping, then we re-create the full mapping. This helps flush out dead processes from the cache and also speed up subsequent lookups. However this could result in a bit of load in Dobby, if the client constantly sent invalid pid numbers to us ... or more likely there are lots of transient processes that log just a single line, like a shell script or something ... not sure what the solution for that is.
- Parameters
-
[in] | nsPid | The pid in the namespace of the container. |
- Returns
- The 'real' pid in the global namespace.
void EthanLogClient::processLogData |
( |
| ) |
|
|
private |
Process some log data from a client pipe.
- Parameters
-
app | The app/client that has generated the data |
data | The string (or part of a string) sent by the client |
datalen | The number of characters received |
The log string(s) sent by the client library are formatted using ASCII separators, the format is (temporarily) described on the following confluence page: https://www.stb.bskyb.com/confluence/display/~grayb/Unified+Logging+on+the+STB
But for those that can't be bothered opening a browser, the following are the cliff notes:
\x1e - Character used to start and terminate a log message
\x1f - Character used to delimit fields within the message string
Each field within the message is prefixed with one of the following
upper case characters that define the field type.
L - Log level
P - PID of app in hexadecimal (without 0x prefix)
T - Timestamp from monotonic clock in hexadecimal (without 0x prefix)
R - Name of the thread
S - Name of the source file containing the log message
F - Name of the function producing the log message
N - The line number of the log producer
M - The log message (mandatory but can be empty)