up
This commit is contained in:
parent
18b8ddb49a
commit
538ab0bc62
|
@ -14,7 +14,9 @@ import (
|
||||||
"github.com/crowdsecurity/go-cs-lib/trace"
|
"github.com/crowdsecurity/go-cs-lib/trace"
|
||||||
"github.com/crowdsecurity/go-cs-lib/version"
|
"github.com/crowdsecurity/go-cs-lib/version"
|
||||||
|
|
||||||
|
"github.com/crowdsecurity/crowdsec/pkg/cwversion"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/database/ent"
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent"
|
||||||
|
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -77,6 +79,12 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
|
||||||
|
|
||||||
metrics.Name = lpName
|
metrics.Name = lpName
|
||||||
metrics.LastPush = lp.LastPush.UTC().Unix()
|
metrics.LastPush = lp.LastPush.UTC().Unix()
|
||||||
|
metrics.LastUpdate = lp.UpdatedAt.UTC().Unix()
|
||||||
|
|
||||||
|
//To prevent marshalling a nil slice to null, which gets rejected by the API
|
||||||
|
if metrics.Metrics == nil {
|
||||||
|
metrics.Metrics = make([]*models.MetricsDetailItem, 0)
|
||||||
|
}
|
||||||
|
|
||||||
allMetrics.LogProcessors = append(allMetrics.LogProcessors, &metrics)
|
allMetrics.LogProcessors = append(allMetrics.LogProcessors, &metrics)
|
||||||
metricsIds = append(metricsIds, lpsMetric.ID)
|
metricsIds = append(metricsIds, lpsMetric.ID)
|
||||||
|
@ -114,13 +122,42 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
|
||||||
metrics.Name = bouncerName
|
metrics.Name = bouncerName
|
||||||
metrics.LastPull = bouncer.LastPull.UTC().Unix()
|
metrics.LastPull = bouncer.LastPull.UTC().Unix()
|
||||||
|
|
||||||
|
//To prevent marshalling a nil slice to null, which gets rejected by the API
|
||||||
|
if metrics.Metrics == nil {
|
||||||
|
metrics.Metrics = make([]*models.MetricsDetailItem, 0)
|
||||||
|
}
|
||||||
|
|
||||||
allMetrics.RemediationComponents = append(allMetrics.RemediationComponents, &metrics)
|
allMetrics.RemediationComponents = append(allMetrics.RemediationComponents, &metrics)
|
||||||
metricsIds = append(metricsIds, bouncersMetric.ID)
|
metricsIds = append(metricsIds, bouncersMetric.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
//bouncerInfos := make(map[string]string)
|
//FIXME: all of this should only be done once on startup/reload
|
||||||
|
allMetrics.Lapi = &models.LapiMetrics{
|
||||||
|
ConsoleOptions: models.ConsoleOptions{
|
||||||
|
"FIXME",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
allMetrics.Lapi.Os = &models.OSversion{
|
||||||
|
Name: "FIXME",
|
||||||
|
Version: "FIXME",
|
||||||
|
}
|
||||||
|
allMetrics.Lapi.Version = ptr.Of(cwversion.VersionStr())
|
||||||
|
allMetrics.Lapi.FeatureFlags = fflag.Crowdsec.GetEnabledFeatures()
|
||||||
|
|
||||||
//TODO: add LAPI metrics
|
allMetrics.Lapi.Meta = &models.MetricsMeta{
|
||||||
|
UtcStartupTimestamp: time.Now().UTC().Unix(),
|
||||||
|
UtcNowTimestamp: time.Now().UTC().Unix(),
|
||||||
|
WindowSizeSeconds: int64(a.metricsInterval.Seconds()),
|
||||||
|
}
|
||||||
|
allMetrics.Lapi.Metrics = make([]*models.MetricsDetailItem, 0)
|
||||||
|
|
||||||
|
if allMetrics.RemediationComponents == nil {
|
||||||
|
allMetrics.RemediationComponents = make([]*models.RemediationComponentsMetrics, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if allMetrics.LogProcessors == nil {
|
||||||
|
allMetrics.LogProcessors = make([]*models.LogProcessorsMetrics, 0)
|
||||||
|
}
|
||||||
|
|
||||||
return allMetrics, metricsIds, nil
|
return allMetrics, metricsIds, nil
|
||||||
}
|
}
|
||||||
|
@ -306,6 +343,8 @@ func (a *apic) SendUsageMetrics() {
|
||||||
err = a.MarkUsageMetricsAsSent(metricsId)
|
err = a.MarkUsageMetricsAsSent(metricsId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("unable to mark usage metrics as sent: %s", err)
|
log.Errorf("unable to mark usage metrics as sent: %s", err)
|
||||||
|
} else {
|
||||||
|
log.Infof("Usage metrics sent")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,6 @@ func (c *Controller) UsageMetrics(gctx *gin.Context) {
|
||||||
"type": item0.Type,
|
"type": item0.Type,
|
||||||
"metrics": item0.Metrics,
|
"metrics": item0.Metrics,
|
||||||
"meta": item0.Meta,
|
"meta": item0.Meta,
|
||||||
// TODO: RC stuff like traffic stats
|
|
||||||
}
|
}
|
||||||
baseMetrics = item0.BaseMetrics
|
baseMetrics = item0.BaseMetrics
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1060,6 +1060,9 @@ definitions:
|
||||||
last_push:
|
last_push:
|
||||||
type: integer
|
type: integer
|
||||||
description: last push date
|
description: last push date
|
||||||
|
last_update:
|
||||||
|
type: integer
|
||||||
|
description: last update date
|
||||||
LapiMetrics:
|
LapiMetrics:
|
||||||
title: LapiMetrics
|
title: LapiMetrics
|
||||||
type: object
|
type: object
|
||||||
|
|
|
@ -31,6 +31,9 @@ type LogProcessorsMetrics struct {
|
||||||
// last push date
|
// last push date
|
||||||
LastPush int64 `json:"last_push,omitempty"`
|
LastPush int64 `json:"last_push,omitempty"`
|
||||||
|
|
||||||
|
// last update date
|
||||||
|
LastUpdate int64 `json:"last_update,omitempty"`
|
||||||
|
|
||||||
// name of the log processor
|
// name of the log processor
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -54,6 +57,8 @@ func (m *LogProcessorsMetrics) UnmarshalJSON(raw []byte) error {
|
||||||
|
|
||||||
LastPush int64 `json:"last_push,omitempty"`
|
LastPush int64 `json:"last_push,omitempty"`
|
||||||
|
|
||||||
|
LastUpdate int64 `json:"last_update,omitempty"`
|
||||||
|
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
if err := swag.ReadJSON(raw, &dataAO1); err != nil {
|
if err := swag.ReadJSON(raw, &dataAO1); err != nil {
|
||||||
|
@ -68,6 +73,8 @@ func (m *LogProcessorsMetrics) UnmarshalJSON(raw []byte) error {
|
||||||
|
|
||||||
m.LastPush = dataAO1.LastPush
|
m.LastPush = dataAO1.LastPush
|
||||||
|
|
||||||
|
m.LastUpdate = dataAO1.LastUpdate
|
||||||
|
|
||||||
m.Name = dataAO1.Name
|
m.Name = dataAO1.Name
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -91,6 +98,8 @@ func (m LogProcessorsMetrics) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
LastPush int64 `json:"last_push,omitempty"`
|
LastPush int64 `json:"last_push,omitempty"`
|
||||||
|
|
||||||
|
LastUpdate int64 `json:"last_update,omitempty"`
|
||||||
|
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +111,8 @@ func (m LogProcessorsMetrics) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
dataAO1.LastPush = m.LastPush
|
dataAO1.LastPush = m.LastPush
|
||||||
|
|
||||||
|
dataAO1.LastUpdate = m.LastUpdate
|
||||||
|
|
||||||
dataAO1.Name = m.Name
|
dataAO1.Name = m.Name
|
||||||
|
|
||||||
jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)
|
jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)
|
||||||
|
|
Loading…
Reference in a new issue