Compare commits

..

2 Commits

Author SHA1 Message Date
Mark Stemm
d1b6b2be87 Merge pull request #229 from draios/dev
Merging for 0.6.0
2017-03-29 16:00:06 -07:00
Mark Stemm
e00181d553 Merge pull request #174 from draios/dev
Merging for 0.5.0
2016-12-22 13:25:32 -08:00
3 changed files with 15 additions and 47 deletions

View File

@@ -433,7 +433,7 @@
and shell_procs
and proc.pname exists
and not proc.pname in (shell_binaries, docker_binaries, k8s_binaries, lxd_binaries, aide_wrapper_binaries, nids_binaries,
monitoring_binaries, gitlab_binaries, initdb, pg_ctl, awk, falco, cron, erl_child_setup)
monitoring_binaries, gitlab_binaries, initdb, pg_ctl, awk, apache2, falco, cron, erl_child_setup)
and not trusted_containers
output: "Shell spawned in a container other than entrypoint (user=%user.name %container.info shell=%proc.name parent=%proc.pname cmdline=%proc.cmdline)"
priority: WARNING

View File

@@ -31,30 +31,20 @@ token_bucket::~token_bucket()
{
}
void token_bucket::init(double rate, double max_tokens, uint64_t now)
void token_bucket::init(uint32_t rate, uint32_t max_tokens)
{
m_rate = rate;
m_max_tokens = max_tokens;
m_tokens = max_tokens;
if(now == 0)
{
now = sinsp_utils::get_current_time_ns();
}
m_last_seen = now;
m_last_seen = sinsp_utils::get_current_time_ns();
}
bool token_bucket::claim()
{
// Determine the number of tokens gained. Delta between
// last_seen and now, divided by the rate.
uint64_t now = sinsp_utils::get_current_time_ns();
return claim(1, now);
}
bool token_bucket::claim(double tokens, uint64_t now)
{
double tokens_gained = m_rate * ((now - m_last_seen) / (1000000000.0));
uint64_t tokens_gained = (now - m_last_seen) / (m_rate * 1000000000);
m_last_seen = now;
m_tokens += tokens_gained;
@@ -68,24 +58,14 @@ bool token_bucket::claim(double tokens, uint64_t now)
}
//
// If m_tokens is < tokens, can't claim.
// If tokens is < 1, can't claim.
//
if(m_tokens < tokens)
if(m_tokens < 1)
{
return false;
}
m_tokens -= tokens;
m_tokens--;
return true;
}
double token_bucket::get_tokens()
{
return m_tokens;
}
uint64_t token_bucket::get_last_seen()
{
return m_last_seen;
}

View File

@@ -31,42 +31,30 @@ public:
//
// Initialize the token bucket and start accumulating tokens
//
void init(double rate, double max_tokens, uint64_t now = 0);
void init(uint32_t rate, uint32_t max_tokens);
//
// Try to claim tokens tokens from the token bucket, using a
// timestamp of now. Returns true if the tokens could be
// claimed. Also updates internal metrics.
// Returns true if a token can be claimed. Also updates
// internal metrics.
//
bool claim(double tokens, uint64_t now);
// Simpler version of claim that claims a single token and
// uses the current time for now
bool claim();
// Return the current number of tokens available
double get_tokens();
// Return the last time someone tried to claim a token.
uint64_t get_last_seen();
private:
//
// The number of tokens generated per second.
//
double m_rate;
uint64_t m_rate;
//
// The maximum number of tokens that can be banked for future
// claim()s.
//
double m_max_tokens;
uint64_t m_max_tokens;
//
// The current number of tokens
//
double m_tokens;
uint64_t m_tokens;
//
// The last time claim() was called (or the object was created).