parent
d1ce543440
commit
fb54388e93
|
@ -366,14 +366,7 @@ func (a *apic) Pull() error {
|
|||
}
|
||||
}
|
||||
|
||||
func (a *apic) SendMetrics() error {
|
||||
defer types.CatchPanic("lapi/metricsToAPIC")
|
||||
|
||||
log.Infof("start crowdsec api send metrics (interval: %s)", MetricsInterval)
|
||||
ticker := time.NewTicker(a.metricsInterval)
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
func (a *apic) GetMetrics() (*models.Metrics, error) {
|
||||
version := cwversion.VersionStr()
|
||||
metric := &models.Metrics{
|
||||
ApilVersion: &version,
|
||||
|
@ -382,11 +375,11 @@ func (a *apic) SendMetrics() error {
|
|||
}
|
||||
machines, err := a.dbClient.ListMachines()
|
||||
if err != nil {
|
||||
return err
|
||||
return metric, err
|
||||
}
|
||||
bouncers, err := a.dbClient.ListBouncers()
|
||||
if err != nil {
|
||||
return err
|
||||
return metric, err
|
||||
}
|
||||
for _, machine := range machines {
|
||||
m := &models.MetricsSoftInfo{
|
||||
|
@ -403,11 +396,36 @@ func (a *apic) SendMetrics() error {
|
|||
}
|
||||
metric.Bouncers = append(metric.Bouncers, m)
|
||||
}
|
||||
_, _, err = a.apiClient.Metrics.Add(context.Background(), metric)
|
||||
return metric, nil
|
||||
}
|
||||
|
||||
func (a *apic) SendMetrics() error {
|
||||
defer types.CatchPanic("lapi/metricsToAPIC")
|
||||
|
||||
metrics, err := a.GetMetrics()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sending metrics failed")
|
||||
log.Errorf("unable to get metrics (%s), will retry", err)
|
||||
}
|
||||
_, _, err = a.apiClient.Metrics.Add(context.Background(), metrics)
|
||||
if err != nil {
|
||||
log.Errorf("unable to send metrics (%s), will retry", err)
|
||||
}
|
||||
log.Infof("capi metrics: metrics sent successfully")
|
||||
log.Infof("start crowdsec api send metrics (interval: %s)", MetricsInterval)
|
||||
ticker := time.NewTicker(a.metricsInterval)
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
metrics, err := a.GetMetrics()
|
||||
if err != nil {
|
||||
log.Errorf("unable to get metrics (%s), will retry", err)
|
||||
}
|
||||
_, _, err = a.apiClient.Metrics.Add(context.Background(), metrics)
|
||||
if err != nil {
|
||||
log.Errorf("capi metrics: failed: %s", err.Error())
|
||||
} else {
|
||||
log.Infof("capi metrics: metrics sent successfully")
|
||||
}
|
||||
case <-a.metricsTomb.Dying(): // if one apic routine is dying, do we kill the others?
|
||||
a.pullTomb.Kill(nil)
|
||||
a.pushTomb.Kill(nil)
|
||||
|
|
|
@ -828,15 +828,15 @@ func (c *Client) FlushAlerts(MaxAge string, MaxItems int) error {
|
|||
var totalAlerts int
|
||||
var err error
|
||||
|
||||
c.Log.Info("Flushing orphan alerts")
|
||||
c.Log.Debug("Flushing orphan alerts")
|
||||
c.FlushOrphans()
|
||||
c.Log.Info("Done flushing orphan alerts")
|
||||
c.Log.Debug("Done flushing orphan alerts")
|
||||
totalAlerts, err = c.TotalAlerts()
|
||||
if err != nil {
|
||||
c.Log.Warningf("FlushAlerts (max items count) : %s", err)
|
||||
return errors.Wrap(err, "unable to get alerts count")
|
||||
}
|
||||
c.Log.Infof("FlushAlerts (Total alerts): %d", totalAlerts)
|
||||
c.Log.Debugf("FlushAlerts (Total alerts): %d", totalAlerts)
|
||||
if MaxAge != "" {
|
||||
filter := map[string][]string{
|
||||
"created_before": {MaxAge},
|
||||
|
@ -846,7 +846,7 @@ func (c *Client) FlushAlerts(MaxAge string, MaxItems int) error {
|
|||
c.Log.Warningf("FlushAlerts (max age) : %s", err)
|
||||
return errors.Wrapf(err, "unable to flush alerts with filter until: %s", MaxAge)
|
||||
}
|
||||
c.Log.Infof("FlushAlerts (deleted max age alerts): %d", nbDeleted)
|
||||
c.Log.Debugf("FlushAlerts (deleted max age alerts): %d", nbDeleted)
|
||||
deletedByAge = nbDeleted
|
||||
}
|
||||
if MaxItems > 0 {
|
||||
|
@ -858,7 +858,7 @@ func (c *Client) FlushAlerts(MaxAge string, MaxItems int) error {
|
|||
}
|
||||
deleted := 0
|
||||
for deleted < nbToDelete {
|
||||
c.Log.Infof("FlushAlerts (before query with filter) to delete: %d", nbToDelete)
|
||||
c.Log.Debugf("FlushAlerts (before query with filter) to delete: %d", nbToDelete)
|
||||
alerts, err := c.QueryAlertWithFilter(map[string][]string{
|
||||
"sort": {"ASC"},
|
||||
"limit": {strconv.Itoa(batchSize)},
|
||||
|
|
Loading…
Reference in a new issue