-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (56 loc) · 1.29 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"io/fs"
"log"
"net/http"
"os"
"path/filepath"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var addr = flag.String("listen-address", ":8090", "The address to listen on for HTTP requests.")
var files = flag.String("vault-collection", "./", "location of your files to check")
var tag = flag.String("tag", "#unprocessed", "tag to check for")
var count int
// var c int
func main() {
flag.Parse()
var (
unprocessedNotes = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "total_unprocessed_notes",
Help: "The total number of unprocessed notes",
})
)
prometheus.MustRegister(unprocessedNotes)
go func() {
for {
unprocessedNotes.Set(float64(returncount()))
}
}()
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(*addr, nil))
}
func returncount() int {
count = 0
filepath.WalkDir(*files, visit)
return count
}
func visit(path string, di fs.DirEntry, err error) error {
var tagged bool
fileInfo, err := os.Lstat(path)
if fileInfo.Mode().IsRegular() {
b, err := os.ReadFile(path)
if err != nil {
// fmt.Println(err)
panic(err)
}
s := string(b)
tagged = (strings.Contains(s, *tag))
if tagged == true {
count++
}
}
return nil
}