Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix prometheus exporter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
infra
matrix prometheus exporter
Commits
c8ed2cfe
Commit
c8ed2cfe
authored
5 months ago
by
psy
Browse files
Options
Downloads
Patches
Plain Diff
save state as json, add absolute gauge, initialize counters
parent
82d54434
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
exporter.py
+35
-8
35 additions, 8 deletions
exporter.py
with
35 additions
and
8 deletions
exporter.py
+
35
−
8
View file @
c8ed2cfe
...
@@ -3,12 +3,14 @@ import requests
...
@@ -3,12 +3,14 @@ import requests
from
prometheus_client
import
start_http_server
,
Counter
,
Gauge
from
prometheus_client
import
start_http_server
,
Counter
,
Gauge
from
time
import
sleep
from
time
import
sleep
import
argparse
import
argparse
import
json
metric_members
=
Gauge
(
'
matrix_channel_members_total
'
,
'
Members joined in room
'
,
[
'
room_id
'
,
'
canonical_alias
'
,
'
name
'
])
metric_members
=
Gauge
(
'
matrix_channel_members_total
'
,
'
Members joined in room
'
,
[
'
room_id
'
,
'
canonical_alias
'
,
'
name
'
])
metric_channel_types
=
Gauge
(
'
matrix_channel_types_total
'
,
'
Channels per type
'
,
[
'
type
'
])
metric_channel_types
=
Gauge
(
'
matrix_channel_types_total
'
,
'
Channels per type
'
,
[
'
type
'
])
metric_channel_version
=
Gauge
(
'
matrix_channel_version_total
'
,
'
Channels per version
'
,
[
'
version
'
])
metric_channel_version
=
Gauge
(
'
matrix_channel_version_total
'
,
'
Channels per version
'
,
[
'
version
'
])
metric_channel_state_events
=
Gauge
(
'
matrix_channel_state_events_total
'
,
'
State events per room
'
,
metric_channel_state_events
=
Gauge
(
'
matrix_channel_state_events_total
'
,
'
State events per room
'
,
[
'
room_id
'
,
'
canonical_alias
'
,
'
name
'
])
[
'
room_id
'
,
'
canonical_alias
'
,
'
name
'
])
metric_channel_messages_absolute
=
Gauge
(
'
matrix_channel_messages_absolute
'
,
'
Messages per channel absolute
'
,
[
'
room_id
'
,
'
canonical_alias
'
,
'
name
'
,
'
type
'
])
metric_channel_messages
=
Counter
(
'
matrix_channel_messages_total
'
,
'
Messages per channel
'
,
[
'
room_id
'
,
'
canonical_alias
'
,
'
name
'
,
'
type
'
])
metric_channel_messages
=
Counter
(
'
matrix_channel_messages_total
'
,
'
Messages per channel
'
,
[
'
room_id
'
,
'
canonical_alias
'
,
'
name
'
,
'
type
'
])
...
@@ -22,21 +24,35 @@ def fetch_metrics(synapse_url, access_token):
...
@@ -22,21 +24,35 @@ def fetch_metrics(synapse_url, access_token):
update_room_metrics
(
rooms
)
update_room_metrics
(
rooms
)
for
room
in
rooms
:
for
room
in
rooms
:
statefile
=
f
"
state/
{
room
[
'
room_id
'
]
}
.
end
"
statefile
=
f
"
state/
{
room
[
'
room_id
'
]
}
.
state
"
url
=
f
"
{
synapse_url
}
/_synapse/admin/v1/rooms/
{
room
[
'
room_id
'
]
}
/messages
"
url
=
f
"
{
synapse_url
}
/_synapse/admin/v1/rooms/
{
room
[
'
room_id
'
]
}
/messages
"
messages
=
[]
end
=
None
state
=
{}
try
:
try
:
with
open
(
statefile
,
'
r
'
)
as
file
:
with
open
(
statefile
,
'
r
'
)
as
file
:
end
=
file
.
read
(
)
state
=
json
.
load
(
file
)
except
OSError
:
except
OSError
:
print
(
f
"
No state file for room
{
room
[
'
room_id
'
]
}
(
{
room
.
get
(
'
name
'
,
''
)
}
) found. Fetching messages could take a while.
"
)
print
(
f
"
No state file for room
{
room
[
'
room_id
'
]
}
(
{
room
.
get
(
'
name
'
,
''
)
}
) found. Fetching messages could take a while.
"
)
state
[
'
messagecount
'
]
=
{}
for
type
in
state
[
'
messagecount
'
]:
metric_channel_messages
.
labels
(
room_id
=
room
[
'
room_id
'
],
canonical_alias
=
room
[
'
canonical_alias
'
]
if
room
[
'
canonical_alias
'
]
else
''
,
name
=
room
[
'
name
'
]
if
room
[
'
name
'
]
else
''
,
type
=
type
)
metric_channel_messages_absolute
.
labels
(
room_id
=
room
[
'
room_id
'
],
canonical_alias
=
room
[
'
canonical_alias
'
]
if
room
[
'
canonical_alias
'
]
else
''
,
name
=
room
[
'
name
'
]
if
room
[
'
name
'
]
else
''
,
type
=
type
).
set
(
state
[
'
messagecount
'
][
type
])
messages
=
[]
while
True
:
while
True
:
params
=
{}
params
=
{}
if
end
i
s
not
Non
e
:
if
'
end
'
i
n
stat
e
:
params
[
'
from
'
]
=
end
params
[
'
from
'
]
=
state
[
'
end
'
]
result
=
requests
.
get
(
url
,
params
=
params
,
headers
=
auth
).
json
()
result
=
requests
.
get
(
url
,
params
=
params
,
headers
=
auth
).
json
()
...
@@ -44,7 +60,7 @@ def fetch_metrics(synapse_url, access_token):
...
@@ -44,7 +60,7 @@ def fetch_metrics(synapse_url, access_token):
messages
.
extend
(
result
[
'
chunk
'
])
messages
.
extend
(
result
[
'
chunk
'
])
if
'
end
'
in
result
:
if
'
end
'
in
result
:
end
=
result
[
'
end
'
]
state
[
'
end
'
]
=
result
[
'
end
'
]
else
:
else
:
break
break
...
@@ -55,8 +71,19 @@ def fetch_metrics(synapse_url, access_token):
...
@@ -55,8 +71,19 @@ def fetch_metrics(synapse_url, access_token):
name
=
room
[
'
name
'
]
if
room
[
'
name
'
]
else
''
,
name
=
room
[
'
name
'
]
if
room
[
'
name
'
]
else
''
,
type
=
message
[
'
type
'
]).
inc
()
type
=
message
[
'
type
'
]).
inc
()
metric_channel_messages_absolute
.
labels
(
room_id
=
room
[
'
room_id
'
],
canonical_alias
=
room
[
'
canonical_alias
'
]
if
room
[
'
canonical_alias
'
]
else
''
,
name
=
room
[
'
name
'
]
if
room
[
'
name
'
]
else
''
,
type
=
message
[
'
type
'
]).
inc
()
if
message
[
'
type
'
]
not
in
state
[
'
messagecount
'
]:
state
[
'
messagecount
'
][
message
[
'
type
'
]]
=
0
state
[
'
messagecount
'
][
message
[
'
type
'
]]
+=
1
with
open
(
statefile
,
'
w
'
)
as
file
:
with
open
(
statefile
,
'
w
'
)
as
file
:
file
.
write
(
end
)
json
.
dump
(
state
,
file
)
def
update_room_metrics
(
rooms
):
def
update_room_metrics
(
rooms
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment