Skip to content

Commit

Permalink
fix queryid
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmarsh committed Feb 11, 2023
1 parent 166dc62 commit 9ee55d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
39 changes: 20 additions & 19 deletions exporter/collectors/pg_stat_statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package collectors
import (
"context"
"fmt"
"strconv"
"sync"

"github.com/odonate/postgres-exporter/exporter/db"
Expand Down Expand Up @@ -199,25 +200,25 @@ func (c *PgStatStatementsCollector) Scrape(ch chan<- prometheus.Metric) error {
}

for _, stat := range statementStats {
ch <- prometheus.MustNewConstMetric(c.calls, prometheus.CounterValue, float64(stat.Calls), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.totalTimeSeconds, prometheus.CounterValue, float64(stat.TotalTimeSeconds), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.minTimeSeconds, prometheus.GaugeValue, float64(stat.MinTimeSeconds), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.maxTimeSeconds, prometheus.GaugeValue, float64(stat.MaxTimeSeconds), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.meanTimeSeconds, prometheus.GaugeValue, float64(stat.MeanTimeSeconds), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.stdDevTimeSeconds, prometheus.GaugeValue, float64(stat.StdDevTimeSeconds), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.rows, prometheus.CounterValue, float64(stat.Rows), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.sharedBlksHit, prometheus.CounterValue, float64(stat.SharedBlksHit), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.sharedBlksRead, prometheus.CounterValue, float64(stat.SharedBlksRead), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.sharedBlksDirtied, prometheus.CounterValue, float64(stat.SharedBlksDirtied), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.sharedBlksWritten, prometheus.CounterValue, float64(stat.SharedBlksWritten), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.localBlksHit, prometheus.CounterValue, float64(stat.LocalBlksHit), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.localBlksRead, prometheus.CounterValue, float64(stat.LocalBlksRead), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.localBlksDirtied, prometheus.CounterValue, float64(stat.LocalBlksDirtied), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.localBlksWritten, prometheus.CounterValue, float64(stat.LocalBlksWritten), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.tempBlksRead, prometheus.CounterValue, float64(stat.TempBlksRead), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.tempBlksWritten, prometheus.CounterValue, float64(stat.TempBlksWritten), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.blkReadTimeSeconds, prometheus.CounterValue, float64(stat.BlkReadTimeSeconds), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.blkWriteTimeSeconds, prometheus.CounterValue, float64(stat.BlkWriteTimeSeconds), stat.RolName, stat.DatName, stat.QueryID)
ch <- prometheus.MustNewConstMetric(c.calls, prometheus.CounterValue, float64(stat.Calls), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.totalTimeSeconds, prometheus.CounterValue, float64(stat.TotalTimeSeconds), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.minTimeSeconds, prometheus.GaugeValue, float64(stat.MinTimeSeconds), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.maxTimeSeconds, prometheus.GaugeValue, float64(stat.MaxTimeSeconds), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.meanTimeSeconds, prometheus.GaugeValue, float64(stat.MeanTimeSeconds), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.stdDevTimeSeconds, prometheus.GaugeValue, float64(stat.StdDevTimeSeconds), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.rows, prometheus.CounterValue, float64(stat.Rows), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.sharedBlksHit, prometheus.CounterValue, float64(stat.SharedBlksHit), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.sharedBlksRead, prometheus.CounterValue, float64(stat.SharedBlksRead), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.sharedBlksDirtied, prometheus.CounterValue, float64(stat.SharedBlksDirtied), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.sharedBlksWritten, prometheus.CounterValue, float64(stat.SharedBlksWritten), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.localBlksHit, prometheus.CounterValue, float64(stat.LocalBlksHit), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.localBlksRead, prometheus.CounterValue, float64(stat.LocalBlksRead), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.localBlksDirtied, prometheus.CounterValue, float64(stat.LocalBlksDirtied), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.localBlksWritten, prometheus.CounterValue, float64(stat.LocalBlksWritten), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.tempBlksRead, prometheus.CounterValue, float64(stat.TempBlksRead), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.tempBlksWritten, prometheus.CounterValue, float64(stat.TempBlksWritten), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.blkReadTimeSeconds, prometheus.CounterValue, float64(stat.BlkReadTimeSeconds), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
ch <- prometheus.MustNewConstMetric(c.blkWriteTimeSeconds, prometheus.CounterValue, float64(stat.BlkWriteTimeSeconds), stat.RolName, stat.DatName, strconv.Itoa(stat.QueryID))
}
return nil
}
2 changes: 1 addition & 1 deletion exporter/db/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type PgStatUserTable struct {
type PgStatStatement struct {
RolName string `db:"rolname"`
DatName string `db:"datname"`
QueryID string `db:"queryid"`
QueryID int `db:"queryid"`
Calls int `db:"calls"`
TotalTimeSeconds int `db:"total_time_seconds"`
MinTimeSeconds int `db:"min_time_seconds"`
Expand Down

0 comments on commit 9ee55d4

Please sign in to comment.