Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Zach Zhu <zzqshu@126.com>
- Loading branch information
Showing
16 changed files
with
238 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package generic | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
LabelSuccess = "success" | ||
LabelError = "error" | ||
) | ||
|
||
var ( | ||
SQLTotal = prometheus.NewCounterVec(prometheus.CounterOpts{ | ||
Name: "kine_sql_total", | ||
Help: "Total number of SQL operations", | ||
}, []string{"result"}) | ||
|
||
SQLTime = prometheus.NewHistogramVec(prometheus.HistogramOpts{ | ||
Name: "kine_sql_time_seconds", | ||
Help: "Length of time per SQL operation", | ||
Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, | ||
1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30}, | ||
}, []string{"result"}) | ||
) | ||
|
||
var ( | ||
// SlowSQLThreshold is a duration which SQL executed longer than will be logged. | ||
// This can be directly modified to override the default value when kine is used as a library. | ||
SlowSQLThreshold = time.Second | ||
) | ||
|
||
func ObserveSQL(start time.Time, success bool, sql Stripped, args ...interface{}) { | ||
result := LabelSuccess | ||
if !success { | ||
result = LabelError | ||
} | ||
SQLTotal.WithLabelValues(result).Inc() | ||
duration := time.Since(start) | ||
SQLTime.WithLabelValues(result).Observe(duration.Seconds()) | ||
if SlowSQLThreshold > 0 && duration >= SlowSQLThreshold { | ||
logrus.Infof("Slow SQL (started: %v) (total time: %v): %s : %v", start, duration, sql, args) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.