chore: make deps
This commit is contained in:
14
vendor/github.com/prometheus/common/expfmt/decode.go
generated
vendored
14
vendor/github.com/prometheus/common/expfmt/decode.go
generated
vendored
@ -220,7 +220,7 @@ func extractSamples(f *dto.MetricFamily, o *DecodeOptions) (model.Vector, error)
|
||||
return extractSummary(o, f), nil
|
||||
case dto.MetricType_UNTYPED:
|
||||
return extractUntyped(o, f), nil
|
||||
case dto.MetricType_HISTOGRAM:
|
||||
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||
return extractHistogram(o, f), nil
|
||||
}
|
||||
return nil, fmt.Errorf("expfmt.extractSamples: unknown metric family type %v", f.GetType())
|
||||
@ -403,9 +403,13 @@ func extractHistogram(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
|
||||
infSeen = true
|
||||
}
|
||||
|
||||
v := q.GetCumulativeCountFloat()
|
||||
if v <= 0 {
|
||||
v = float64(q.GetCumulativeCount())
|
||||
}
|
||||
samples = append(samples, &model.Sample{
|
||||
Metric: model.Metric(lset),
|
||||
Value: model.SampleValue(q.GetCumulativeCount()),
|
||||
Value: model.SampleValue(v),
|
||||
Timestamp: timestamp,
|
||||
})
|
||||
}
|
||||
@ -428,9 +432,13 @@ func extractHistogram(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
|
||||
}
|
||||
lset[model.MetricNameLabel] = model.LabelValue(f.GetName() + "_count")
|
||||
|
||||
v := m.Histogram.GetSampleCountFloat()
|
||||
if v <= 0 {
|
||||
v = float64(m.Histogram.GetSampleCount())
|
||||
}
|
||||
count := &model.Sample{
|
||||
Metric: model.Metric(lset),
|
||||
Value: model.SampleValue(m.Histogram.GetSampleCount()),
|
||||
Value: model.SampleValue(v),
|
||||
Timestamp: timestamp,
|
||||
}
|
||||
samples = append(samples, count)
|
||||
|
||||
59
vendor/github.com/prometheus/common/expfmt/openmetrics_create.go
generated
vendored
59
vendor/github.com/prometheus/common/expfmt/openmetrics_create.go
generated
vendored
@ -160,38 +160,38 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
n, err = w.WriteString("# HELP ")
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeName(w, compliantName)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
err = w.WriteByte(' ')
|
||||
written++
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeEscapedString(w, *in.Help, true)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
err = w.WriteByte('\n')
|
||||
written++
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
n, err = w.WriteString("# TYPE ")
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeName(w, compliantName)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
switch metricType {
|
||||
case dto.MetricType_COUNTER:
|
||||
@ -208,39 +208,41 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
n, err = w.WriteString(" unknown\n")
|
||||
case dto.MetricType_HISTOGRAM:
|
||||
n, err = w.WriteString(" histogram\n")
|
||||
case dto.MetricType_GAUGE_HISTOGRAM:
|
||||
n, err = w.WriteString(" gaugehistogram\n")
|
||||
default:
|
||||
return written, fmt.Errorf("unknown metric type %s", metricType.String())
|
||||
}
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
if toOM.withUnit && in.Unit != nil {
|
||||
n, err = w.WriteString("# UNIT ")
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeName(w, compliantName)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
|
||||
err = w.WriteByte(' ')
|
||||
written++
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeEscapedString(w, *in.Unit, true)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
err = w.WriteByte('\n')
|
||||
written++
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,7 +306,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
n, err = writeOpenMetricsSample(
|
||||
@ -314,7 +316,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeOpenMetricsSample(
|
||||
w, compliantName, "_count", metric, "", 0,
|
||||
@ -325,7 +327,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
createdTsBytesWritten, err = writeOpenMetricsCreated(w, compliantName, "", metric, "", 0, metric.Summary.GetCreatedTimestamp())
|
||||
n += createdTsBytesWritten
|
||||
}
|
||||
case dto.MetricType_HISTOGRAM:
|
||||
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||
if metric.Histogram == nil {
|
||||
return written, fmt.Errorf(
|
||||
"expected histogram in metric %s %s", compliantName, metric,
|
||||
@ -333,6 +335,12 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
}
|
||||
infSeen := false
|
||||
for _, b := range metric.Histogram.Bucket {
|
||||
if b.GetCumulativeCountFloat() > 0 {
|
||||
return written, fmt.Errorf(
|
||||
"OpenMetrics v1.0 does not support float histogram %s %s",
|
||||
compliantName, metric,
|
||||
)
|
||||
}
|
||||
n, err = writeOpenMetricsSample(
|
||||
w, compliantName, "_bucket", metric,
|
||||
model.BucketLabel, b.GetUpperBound(),
|
||||
@ -341,7 +349,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
if math.IsInf(b.GetUpperBound(), +1) {
|
||||
infSeen = true
|
||||
@ -354,9 +362,12 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
0, metric.Histogram.GetSampleCount(), true,
|
||||
nil,
|
||||
)
|
||||
// We do not check for a float sample count here
|
||||
// because we will check for it below (and error
|
||||
// out if needed).
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
n, err = writeOpenMetricsSample(
|
||||
@ -366,7 +377,13 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
if metric.Histogram.GetSampleCountFloat() > 0 {
|
||||
return written, fmt.Errorf(
|
||||
"OpenMetrics v1.0 does not support float histogram %s %s",
|
||||
compliantName, metric,
|
||||
)
|
||||
}
|
||||
n, err = writeOpenMetricsSample(
|
||||
w, compliantName, "_count", metric, "", 0,
|
||||
@ -384,10 +401,10 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...E
|
||||
}
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
|
||||
// FinalizeOpenMetrics writes the final `# EOF\n` line required by OpenMetrics.
|
||||
|
||||
58
vendor/github.com/prometheus/common/expfmt/text_create.go
generated
vendored
58
vendor/github.com/prometheus/common/expfmt/text_create.go
generated
vendored
@ -108,38 +108,38 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
||||
n, err = w.WriteString("# HELP ")
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeName(w, name)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
err = w.WriteByte(' ')
|
||||
written++
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeEscapedString(w, *in.Help, false)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
err = w.WriteByte('\n')
|
||||
written++
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
n, err = w.WriteString("# TYPE ")
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeName(w, name)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
metricType := in.GetType()
|
||||
switch metricType {
|
||||
@ -151,14 +151,17 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
||||
n, err = w.WriteString(" summary\n")
|
||||
case dto.MetricType_UNTYPED:
|
||||
n, err = w.WriteString(" untyped\n")
|
||||
case dto.MetricType_HISTOGRAM:
|
||||
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||
// The classic Prometheus text format has no notion of a gauge
|
||||
// histogram. We render a gauge histogram in the same way as a
|
||||
// regular histogram.
|
||||
n, err = w.WriteString(" histogram\n")
|
||||
default:
|
||||
return written, fmt.Errorf("unknown metric type %s", metricType.String())
|
||||
}
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
|
||||
// Finally the samples, one line for each.
|
||||
@ -208,7 +211,7 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
n, err = writeSample(
|
||||
@ -217,13 +220,13 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeSample(
|
||||
w, name, "_count", metric, "", 0,
|
||||
float64(metric.Summary.GetSampleCount()),
|
||||
)
|
||||
case dto.MetricType_HISTOGRAM:
|
||||
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||
if metric.Histogram == nil {
|
||||
return written, fmt.Errorf(
|
||||
"expected histogram in metric %s %s", name, metric,
|
||||
@ -231,28 +234,36 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
||||
}
|
||||
infSeen := false
|
||||
for _, b := range metric.Histogram.Bucket {
|
||||
v := b.GetCumulativeCountFloat()
|
||||
if v == 0 {
|
||||
v = float64(b.GetCumulativeCount())
|
||||
}
|
||||
n, err = writeSample(
|
||||
w, name, "_bucket", metric,
|
||||
model.BucketLabel, b.GetUpperBound(),
|
||||
float64(b.GetCumulativeCount()),
|
||||
v,
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
if math.IsInf(b.GetUpperBound(), +1) {
|
||||
infSeen = true
|
||||
}
|
||||
}
|
||||
if !infSeen {
|
||||
v := metric.Histogram.GetSampleCountFloat()
|
||||
if v == 0 {
|
||||
v = float64(metric.Histogram.GetSampleCount())
|
||||
}
|
||||
n, err = writeSample(
|
||||
w, name, "_bucket", metric,
|
||||
model.BucketLabel, math.Inf(+1),
|
||||
float64(metric.Histogram.GetSampleCount()),
|
||||
v,
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
n, err = writeSample(
|
||||
@ -261,12 +272,13 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
||||
)
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
n, err = writeSample(
|
||||
w, name, "_count", metric, "", 0,
|
||||
float64(metric.Histogram.GetSampleCount()),
|
||||
)
|
||||
v := metric.Histogram.GetSampleCountFloat()
|
||||
if v == 0 {
|
||||
v = float64(metric.Histogram.GetSampleCount())
|
||||
}
|
||||
n, err = writeSample(w, name, "_count", metric, "", 0, v)
|
||||
default:
|
||||
return written, fmt.Errorf(
|
||||
"unexpected type in metric %s %s", name, metric,
|
||||
@ -274,10 +286,10 @@ func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err e
|
||||
}
|
||||
written += n
|
||||
if err != nil {
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
return
|
||||
return written, err
|
||||
}
|
||||
|
||||
// writeSample writes a single sample in text format to w, given the metric
|
||||
|
||||
102
vendor/github.com/prometheus/common/expfmt/text_parse.go
generated
vendored
102
vendor/github.com/prometheus/common/expfmt/text_parse.go
generated
vendored
@ -48,8 +48,10 @@ func (e ParseError) Error() string {
|
||||
return fmt.Sprintf("text format parsing error in line %d: %s", e.Line, e.Msg)
|
||||
}
|
||||
|
||||
// TextParser is used to parse the simple and flat text-based exchange format. Its
|
||||
// zero value is ready to use.
|
||||
// TextParser is used to parse the simple and flat text-based exchange format.
|
||||
//
|
||||
// TextParser instances must be created with NewTextParser, the zero value of
|
||||
// TextParser is invalid.
|
||||
type TextParser struct {
|
||||
metricFamiliesByName map[string]*dto.MetricFamily
|
||||
buf *bufio.Reader // Where the parsed input is read through.
|
||||
@ -129,9 +131,44 @@ func (p *TextParser) TextToMetricFamilies(in io.Reader) (map[string]*dto.MetricF
|
||||
if p.err != nil && errors.Is(p.err, io.EOF) {
|
||||
p.parseError("unexpected end of input stream")
|
||||
}
|
||||
for _, histogramMetric := range p.histograms {
|
||||
normalizeHistogram(histogramMetric.GetHistogram())
|
||||
}
|
||||
return p.metricFamiliesByName, p.err
|
||||
}
|
||||
|
||||
// normalizeHistogram makes sure that all the buckets and the count in each
|
||||
// histogram is either completely float or completely integer.
|
||||
func normalizeHistogram(histogram *dto.Histogram) {
|
||||
if histogram == nil {
|
||||
return
|
||||
}
|
||||
anyFloats := false
|
||||
if histogram.GetSampleCountFloat() != 0 {
|
||||
anyFloats = true
|
||||
} else {
|
||||
for _, b := range histogram.GetBucket() {
|
||||
if b.GetCumulativeCountFloat() != 0 {
|
||||
anyFloats = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !anyFloats {
|
||||
return
|
||||
}
|
||||
if histogram.GetSampleCountFloat() == 0 {
|
||||
histogram.SampleCountFloat = proto.Float64(float64(histogram.GetSampleCount()))
|
||||
histogram.SampleCount = nil
|
||||
}
|
||||
for _, b := range histogram.GetBucket() {
|
||||
if b.GetCumulativeCountFloat() == 0 {
|
||||
b.CumulativeCountFloat = proto.Float64(float64(b.GetCumulativeCount()))
|
||||
b.CumulativeCount = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *TextParser) reset(in io.Reader) {
|
||||
p.metricFamiliesByName = map[string]*dto.MetricFamily{}
|
||||
p.currentLabelPairs = nil
|
||||
@ -281,7 +318,9 @@ func (p *TextParser) readingLabels() stateFn {
|
||||
// Summaries/histograms are special. We have to reset the
|
||||
// currentLabels map, currentQuantile and currentBucket before starting to
|
||||
// read labels.
|
||||
if p.currentMF.GetType() == dto.MetricType_SUMMARY || p.currentMF.GetType() == dto.MetricType_HISTOGRAM {
|
||||
if p.currentMF.GetType() == dto.MetricType_SUMMARY ||
|
||||
p.currentMF.GetType() == dto.MetricType_HISTOGRAM ||
|
||||
p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM {
|
||||
p.currentLabels = map[string]string{}
|
||||
p.currentLabels[string(model.MetricNameLabel)] = p.currentMF.GetName()
|
||||
p.currentQuantile = math.NaN()
|
||||
@ -374,7 +413,9 @@ func (p *TextParser) startLabelName() stateFn {
|
||||
// Special summary/histogram treatment. Don't add 'quantile' and 'le'
|
||||
// labels to 'real' labels.
|
||||
if (p.currentMF.GetType() != dto.MetricType_SUMMARY || p.currentLabelPair.GetName() != model.QuantileLabel) &&
|
||||
(p.currentMF.GetType() != dto.MetricType_HISTOGRAM || p.currentLabelPair.GetName() != model.BucketLabel) {
|
||||
((p.currentMF.GetType() != dto.MetricType_HISTOGRAM &&
|
||||
p.currentMF.GetType() != dto.MetricType_GAUGE_HISTOGRAM) ||
|
||||
p.currentLabelPair.GetName() != model.BucketLabel) {
|
||||
p.currentLabelPairs = append(p.currentLabelPairs, p.currentLabelPair)
|
||||
}
|
||||
// Check for duplicate label names.
|
||||
@ -425,7 +466,7 @@ func (p *TextParser) startLabelValue() stateFn {
|
||||
}
|
||||
}
|
||||
// Similar special treatment of histograms.
|
||||
if p.currentMF.GetType() == dto.MetricType_HISTOGRAM {
|
||||
if p.currentMF.GetType() == dto.MetricType_HISTOGRAM || p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM {
|
||||
if p.currentLabelPair.GetName() == model.BucketLabel {
|
||||
if p.currentBucket, p.err = parseFloat(p.currentLabelPair.GetValue()); p.err != nil {
|
||||
// Create a more helpful error message.
|
||||
@ -476,7 +517,7 @@ func (p *TextParser) readingValue() stateFn {
|
||||
p.summaries[signature] = p.currentMetric
|
||||
p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric)
|
||||
}
|
||||
case dto.MetricType_HISTOGRAM:
|
||||
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||
signature := model.LabelsToSignature(p.currentLabels)
|
||||
if histogram := p.histograms[signature]; histogram != nil {
|
||||
p.currentMetric = histogram
|
||||
@ -522,24 +563,38 @@ func (p *TextParser) readingValue() stateFn {
|
||||
},
|
||||
)
|
||||
}
|
||||
case dto.MetricType_HISTOGRAM:
|
||||
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
|
||||
// *sigh*
|
||||
if p.currentMetric.Histogram == nil {
|
||||
p.currentMetric.Histogram = &dto.Histogram{}
|
||||
}
|
||||
switch {
|
||||
case p.currentIsHistogramCount:
|
||||
p.currentMetric.Histogram.SampleCount = proto.Uint64(uint64(value))
|
||||
if uintValue := uint64(value); value == float64(uintValue) {
|
||||
p.currentMetric.Histogram.SampleCount = proto.Uint64(uintValue)
|
||||
} else {
|
||||
if value < 0 {
|
||||
p.parseError(fmt.Sprintf("negative count for histogram %q", p.currentMF.GetName()))
|
||||
return nil
|
||||
}
|
||||
p.currentMetric.Histogram.SampleCountFloat = proto.Float64(value)
|
||||
}
|
||||
case p.currentIsHistogramSum:
|
||||
p.currentMetric.Histogram.SampleSum = proto.Float64(value)
|
||||
case !math.IsNaN(p.currentBucket):
|
||||
p.currentMetric.Histogram.Bucket = append(
|
||||
p.currentMetric.Histogram.Bucket,
|
||||
&dto.Bucket{
|
||||
UpperBound: proto.Float64(p.currentBucket),
|
||||
CumulativeCount: proto.Uint64(uint64(value)),
|
||||
},
|
||||
)
|
||||
b := &dto.Bucket{
|
||||
UpperBound: proto.Float64(p.currentBucket),
|
||||
}
|
||||
if uintValue := uint64(value); value == float64(uintValue) {
|
||||
b.CumulativeCount = proto.Uint64(uintValue)
|
||||
} else {
|
||||
if value < 0 {
|
||||
p.parseError(fmt.Sprintf("negative bucket population for histogram %q", p.currentMF.GetName()))
|
||||
return nil
|
||||
}
|
||||
b.CumulativeCountFloat = proto.Float64(value)
|
||||
}
|
||||
p.currentMetric.Histogram.Bucket = append(p.currentMetric.Histogram.Bucket, b)
|
||||
}
|
||||
default:
|
||||
p.err = fmt.Errorf("unexpected type for metric name %q", p.currentMF.GetName())
|
||||
@ -602,10 +657,18 @@ func (p *TextParser) readingType() stateFn {
|
||||
if p.readTokenUntilNewline(false); p.err != nil {
|
||||
return nil // Unexpected end of input.
|
||||
}
|
||||
metricType, ok := dto.MetricType_value[strings.ToUpper(p.currentToken.String())]
|
||||
typ := strings.ToUpper(p.currentToken.String()) // Tolerate any combination of upper and lower case.
|
||||
metricType, ok := dto.MetricType_value[typ] // Tolerate "gauge_histogram" (not originally part of the text format).
|
||||
if !ok {
|
||||
p.parseError(fmt.Sprintf("unknown metric type %q", p.currentToken.String()))
|
||||
return nil
|
||||
// We also want to tolerate "gaugehistogram" to mark a gauge
|
||||
// histogram, because that string is used in OpenMetrics. Note,
|
||||
// however, that gauge histograms do not officially exist in the
|
||||
// classic text format.
|
||||
if typ != "GAUGEHISTOGRAM" {
|
||||
p.parseError(fmt.Sprintf("unknown metric type %q", p.currentToken.String()))
|
||||
return nil
|
||||
}
|
||||
metricType = int32(dto.MetricType_GAUGE_HISTOGRAM)
|
||||
}
|
||||
p.currentMF.Type = dto.MetricType(metricType).Enum()
|
||||
return p.startOfLine
|
||||
@ -855,7 +918,8 @@ func (p *TextParser) setOrCreateCurrentMF() {
|
||||
}
|
||||
histogramName := histogramMetricName(name)
|
||||
if p.currentMF = p.metricFamiliesByName[histogramName]; p.currentMF != nil {
|
||||
if p.currentMF.GetType() == dto.MetricType_HISTOGRAM {
|
||||
if p.currentMF.GetType() == dto.MetricType_HISTOGRAM ||
|
||||
p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM {
|
||||
if isCount(name) {
|
||||
p.currentIsHistogramCount = true
|
||||
}
|
||||
|
||||
28
vendor/github.com/prometheus/procfs/.golangci.yml
generated
vendored
28
vendor/github.com/prometheus/procfs/.golangci.yml
generated
vendored
@ -1,7 +1,9 @@
|
||||
version: "2"
|
||||
linters:
|
||||
enable:
|
||||
- errorlint
|
||||
- forbidigo
|
||||
- gocritic
|
||||
- godot
|
||||
- misspell
|
||||
- revive
|
||||
@ -11,6 +13,20 @@ linters:
|
||||
forbid:
|
||||
- pattern: ^fmt\.Print.*$
|
||||
msg: Do not commit print statements.
|
||||
gocritic:
|
||||
enable-all: true
|
||||
disabled-checks:
|
||||
- commentFormatting
|
||||
- commentedOutCode
|
||||
- deferInLoop
|
||||
- filepathJoin
|
||||
- hugeParam
|
||||
- importShadow
|
||||
- paramTypeCombine
|
||||
- rangeValCopy
|
||||
- tooManyResultsChecker
|
||||
- unnamedResult
|
||||
- whyNoLint
|
||||
godot:
|
||||
exclude:
|
||||
# Ignore "See: URL".
|
||||
@ -19,16 +35,12 @@ linters:
|
||||
misspell:
|
||||
locale: US
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
warn-unused: true
|
||||
formatters:
|
||||
enable:
|
||||
- gofmt
|
||||
@ -37,9 +49,3 @@ formatters:
|
||||
goimports:
|
||||
local-prefixes:
|
||||
- github.com/prometheus/procfs
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/Makefile
generated
vendored
2
vendor/github.com/prometheus/procfs/Makefile
generated
vendored
@ -1,4 +1,4 @@
|
||||
# Copyright 2018 The Prometheus Authors
|
||||
# Copyright The Prometheus Authors
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/Makefile.common
generated
vendored
2
vendor/github.com/prometheus/procfs/Makefile.common
generated
vendored
@ -139,7 +139,7 @@ common-deps:
|
||||
update-go-deps:
|
||||
@echo ">> updating Go dependencies"
|
||||
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
|
||||
$(GO) get -d $$m; \
|
||||
$(GO) get $$m; \
|
||||
done
|
||||
$(GO) mod tidy
|
||||
|
||||
|
||||
9
vendor/github.com/prometheus/procfs/arp.go
generated
vendored
9
vendor/github.com/prometheus/procfs/arp.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -73,15 +73,16 @@ func parseARPEntries(data []byte) ([]ARPEntry, error) {
|
||||
columns := strings.Fields(line)
|
||||
width := len(columns)
|
||||
|
||||
if width == expectedHeaderWidth || width == 0 {
|
||||
switch width {
|
||||
case expectedHeaderWidth, 0:
|
||||
continue
|
||||
} else if width == expectedDataWidth {
|
||||
case expectedDataWidth:
|
||||
entry, err := parseARPEntry(columns)
|
||||
if err != nil {
|
||||
return []ARPEntry{}, fmt.Errorf("%w: Failed to parse ARP entry: %v: %w", ErrFileParse, entry, err)
|
||||
}
|
||||
entries = append(entries, entry)
|
||||
} else {
|
||||
default:
|
||||
return []ARPEntry{}, fmt.Errorf("%w: %d columns found, but expected %d: %w", ErrFileParse, width, expectedDataWidth, err)
|
||||
}
|
||||
|
||||
|
||||
10
vendor/github.com/prometheus/procfs/buddyinfo.go
generated
vendored
10
vendor/github.com/prometheus/procfs/buddyinfo.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2017 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -64,14 +64,12 @@ func parseBuddyInfo(r io.Reader) ([]BuddyInfo, error) {
|
||||
|
||||
if bucketCount == -1 {
|
||||
bucketCount = arraySize
|
||||
} else {
|
||||
if bucketCount != arraySize {
|
||||
return nil, fmt.Errorf("%w: mismatch in number of buddyinfo buckets, previous count %d, new count %d", ErrFileParse, bucketCount, arraySize)
|
||||
}
|
||||
} else if bucketCount != arraySize {
|
||||
return nil, fmt.Errorf("%w: mismatch in number of buddyinfo buckets, previous count %d, new count %d", ErrFileParse, bucketCount, arraySize)
|
||||
}
|
||||
|
||||
sizes := make([]float64, arraySize)
|
||||
for i := 0; i < arraySize; i++ {
|
||||
for i := range arraySize {
|
||||
sizes[i], err = strconv.ParseFloat(parts[i+4], 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: Invalid valid in buddyinfo: %f: %w", ErrFileParse, sizes[i], err)
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cmdline.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cmdline.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2021 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo_armx.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo_armx.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo_loong64.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo_loong64.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo_mipsx.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo_mipsx.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo_others.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo_others.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo_ppcx.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo_ppcx.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo_riscvx.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo_riscvx.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo_s390x.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo_s390x.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/cpuinfo_x86.go
generated
vendored
2
vendor/github.com/prometheus/procfs/cpuinfo_x86.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/crypto.go
generated
vendored
2
vendor/github.com/prometheus/procfs/crypto.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/doc.go
generated
vendored
2
vendor/github.com/prometheus/procfs/doc.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2014 Prometheus Team
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/fs.go
generated
vendored
2
vendor/github.com/prometheus/procfs/fs.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/fs_statfs_notype.go
generated
vendored
2
vendor/github.com/prometheus/procfs/fs_statfs_notype.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/fs_statfs_type.go
generated
vendored
2
vendor/github.com/prometheus/procfs/fs_statfs_type.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
9
vendor/github.com/prometheus/procfs/fscache.go
generated
vendored
9
vendor/github.com/prometheus/procfs/fscache.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -388,20 +388,21 @@ func parseFscacheinfo(r io.Reader) (*Fscacheinfo, error) {
|
||||
}
|
||||
}
|
||||
case "CacheOp:":
|
||||
if strings.Split(fields[1], "=")[0] == "alo" {
|
||||
switch strings.Split(fields[1], "=")[0] {
|
||||
case "alo":
|
||||
err := setFSCacheFields(fields[1:], &m.CacheopAllocationsinProgress, &m.CacheopLookupObjectInProgress,
|
||||
&m.CacheopLookupCompleteInPorgress, &m.CacheopGrabObjectInProgress)
|
||||
if err != nil {
|
||||
return &m, err
|
||||
}
|
||||
} else if strings.Split(fields[1], "=")[0] == "inv" {
|
||||
case "inv":
|
||||
err := setFSCacheFields(fields[1:], &m.CacheopInvalidations, &m.CacheopUpdateObjectInProgress,
|
||||
&m.CacheopDropObjectInProgress, &m.CacheopPutObjectInProgress, &m.CacheopAttributeChangeInProgress,
|
||||
&m.CacheopSyncCacheInProgress)
|
||||
if err != nil {
|
||||
return &m, err
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
err := setFSCacheFields(fields[1:], &m.CacheopReadOrAllocPageInProgress, &m.CacheopReadOrAllocPagesInProgress,
|
||||
&m.CacheopAllocatePageInProgress, &m.CacheopAllocatePagesInProgress, &m.CacheopWritePagesInProgress,
|
||||
&m.CacheopUncachePagesInProgress, &m.CacheopDissociatePagesInProgress)
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/internal/fs/fs.go
generated
vendored
2
vendor/github.com/prometheus/procfs/internal/fs/fs.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/internal/util/parse.go
generated
vendored
2
vendor/github.com/prometheus/procfs/internal/util/parse.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/internal/util/readfile.go
generated
vendored
2
vendor/github.com/prometheus/procfs/internal/util/readfile.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go
generated
vendored
2
vendor/github.com/prometheus/procfs/internal/util/sysreadfile.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/internal/util/sysreadfile_compat.go
generated
vendored
2
vendor/github.com/prometheus/procfs/internal/util/sysreadfile_compat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/internal/util/valueparser.go
generated
vendored
2
vendor/github.com/prometheus/procfs/internal/util/valueparser.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/ipvs.go
generated
vendored
2
vendor/github.com/prometheus/procfs/ipvs.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
45
vendor/github.com/prometheus/procfs/kernel_hung.go
generated
vendored
Normal file
45
vendor/github.com/prometheus/procfs/kernel_hung.go
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// KernelHung contains information about to the kernel's hung_task_detect_count number.
|
||||
type KernelHung struct {
|
||||
// Indicates the total number of tasks that have been detected as hung since the system boot.
|
||||
// This file shows up if `CONFIG_DETECT_HUNG_TASK` is enabled.
|
||||
HungTaskDetectCount *uint64
|
||||
}
|
||||
|
||||
// KernelHung returns values from /proc/sys/kernel/hung_task_detect_count.
|
||||
func (fs FS) KernelHung() (KernelHung, error) {
|
||||
data, err := os.ReadFile(fs.proc.Path("sys", "kernel", "hung_task_detect_count"))
|
||||
if err != nil {
|
||||
return KernelHung{}, err
|
||||
}
|
||||
val, err := strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64)
|
||||
if err != nil {
|
||||
return KernelHung{}, err
|
||||
}
|
||||
return KernelHung{
|
||||
HungTaskDetectCount: &val,
|
||||
}, nil
|
||||
}
|
||||
2
vendor/github.com/prometheus/procfs/kernel_random.go
generated
vendored
2
vendor/github.com/prometheus/procfs/kernel_random.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/loadavg.go
generated
vendored
2
vendor/github.com/prometheus/procfs/loadavg.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
118
vendor/github.com/prometheus/procfs/mdstat.go
generated
vendored
118
vendor/github.com/prometheus/procfs/mdstat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -27,13 +27,34 @@ var (
|
||||
recoveryLinePctRE = regexp.MustCompile(`= (.+)%`)
|
||||
recoveryLineFinishRE = regexp.MustCompile(`finish=(.+)min`)
|
||||
recoveryLineSpeedRE = regexp.MustCompile(`speed=(.+)[A-Z]`)
|
||||
componentDeviceRE = regexp.MustCompile(`(.*)\[\d+\]`)
|
||||
componentDeviceRE = regexp.MustCompile(`(.*)\[(\d+)\](\([SF]+\))?`)
|
||||
personalitiesPrefix = "Personalities : "
|
||||
)
|
||||
|
||||
type MDStatComponent struct {
|
||||
// Name of the component device.
|
||||
Name string
|
||||
// DescriptorIndex number of component device, e.g. the order in the superblock.
|
||||
DescriptorIndex int32
|
||||
// Flags per Linux drivers/md/md.[ch] as of v6.12-rc1
|
||||
// Subset that are exposed in mdstat
|
||||
WriteMostly bool
|
||||
Journal bool
|
||||
Faulty bool // "Faulty" is what kernel source uses for "(F)"
|
||||
Spare bool
|
||||
Replacement bool
|
||||
// Some additional flags that are NOT exposed in procfs today; they may
|
||||
// be available via sysfs.
|
||||
// In_sync, Bitmap_sync, Blocked, WriteErrorSeen, FaultRecorded,
|
||||
// BlockedBadBlocks, WantReplacement, Candidate, ...
|
||||
}
|
||||
|
||||
// MDStat holds info parsed from /proc/mdstat.
|
||||
type MDStat struct {
|
||||
// Name of the device.
|
||||
Name string
|
||||
// raid type of the device.
|
||||
Type string
|
||||
// activity-state of the device.
|
||||
ActivityState string
|
||||
// Number of active disks.
|
||||
@ -58,8 +79,8 @@ type MDStat struct {
|
||||
BlocksSyncedFinishTime float64
|
||||
// current sync speed (in Kilobytes/sec)
|
||||
BlocksSyncedSpeed float64
|
||||
// Name of md component devices
|
||||
Devices []string
|
||||
// component devices
|
||||
Devices []MDStatComponent
|
||||
}
|
||||
|
||||
// MDStat parses an mdstat-file (/proc/mdstat) and returns a slice of
|
||||
@ -80,28 +101,52 @@ func (fs FS) MDStat() ([]MDStat, error) {
|
||||
// parseMDStat parses data from mdstat file (/proc/mdstat) and returns a slice of
|
||||
// structs containing the relevant info.
|
||||
func parseMDStat(mdStatData []byte) ([]MDStat, error) {
|
||||
// TODO:
|
||||
// - parse global hotspares from the "unused devices" line.
|
||||
mdStats := []MDStat{}
|
||||
lines := strings.Split(string(mdStatData), "\n")
|
||||
knownRaidTypes := make(map[string]bool)
|
||||
|
||||
for i, line := range lines {
|
||||
if strings.TrimSpace(line) == "" || line[0] == ' ' ||
|
||||
strings.HasPrefix(line, "Personalities") ||
|
||||
strings.HasPrefix(line, "unused") {
|
||||
continue
|
||||
}
|
||||
// Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
|
||||
if len(knownRaidTypes) == 0 && strings.HasPrefix(line, personalitiesPrefix) {
|
||||
personalities := strings.Fields(line[len(personalitiesPrefix):])
|
||||
for _, word := range personalities {
|
||||
word := word[1 : len(word)-1]
|
||||
knownRaidTypes[word] = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
deviceFields := strings.Fields(line)
|
||||
if len(deviceFields) < 3 {
|
||||
return nil, fmt.Errorf("%w: Expected 3+ lines, got %q", ErrFileParse, line)
|
||||
}
|
||||
mdName := deviceFields[0] // mdx
|
||||
state := deviceFields[2] // active or inactive
|
||||
state := deviceFields[2] // active, inactive, broken
|
||||
|
||||
mdType := "unknown" // raid1, raid5, etc.
|
||||
var deviceStartIndex int
|
||||
if len(deviceFields) > 3 { // mdType may be in the 3rd or 4th field
|
||||
if isRaidType(deviceFields[3], knownRaidTypes) {
|
||||
mdType = deviceFields[3]
|
||||
deviceStartIndex = 4
|
||||
} else if len(deviceFields) > 4 && isRaidType(deviceFields[4], knownRaidTypes) {
|
||||
// if the 3rd field is (...), the 4th field is the mdType
|
||||
mdType = deviceFields[4]
|
||||
deviceStartIndex = 5
|
||||
}
|
||||
}
|
||||
|
||||
if len(lines) <= i+3 {
|
||||
return nil, fmt.Errorf("%w: Too few lines for md device: %q", ErrFileParse, mdName)
|
||||
}
|
||||
|
||||
// Failed disks have the suffix (F) & Spare disks have the suffix (S).
|
||||
// Failed (Faulty) disks have the suffix (F) & Spare disks have the suffix (S).
|
||||
fail := int64(strings.Count(line, "(F)"))
|
||||
spare := int64(strings.Count(line, "(S)"))
|
||||
active, total, down, size, err := evalStatusLine(lines[i], lines[i+1])
|
||||
@ -129,13 +174,14 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
|
||||
|
||||
// Append recovery and resyncing state info.
|
||||
if recovering || resyncing || checking || reshaping {
|
||||
if recovering {
|
||||
switch {
|
||||
case recovering:
|
||||
state = "recovering"
|
||||
} else if reshaping {
|
||||
case reshaping:
|
||||
state = "reshaping"
|
||||
} else if checking {
|
||||
case checking:
|
||||
state = "checking"
|
||||
} else {
|
||||
default:
|
||||
state = "resyncing"
|
||||
}
|
||||
|
||||
@ -151,8 +197,14 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
|
||||
}
|
||||
}
|
||||
|
||||
devices, err := evalComponentDevices(deviceFields[deviceStartIndex:])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing components in md device %q: %w", mdName, err)
|
||||
}
|
||||
|
||||
mdStats = append(mdStats, MDStat{
|
||||
Name: mdName,
|
||||
Type: mdType,
|
||||
ActivityState: state,
|
||||
DisksActive: active,
|
||||
DisksFailed: fail,
|
||||
@ -165,14 +217,24 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
|
||||
BlocksSyncedPct: pct,
|
||||
BlocksSyncedFinishTime: finish,
|
||||
BlocksSyncedSpeed: speed,
|
||||
Devices: evalComponentDevices(deviceFields),
|
||||
Devices: devices,
|
||||
})
|
||||
}
|
||||
|
||||
return mdStats, nil
|
||||
}
|
||||
|
||||
// check if a string's format is like the mdType
|
||||
// Rule 1: mdType should not be like (...)
|
||||
// Rule 2: mdType should not be like sda[0]
|
||||
// .
|
||||
func isRaidType(mdType string, knownRaidTypes map[string]bool) bool {
|
||||
_, ok := knownRaidTypes[mdType]
|
||||
return !strings.ContainsAny(mdType, "([") && ok
|
||||
}
|
||||
|
||||
func evalStatusLine(deviceLine, statusLine string) (active, total, down, size int64, err error) {
|
||||
// e.g. 523968 blocks super 1.2 [4/4] [UUUU]
|
||||
statusFields := strings.Fields(statusLine)
|
||||
if len(statusFields) < 1 {
|
||||
return 0, 0, 0, 0, fmt.Errorf("%w: Unexpected statusline %q: %w", ErrFileParse, statusLine, err)
|
||||
@ -263,17 +325,29 @@ func evalRecoveryLine(recoveryLine string) (blocksSynced int64, blocksToBeSynced
|
||||
return blocksSynced, blocksToBeSynced, pct, finish, speed, nil
|
||||
}
|
||||
|
||||
func evalComponentDevices(deviceFields []string) []string {
|
||||
mdComponentDevices := make([]string, 0)
|
||||
if len(deviceFields) > 3 {
|
||||
for _, field := range deviceFields[4:] {
|
||||
match := componentDeviceRE.FindStringSubmatch(field)
|
||||
if match == nil {
|
||||
continue
|
||||
}
|
||||
mdComponentDevices = append(mdComponentDevices, match[1])
|
||||
func evalComponentDevices(deviceFields []string) ([]MDStatComponent, error) {
|
||||
mdComponentDevices := make([]MDStatComponent, 0)
|
||||
for _, field := range deviceFields {
|
||||
match := componentDeviceRE.FindStringSubmatch(field)
|
||||
if match == nil {
|
||||
continue
|
||||
}
|
||||
descriptorIndex, err := strconv.ParseInt(match[2], 10, 32)
|
||||
if err != nil {
|
||||
return mdComponentDevices, fmt.Errorf("error parsing int from device %q: %w", match[2], err)
|
||||
}
|
||||
mdComponentDevices = append(mdComponentDevices, MDStatComponent{
|
||||
Name: match[1],
|
||||
DescriptorIndex: int32(descriptorIndex),
|
||||
// match may contain one or more of these
|
||||
// https://github.com/torvalds/linux/blob/7ec462100ef9142344ddbf86f2c3008b97acddbe/drivers/md/md.c#L8376-L8392
|
||||
Faulty: strings.Contains(match[3], "(F)"),
|
||||
Spare: strings.Contains(match[3], "(S)"),
|
||||
Journal: strings.Contains(match[3], "(J)"),
|
||||
Replacement: strings.Contains(match[3], "(R)"),
|
||||
WriteMostly: strings.Contains(match[3], "(W)"),
|
||||
})
|
||||
}
|
||||
|
||||
return mdComponentDevices
|
||||
return mdComponentDevices, nil
|
||||
}
|
||||
|
||||
4
vendor/github.com/prometheus/procfs/meminfo.go
generated
vendored
4
vendor/github.com/prometheus/procfs/meminfo.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -307,7 +307,7 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) {
|
||||
m.ZswapBytes = &valBytes
|
||||
case "Zswapped:":
|
||||
m.Zswapped = &val
|
||||
m.ZswapBytes = &valBytes
|
||||
m.ZswappedBytes = &valBytes
|
||||
case "Dirty:":
|
||||
m.Dirty = &val
|
||||
m.DirtyBytes = &valBytes
|
||||
|
||||
23
vendor/github.com/prometheus/procfs/mountinfo.go
generated
vendored
23
vendor/github.com/prometheus/procfs/mountinfo.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -147,8 +147,7 @@ func mountOptionsParseOptionalFields(o []string) (map[string]string, error) {
|
||||
// mountOptionsParser parses the mount options, superblock options.
|
||||
func mountOptionsParser(mountOptions string) map[string]string {
|
||||
opts := make(map[string]string)
|
||||
options := strings.Split(mountOptions, ",")
|
||||
for _, opt := range options {
|
||||
for opt := range strings.SplitSeq(mountOptions, ",") {
|
||||
splitOption := strings.Split(opt, "=")
|
||||
if len(splitOption) < 2 {
|
||||
key := splitOption[0]
|
||||
@ -178,3 +177,21 @@ func GetProcMounts(pid int) ([]*MountInfo, error) {
|
||||
}
|
||||
return parseMountInfo(data)
|
||||
}
|
||||
|
||||
// GetMounts retrieves mountinfo information from `/proc/self/mountinfo`.
|
||||
func (fs FS) GetMounts() ([]*MountInfo, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("self/mountinfo"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseMountInfo(data)
|
||||
}
|
||||
|
||||
// GetProcMounts retrieves mountinfo information from a processes' `/proc/<pid>/mountinfo`.
|
||||
func (fs FS) GetProcMounts(pid int) ([]*MountInfo, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path(fmt.Sprintf("%d/mountinfo", pid)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseMountInfo(data)
|
||||
}
|
||||
|
||||
4
vendor/github.com/prometheus/procfs/mountstats.go
generated
vendored
4
vendor/github.com/prometheus/procfs/mountstats.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -383,7 +383,7 @@ func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, e
|
||||
if stats.Opts == nil {
|
||||
stats.Opts = map[string]string{}
|
||||
}
|
||||
for _, opt := range strings.Split(ss[1], ",") {
|
||||
for opt := range strings.SplitSeq(ss[1], ",") {
|
||||
split := strings.Split(opt, "=")
|
||||
if len(split) == 2 {
|
||||
stats.Opts[split[0]] = split[1]
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_conntrackstat.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_conntrackstat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_dev.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_dev.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
7
vendor/github.com/prometheus/procfs/net_dev_snmp6.go
generated
vendored
7
vendor/github.com/prometheus/procfs/net_dev_snmp6.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -56,7 +57,9 @@ func newNetDevSNMP6(dir string) (NetDevSNMP6, error) {
|
||||
}
|
||||
|
||||
for _, iFaceFile := range ifaceFiles {
|
||||
f, err := os.Open(dir + "/" + iFaceFile.Name())
|
||||
filePath := filepath.Join(dir, iFaceFile.Name())
|
||||
|
||||
f, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return netDevSNMP6, err
|
||||
}
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_ip_socket.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_ip_socket.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
4
vendor/github.com/prometheus/procfs/net_protocols.go
generated
vendored
4
vendor/github.com/prometheus/procfs/net_protocols.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -169,7 +169,7 @@ func (pc *NetProtocolCapabilities) parseCapabilities(capabilities []string) erro
|
||||
&pc.EnterMemoryPressure,
|
||||
}
|
||||
|
||||
for i := 0; i < len(capabilities); i++ {
|
||||
for i := range capabilities {
|
||||
switch capabilities[i] {
|
||||
case "y":
|
||||
*capabilityFields[i] = true
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_route.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_route.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2023 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
5
vendor/github.com/prometheus/procfs/net_sockstat.go
generated
vendored
5
vendor/github.com/prometheus/procfs/net_sockstat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -139,9 +139,6 @@ func parseSockstatKVs(kvs []string) (map[string]int, error) {
|
||||
func parseSockstatProtocol(kvs map[string]int) NetSockstatProtocol {
|
||||
var nsp NetSockstatProtocol
|
||||
for k, v := range kvs {
|
||||
// Capture the range variable to ensure we get unique pointers for
|
||||
// each of the optional fields.
|
||||
v := v
|
||||
switch k {
|
||||
case "inuse":
|
||||
nsp.InUse = v
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_softnet.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_softnet.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_tcp.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_tcp.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_tls_stat.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_tls_stat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2023 Prometheus Team
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_udp.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_udp.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_unix.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_unix.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_wireless.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_wireless.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2023 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/net_xfrm.go
generated
vendored
2
vendor/github.com/prometheus/procfs/net_xfrm.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2017 Prometheus Team
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/netstat.go
generated
vendored
2
vendor/github.com/prometheus/procfs/netstat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
85
vendor/github.com/prometheus/procfs/nfnetlink_queue.go
generated
vendored
Normal file
85
vendor/github.com/prometheus/procfs/nfnetlink_queue.go
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
)
|
||||
|
||||
const nfNetLinkQueueFormat = "%d %d %d %d %d %d %d %d %d"
|
||||
|
||||
// NFNetLinkQueue contains general information about netfilter queues found in /proc/net/netfilter/nfnetlink_queue.
|
||||
type NFNetLinkQueue struct {
|
||||
// id of the queue
|
||||
QueueID uint
|
||||
// pid of process handling the queue
|
||||
PeerPID uint
|
||||
// number of packets waiting for a decision
|
||||
QueueTotal uint
|
||||
// indicate how userspace receive packets
|
||||
CopyMode uint
|
||||
// size of copy
|
||||
CopyRange uint
|
||||
// number of items dropped by the kernel because too many packets were waiting a decision.
|
||||
// It queue_total is superior to queue_max_len (1024 per default) the packets are dropped.
|
||||
QueueDropped uint
|
||||
// number of packets dropped by userspace (due to kernel send failure on the netlink socket)
|
||||
QueueUserDropped uint
|
||||
// sequence number of packets queued. It gives a correct approximation of the number of queued packets.
|
||||
SequenceID uint
|
||||
// internal value (number of entity using the queue)
|
||||
Use uint
|
||||
}
|
||||
|
||||
// NFNetLinkQueue returns information about current state of netfilter queues.
|
||||
func (fs FS) NFNetLinkQueue() ([]NFNetLinkQueue, error) {
|
||||
data, err := util.ReadFileNoStat(fs.proc.Path("net/netfilter/nfnetlink_queue"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queue := []NFNetLinkQueue{}
|
||||
if len(data) == 0 {
|
||||
return queue, nil
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(bytes.NewReader(data))
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
nFNetLinkQueue, err := parseNFNetLinkQueueLine(line)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
queue = append(queue, *nFNetLinkQueue)
|
||||
}
|
||||
return queue, nil
|
||||
}
|
||||
|
||||
// parseNFNetLinkQueueLine parses each line of the /proc/net/netfilter/nfnetlink_queue file.
|
||||
func parseNFNetLinkQueueLine(line string) (*NFNetLinkQueue, error) {
|
||||
nFNetLinkQueue := NFNetLinkQueue{}
|
||||
_, err := fmt.Sscanf(
|
||||
line, nfNetLinkQueueFormat,
|
||||
&nFNetLinkQueue.QueueID, &nFNetLinkQueue.PeerPID, &nFNetLinkQueue.QueueTotal, &nFNetLinkQueue.CopyMode,
|
||||
&nFNetLinkQueue.CopyRange, &nFNetLinkQueue.QueueDropped, &nFNetLinkQueue.QueueUserDropped, &nFNetLinkQueue.SequenceID, &nFNetLinkQueue.Use,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &nFNetLinkQueue, nil
|
||||
}
|
||||
4
vendor/github.com/prometheus/procfs/proc.go
generated
vendored
4
vendor/github.com/prometheus/procfs/proc.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -49,7 +49,7 @@ func (p Procs) Less(i, j int) bool { return p[i].PID < p[j].PID }
|
||||
// Self returns a process for the current process read via /proc/self.
|
||||
func Self() (Proc, error) {
|
||||
fs, err := NewFS(DefaultMountPoint)
|
||||
if err != nil || errors.Unwrap(err) == ErrMountPoint {
|
||||
if err != nil || errors.Is(err, ErrMountPoint) {
|
||||
return Proc{}, err
|
||||
}
|
||||
return fs.Self()
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_cgroup.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_cgroup.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
8
vendor/github.com/prometheus/procfs/proc_cgroups.go
generated
vendored
8
vendor/github.com/prometheus/procfs/proc_cgroups.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2021 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -40,13 +40,13 @@ type CgroupSummary struct {
|
||||
|
||||
// parseCgroupSummary parses each line of the /proc/cgroup file
|
||||
// Line format is `subsys_name hierarchy num_cgroups enabled`.
|
||||
func parseCgroupSummaryString(CgroupSummaryStr string) (*CgroupSummary, error) {
|
||||
func parseCgroupSummaryString(cgroupSummaryStr string) (*CgroupSummary, error) {
|
||||
var err error
|
||||
|
||||
fields := strings.Fields(CgroupSummaryStr)
|
||||
fields := strings.Fields(cgroupSummaryStr)
|
||||
// require at least 4 fields
|
||||
if len(fields) < 4 {
|
||||
return nil, fmt.Errorf("%w: 4+ fields required, found %d fields in cgroup info string: %s", ErrFileParse, len(fields), CgroupSummaryStr)
|
||||
return nil, fmt.Errorf("%w: 4+ fields required, found %d fields in cgroup info string: %s", ErrFileParse, len(fields), cgroupSummaryStr)
|
||||
}
|
||||
|
||||
CgroupSummary := &CgroupSummary{
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_environ.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_environ.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
13
vendor/github.com/prometheus/procfs/proc_fdinfo.go
generated
vendored
13
vendor/github.com/prometheus/procfs/proc_fdinfo.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -60,15 +60,16 @@ func (p Proc) FDInfo(fd string) (*ProcFDInfo, error) {
|
||||
scanner := bufio.NewScanner(bytes.NewReader(data))
|
||||
for scanner.Scan() {
|
||||
text = scanner.Text()
|
||||
if rPos.MatchString(text) {
|
||||
switch {
|
||||
case rPos.MatchString(text):
|
||||
pos = rPos.FindStringSubmatch(text)[1]
|
||||
} else if rFlags.MatchString(text) {
|
||||
case rFlags.MatchString(text):
|
||||
flags = rFlags.FindStringSubmatch(text)[1]
|
||||
} else if rMntID.MatchString(text) {
|
||||
case rMntID.MatchString(text):
|
||||
mntid = rMntID.FindStringSubmatch(text)[1]
|
||||
} else if rIno.MatchString(text) {
|
||||
case rIno.MatchString(text):
|
||||
ino = rIno.FindStringSubmatch(text)[1]
|
||||
} else if rInotify.MatchString(text) {
|
||||
case rInotify.MatchString(text):
|
||||
newInotify, err := parseInotifyInfo(text)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_interrupts.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_interrupts.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_io.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_io.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
7
vendor/github.com/prometheus/procfs/proc_limits.go
generated
vendored
7
vendor/github.com/prometheus/procfs/proc_limits.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -19,6 +19,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ProcLimits represents the soft limits for each of the process's resource
|
||||
@ -74,7 +75,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
limitsMatch = regexp.MustCompile(`(Max \w+\s{0,1}?\w*\s{0,1}\w*)\s{2,}(\w+)\s+(\w+)`)
|
||||
limitsMatch = regexp.MustCompile(`(Max \w+\s??\w*\s?\w*)\s{2,}(\w+)\s+(\w+)`)
|
||||
)
|
||||
|
||||
// NewLimits returns the current soft limits of the process.
|
||||
@ -106,7 +107,7 @@ func (p Proc) Limits() (ProcLimits, error) {
|
||||
return ProcLimits{}, fmt.Errorf("%w: couldn't parse %q line %q", ErrFileParse, f.Name(), s.Text())
|
||||
}
|
||||
|
||||
switch fields[1] {
|
||||
switch strings.TrimSpace(fields[1]) {
|
||||
case "Max cpu time":
|
||||
l.CPUTime, err = parseUint(fields[2])
|
||||
case "Max file size":
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_maps.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_maps.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_netstat.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_netstat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_ns.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_ns.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_psi.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_psi.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_smaps.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_smaps.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_snmp.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_snmp.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_snmp6.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_snmp6.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_stat.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_stat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
4
vendor/github.com/prometheus/procfs/proc_statm.go
generated
vendored
4
vendor/github.com/prometheus/procfs/proc_statm.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2025 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -80,7 +80,7 @@ func (p Proc) Statm() (ProcStatm, error) {
|
||||
func parseStatm(data []byte) ([]uint64, error) {
|
||||
var statmSlice []uint64
|
||||
statmItems := strings.Fields(string(data))
|
||||
for i := 0; i < len(statmItems); i++ {
|
||||
for i := range statmItems {
|
||||
statmItem, err := strconv.ParseUint(statmItems[i], 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
9
vendor/github.com/prometheus/procfs/proc_status.go
generated
vendored
9
vendor/github.com/prometheus/procfs/proc_status.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -16,7 +16,7 @@ package procfs
|
||||
import (
|
||||
"bytes"
|
||||
"math/bits"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -94,8 +94,7 @@ func (p Proc) NewStatus() (ProcStatus, error) {
|
||||
|
||||
s := ProcStatus{PID: p.PID}
|
||||
|
||||
lines := strings.Split(string(data), "\n")
|
||||
for _, line := range lines {
|
||||
for line := range strings.SplitSeq(string(data), "\n") {
|
||||
if !bytes.Contains([]byte(line), []byte(":")) {
|
||||
continue
|
||||
}
|
||||
@ -222,7 +221,7 @@ func calcCpusAllowedList(cpuString string) []uint64 {
|
||||
|
||||
}
|
||||
|
||||
sort.Slice(g, func(i, j int) bool { return g[i] < g[j] })
|
||||
slices.Sort(g)
|
||||
return g
|
||||
}
|
||||
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/proc_sys.go
generated
vendored
2
vendor/github.com/prometheus/procfs/proc_sys.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/schedstat.go
generated
vendored
2
vendor/github.com/prometheus/procfs/schedstat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/slab.go
generated
vendored
2
vendor/github.com/prometheus/procfs/slab.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/softirqs.go
generated
vendored
2
vendor/github.com/prometheus/procfs/softirqs.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
5
vendor/github.com/prometheus/procfs/stat.go
generated
vendored
5
vendor/github.com/prometheus/procfs/stat.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -16,6 +16,7 @@ package procfs
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
@ -92,7 +93,7 @@ func parseCPUStat(line string) (CPUStat, int64, error) {
|
||||
&cpuStat.Iowait, &cpuStat.IRQ, &cpuStat.SoftIRQ, &cpuStat.Steal,
|
||||
&cpuStat.Guest, &cpuStat.GuestNice)
|
||||
|
||||
if err != nil && err != io.EOF {
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return CPUStat{}, -1, fmt.Errorf("%w: couldn't parse %q (cpu): %w", ErrFileParse, line, err)
|
||||
}
|
||||
if count == 0 {
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/swaps.go
generated
vendored
2
vendor/github.com/prometheus/procfs/swaps.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/thread.go
generated
vendored
2
vendor/github.com/prometheus/procfs/thread.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
2
vendor/github.com/prometheus/procfs/vm.go
generated
vendored
2
vendor/github.com/prometheus/procfs/vm.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
8
vendor/github.com/prometheus/procfs/zoneinfo.go
generated
vendored
8
vendor/github.com/prometheus/procfs/zoneinfo.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Prometheus Authors
|
||||
// Copyright The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
@ -88,11 +88,9 @@ func parseZoneinfo(zoneinfoData []byte) ([]Zoneinfo, error) {
|
||||
|
||||
zoneinfo := []Zoneinfo{}
|
||||
|
||||
zoneinfoBlocks := bytes.Split(zoneinfoData, []byte("\nNode"))
|
||||
for _, block := range zoneinfoBlocks {
|
||||
for block := range bytes.SplitSeq(zoneinfoData, []byte("\nNode")) {
|
||||
var zoneinfoElement Zoneinfo
|
||||
lines := strings.Split(string(block), "\n")
|
||||
for _, line := range lines {
|
||||
for line := range strings.SplitSeq(string(block), "\n") {
|
||||
|
||||
if nodeZone := nodeZoneRE.FindStringSubmatch(line); nodeZone != nil {
|
||||
zoneinfoElement.Node = nodeZone[1]
|
||||
|
||||
Reference in New Issue
Block a user