diff --git a/cmd/log2sql/Makefile b/cmd/log2sql/Makefile index a2879ec..9ebe66f 100644 --- a/cmd/log2sql/Makefile +++ b/cmd/log2sql/Makefile @@ -27,8 +27,8 @@ build: # Note that this will download and build the latest version of package from github - it won't build the local go # repo. So you need to have published everything (and ensure tags are as desired) before doing this. dist: - ~/go/bin/xgo -go latest --targets=windows/amd64,darwin/amd64 ${LDFLAGS} github.com/rcowham/go-libp4dlog/cmd/log2sql - ~/go/bin/xgo -go latest --targets=linux/amd64 ${LINUX_LDFLAGS} github.com/rcowham/go-libp4dlog/cmd/log2sql + ~/go/bin/xgo -go latest --targets=windows/amd64,darwin/amd64 ${LDFLAGS} github.com/RishiMunagala/go-libp4dlog/cmd/log2sql + ~/go/bin/xgo -go latest --targets=linux/amd64 ${LINUX_LDFLAGS} github.com/RishiMunagalago-libp4dlog/cmd/log2sql rm -f log2sql*amd64*.gz -chmod +x log2sql*amd64* gzip log2sql*amd64* diff --git a/cmd/log2sql/main.go b/cmd/log2sql/main.go index a14d4b8..d059c30 100644 --- a/cmd/log2sql/main.go +++ b/cmd/log2sql/main.go @@ -24,8 +24,8 @@ import ( // "github.com/pkg/profile" "github.com/perforce/p4prometheus/version" - p4dlog "github.com/rcowham/go-libp4dlog" - "github.com/rcowham/go-libp4dlog/metrics" + p4dlog "github.com/RishiMunagala/go-libp4dlog" + "github.com/RishiMunagala/go-libp4dlog/metrics" ) const statementsPerTransaction = 50 * 1000 diff --git a/cmd/p4dpending/Makefile b/cmd/p4dpending/Makefile index 660b3dd..4a1300c 100644 --- a/cmd/p4dpending/Makefile +++ b/cmd/p4dpending/Makefile @@ -24,7 +24,7 @@ build: # Note that this will download and build the latest version of package from github - it won't build the local go # repo. So you need to have published everything (and ensure tags are as desired) before doing this. dist: - ~/go/bin/xgo --targets=linux/amd64,windows/amd64,darwin/amd64 ${LDFLAGS} github.com/rcowham/go-libp4dlog/cmd/p4dpending + ~/go/bin/xgo --targets=linux/amd64,windows/amd64,darwin/amd64 ${LDFLAGS} github.com/RishiMunagala/go-libp4dlog/cmd/p4dpending rm -f p4dpending*amd64*.gz -chmod +x p4dpending*amd64* gzip p4dpending*amd64* diff --git a/cmd/p4dpending/main.go b/cmd/p4dpending/main.go index 7c1a705..8971028 100644 --- a/cmd/p4dpending/main.go +++ b/cmd/p4dpending/main.go @@ -21,7 +21,7 @@ import ( // "github.com/pkg/profile" "github.com/perforce/p4prometheus/version" - p4dlog "github.com/rcowham/go-libp4dlog" + p4dlog "github.com/RishiMunagala/go-libp4dlog" ) func dateStr(t time.Time) string { diff --git a/cmd/p4locks/main.go b/cmd/p4locks/main.go index 353dd43..10963ce 100644 --- a/cmd/p4locks/main.go +++ b/cmd/p4locks/main.go @@ -23,7 +23,7 @@ import ( // "github.com/pkg/profile" "github.com/perforce/p4prometheus/version" - p4dlog "github.com/rcowham/go-libp4dlog" + p4dlog "github.com/RishiMunagala/go-libp4dlog" ) // Threshold in milliseconds below which we filter out commands - for at least one of read/write wait/held diff --git a/go.mod b/go.mod index a4b92a4..cf9934f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rcowham/go-libp4dlog +module github.com/RishiMunagala/go-libp4dlog go 1.18 diff --git a/metrics/metrics.go b/metrics/metrics.go index b1550b6..dbab5cc 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -17,7 +17,7 @@ import ( "strings" "time" - p4dlog "github.com/rcowham/go-libp4dlog" + p4dlog "github.com/RishiMunagala/go-libp4dlog" "github.com/sirupsen/logrus" ) @@ -180,6 +180,19 @@ func (p4m *P4DMetrics) printMetric(metrics *bytes.Buffer, mname string, labels [ fmt.Fprint(metrics, buf) } +func (p4m *P4DMetrics) resetToZero() { + //for _, t := range cmd.Tables { + //p4m.totalReadHeld[t.TableName] = 0 + //p4m.totalReadWait[t.TableName] = 0 + //p4m.totalWriteHeld[t.TableName] = 0 + //p4m.totalWriteWait[t.TableName] = 0 + //} + p4m.syncFilesUpdated = 0 + p4m.syncFilesDeleted = 0 + p4m.syncBytesAdded = 0 + p4m.syncBytesUpdated = 0 +} + // Publish cumulative results - called on a ticker or in historical mode func (p4m *P4DMetrics) getCumulativeMetrics() string { fixedLabels := []labelStruct{{name: "serverid", value: p4m.config.ServerID}, @@ -192,7 +205,7 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { var mname string var metricVal string mname = "p4_prom_log_lines_read" - p4m.printMetricHeader(metrics, mname, "A count of log lines read", "counter") + p4m.printMetricHeader(metrics, mname, "A count of log lines read", "gauge") metricVal = fmt.Sprintf("%d", p4m.linesRead) p4m.printMetric(metrics, mname, fixedLabels, metricVal) @@ -224,60 +237,60 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { p4m.printMetric(metrics, mname, fixedLabels, metricVal) mname = "p4_sync_files_added" - p4m.printMetricHeader(metrics, mname, "The number of files added to workspaces by syncs", "counter") + p4m.printMetricHeader(metrics, mname, "The number of files added to workspaces by syncs", "gauge") metricVal = fmt.Sprintf("%d", p4m.syncFilesAdded) p4m.printMetric(metrics, mname, fixedLabels, metricVal) mname = "p4_sync_files_updated" - p4m.printMetricHeader(metrics, mname, "The number of files updated in workspaces by syncs", "counter") + p4m.printMetricHeader(metrics, mname, "The number of files updated in workspaces by syncs", "gauge") metricVal = fmt.Sprintf("%d", p4m.syncFilesUpdated) p4m.printMetric(metrics, mname, fixedLabels, metricVal) mname = "p4_sync_files_deleted" - p4m.printMetricHeader(metrics, mname, "The number of files deleted in workspaces by syncs", "counter") + p4m.printMetricHeader(metrics, mname, "The number of files deleted in workspaces by syncs", "gauge") metricVal = fmt.Sprintf("%d", p4m.syncFilesDeleted) p4m.printMetric(metrics, mname, fixedLabels, metricVal) mname = "p4_sync_bytes_added" - p4m.printMetricHeader(metrics, mname, "The number of bytes added to workspaces by syncs", "counter") + p4m.printMetricHeader(metrics, mname, "The number of bytes added to workspaces by syncs", "gauge") metricVal = fmt.Sprintf("%d", p4m.syncBytesAdded) p4m.printMetric(metrics, mname, fixedLabels, metricVal) mname = "p4_sync_bytes_updated" - p4m.printMetricHeader(metrics, mname, "The number of bytes updated in workspaces by syncs", "counter") + p4m.printMetricHeader(metrics, mname, "The number of bytes updated in workspaces by syncs", "gauge") metricVal = fmt.Sprintf("%d", p4m.syncBytesUpdated) p4m.printMetric(metrics, mname, fixedLabels, metricVal) mname = "p4_cmd_counter" - p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by cmd)", "counter") + p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by cmd)", "gauge") for cmd, count := range p4m.cmdCounter { metricVal = fmt.Sprintf("%d", count) labels := append(fixedLabels, labelStruct{"cmd", cmd}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_cumulative_seconds" - p4m.printMetricHeader(metrics, mname, "The total in seconds (by cmd)", "counter") + p4m.printMetricHeader(metrics, mname, "The total in seconds (by cmd)", "gauge") for cmd, lapse := range p4m.cmdCumulative { metricVal = fmt.Sprintf("%0.3f", lapse) labels := append(fixedLabels, labelStruct{"cmd", cmd}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_cpu_user_cumulative_seconds" - p4m.printMetricHeader(metrics, mname, "The total in user CPU seconds (by cmd)", "counter") + p4m.printMetricHeader(metrics, mname, "The total in user CPU seconds (by cmd)", "gauge") for cmd, lapse := range p4m.cmduCPUCumulative { metricVal = fmt.Sprintf("%0.3f", lapse) labels := append(fixedLabels, labelStruct{"cmd", cmd}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_cpu_system_cumulative_seconds" - p4m.printMetricHeader(metrics, mname, "The total in system CPU seconds (by cmd)", "counter") + p4m.printMetricHeader(metrics, mname, "The total in system CPU seconds (by cmd)", "gauge") for cmd, lapse := range p4m.cmdsCPUCumulative { metricVal = fmt.Sprintf("%0.3f", lapse) labels := append(fixedLabels, labelStruct{"cmd", cmd}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_error_counter" - p4m.printMetricHeader(metrics, mname, "A count of cmd errors (by cmd)", "counter") + p4m.printMetricHeader(metrics, mname, "A count of cmd errors (by cmd)", "gauge") for cmd, count := range p4m.cmdErrorCounter { metricVal = fmt.Sprintf("%d", count) labels := append(fixedLabels, labelStruct{"cmd", cmd}) @@ -286,14 +299,14 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { // For large sites this might not be sensible - so they can turn it off if p4m.config.OutputCmdsByUser { mname = "p4_cmd_user_counter" - p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by user)", "counter") + p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by user)", "gauge") for user, count := range p4m.cmdByUserCounter { metricVal = fmt.Sprintf("%d", count) labels := append(fixedLabels, labelStruct{"user", user}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_user_cumulative_seconds" - p4m.printMetricHeader(metrics, mname, "The total in seconds (by user)", "counter") + p4m.printMetricHeader(metrics, mname, "The total in seconds (by user)", "gauge") for user, lapse := range p4m.cmdByUserCumulative { metricVal = fmt.Sprintf("%0.3f", lapse) labels := append(fixedLabels, labelStruct{"user", user}) @@ -303,14 +316,14 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { // For large sites this might not be sensible - so they can turn it off if p4m.config.OutputCmdsByIP { mname = "p4_cmd_ip_counter" - p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by IP)", "counter") + p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by IP)", "gauge") for ip, count := range p4m.cmdByIPCounter { metricVal = fmt.Sprintf("%d", count) labels := append(fixedLabels, labelStruct{"ip", ip}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_ip_cumulative_seconds" - p4m.printMetricHeader(metrics, mname, "The total in seconds (by IP)", "counter") + p4m.printMetricHeader(metrics, mname, "The total in seconds (by IP)", "gauge") for ip, lapse := range p4m.cmdByIPCumulative { metricVal = fmt.Sprintf("%0.3f", lapse) labels := append(fixedLabels, labelStruct{"ip", ip}) @@ -320,7 +333,7 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { // For large sites this might not be sensible - so they can turn it off if p4m.config.OutputCmdsByUserRegex != "" { mname = "p4_cmd_user_detail_counter" - p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by user and cmd)", "counter") + p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by user and cmd)", "gauge") for user, userMap := range p4m.cmdByUserDetailCounter { for cmd, count := range userMap { metricVal = fmt.Sprintf("%d", count) @@ -330,7 +343,7 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { } } mname = "p4_cmd_user_detail_cumulative_seconds" - p4m.printMetricHeader(metrics, mname, "The total in seconds (by user and cmd)", "counter") + p4m.printMetricHeader(metrics, mname, "The total in seconds (by user and cmd)", "gauge") for user, userMap := range p4m.cmdByUserDetailCumulative { for cmd, lapse := range userMap { metricVal = fmt.Sprintf("%0.3f", lapse) @@ -341,28 +354,28 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { } } mname = "p4_cmd_replica_counter" - p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by broker/replica/proxy)", "counter") + p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by broker/replica/proxy)", "gauge") for replica, count := range p4m.cmdByReplicaCounter { metricVal = fmt.Sprintf("%d", count) labels := append(fixedLabels, labelStruct{"replica", replica}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_replica_cumulative_seconds" - p4m.printMetricHeader(metrics, mname, "The total in seconds (by broker/replica/proxy)", "counter") + p4m.printMetricHeader(metrics, mname, "The total in seconds (by broker/replica/proxy)", "gauge") for replica, lapse := range p4m.cmdByReplicaCumulative { metricVal = fmt.Sprintf("%0.3f", lapse) labels := append(fixedLabels, labelStruct{"replica", replica}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_program_counter" - p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by program)", "counter") + p4m.printMetricHeader(metrics, mname, "A count of completed p4 cmds (by program)", "gauge") for program, count := range p4m.cmdByProgramCounter { metricVal = fmt.Sprintf("%d", count) labels := append(fixedLabels, labelStruct{"program", program}) p4m.printMetric(metrics, mname, labels, metricVal) } mname = "p4_cmd_program_cumulative_seconds" - p4m.printMetricHeader(metrics, mname, "The total in seconds (by program)", "counter") + p4m.printMetricHeader(metrics, mname, "The total in seconds (by program)", "gauge") for program, lapse := range p4m.cmdByProgramCumulative { metricVal = fmt.Sprintf("%0.3f", lapse) labels := append(fixedLabels, labelStruct{"program", program}) @@ -370,7 +383,7 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { } mname = "p4_total_read_wait_seconds" p4m.printMetricHeader(metrics, mname, - "The total waiting for read locks in seconds (by table)", "counter") + "The total waiting for read locks in seconds (by table)", "gauge") for table, total := range p4m.totalReadWait { metricVal = fmt.Sprintf("%0.3f", total) labels := append(fixedLabels, labelStruct{"table", table}) @@ -378,7 +391,7 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { } mname = "p4_total_read_held_seconds" p4m.printMetricHeader(metrics, mname, - "The total read locks held in seconds (by table)", "counter") + "The total read locks held in seconds (by table)", "gauge") for table, total := range p4m.totalReadHeld { metricVal = fmt.Sprintf("%0.3f", total) labels := append(fixedLabels, labelStruct{"table", table}) @@ -386,7 +399,7 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { } mname = "p4_total_write_wait_seconds" p4m.printMetricHeader(metrics, mname, - "The total waiting for write locks in seconds (by table)", "counter") + "The total waiting for write locks in seconds (by table)", "gauge") for table, total := range p4m.totalWriteWait { metricVal = fmt.Sprintf("%0.3f", total) labels := append(fixedLabels, labelStruct{"table", table}) @@ -394,7 +407,7 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { } mname = "p4_total_write_held_seconds" p4m.printMetricHeader(metrics, mname, - "The total write locks held in seconds (by table)", "counter") + "The total write locks held in seconds (by table)", "gauge") for table, total := range p4m.totalWriteHeld { metricVal = fmt.Sprintf("%0.3f", total) labels := append(fixedLabels, labelStruct{"table", table}) @@ -403,7 +416,7 @@ func (p4m *P4DMetrics) getCumulativeMetrics() string { if len(p4m.totalTriggerLapse) > 0 { mname = "p4_total_trigger_lapse_seconds" p4m.printMetricHeader(metrics, mname, - "The total lapse time for triggers in seconds (by trigger)", "counter") + "The total lapse time for triggers in seconds (by trigger)", "gauge") for table, total := range p4m.totalTriggerLapse { metricVal = fmt.Sprintf("%0.3f", total) labels := append(fixedLabels, labelStruct{"trigger", table}) @@ -570,6 +583,7 @@ func (p4m *P4DMetrics) ProcessEvents(ctx context.Context, linesInChan <-chan str } if !p4m.historical { metricsChan <- p4m.getCumulativeMetrics() + p4m.resetToZero() } case cmd, ok := <-cmdsInChan: if ok { diff --git a/modifiedPrometheusDetails b/modifiedPrometheusDetails new file mode 100644 index 0000000..88e3f0a --- /dev/null +++ b/modifiedPrometheusDetails @@ -0,0 +1,9 @@ +Change repo: "github.com/rcowham/go-libp4dlog" --> "github.com/RishiMunagala/go-libp4dlog" + p4prom.go + go.mod + p4prom_test.go + +Added "_bucket" in go-libp4dlog to: + metrics.go + metrics_test.go + p4historical.json \ No newline at end of file